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 Comments

Jin - is this the ros subscriber from https://www.mathworks.com/help/robotics/ref/rossubscriber.html? Can you show some of your code?
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.
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?
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.

Sign in to comment.

Answers (1)

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

Categories

Asked:

on 29 Dec 2016

Answered:

on 19 Sep 2017

Community Treasure Hunt

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

Start Hunting!