ros subscriber is interrupted by ginput

I have a ginput command in my ros subscriber callback, which causes an interruption of the subscriber. The callback is entered once, and then it stops spinning. When I comment out ginput command, the callback is called continuously.

4 commentaires

Geoff Hayes
Geoff Hayes le 30 Déc 2016
Jin - is this the ros subscriber from https://www.mathworks.com/help/robotics/ref/rossubscriber.html? Can you show some of your code?
Jin Dai
Jin Dai le 30 Déc 2016
Modifié(e) : Jin Dai le 30 Déc 2016
Hi Geoff, nice to hear from you. The code is attached below:
classdef EdgeFollow
properties
pcl_sub;
initialized;
end
methods
function this = EdgeFollow()
rosshutdown;
close all
rosinit
this.initialized = 0
this.pcl_sub = rossubscriber('lead_laser/pointcloud', @this.extractEdge);
end
end
methods(Access = private, Hidden = true)
function extractEdge(this, src, pclMsg)
disp('enter cbk')
if(~this.initialized)
figure(1)
hold on
xlabel('x','fontsize',15)
ylabel('y','fontsize',15)
axis equal
[x,y] = ginput(1);
else
end
end
end
end
The callback is only called once.
If I comment line: [x,y] = ginput(1), the callback is entered continuously.
Thanks.
Geoff Hayes
Geoff Hayes le 30 Déc 2016
Jin - doesn't the call to ginput "block" and so you are waiting for the user (?) to choose a point on the axes? What are you expecting to happen with the call to ginput?
Jin Dai
Jin Dai le 30 Déc 2016
I deleted most codes to show you only the code structure. I clicked a point and found nearest neighbors of this clicked point. After this, it exits the callback, and never enters it again.

Connectez-vous pour commenter.

Réponses (1)

Sebastian Castro
Sebastian Castro le 19 Sep 2017

0 votes

This is expected, sorry to say.
Recall that the MATLAB environment is single-threaded, with the exception of optimized math functions (which you can't control as a user), or if you're using the Parallel Computing Toolbox to explicitly assign tasks to multiple cores.
So, a blocking operation like ginput means your subscriber won't be receiving any messages until you free up computational resources.
- Sebastian

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by