Two classes being executed at the same time, sharing information
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
Hello everybody
I have two classes, A and B, being B a property of A. B is continuously making some calculations, with its own pace, while A is making others. At some point, A requests information to B. This would be a simplification of both classes:
A:
classdef AClass
properties
B
end
methods
function obj = AClass()
B = BClass();
while true
count = B.getCount;
disp(['Count now: ',num2str(count)])
pause(2)
end
end
end
end
B:
classdef BClass
properties
count = 0
end
methods
function obj = BClass()
while true
obj.count = obj.count + 1;
pause(1)
end
end
function output = getCount(obj)
output = obj.count;
end
end
end
Of course executing AClass does not work as it would be expected, since it gets stuck in the while loop, inside B. I was wondering if there is a way of making it work.
For instance in ROS (Robot Operating System), it would be pretty easy. A would be executed in a node and B in another, and each time A needs the information from B, either it is subscribed to a topic or uses a service.
Thanks a lot in advance
Antworten (0)
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!