starting multiple instances of same callback in MultiThreadedSpinner
My end goal is to have a callback receive a message and until the next message is received to run a few lines of code in an infinite loop.
My initial thought was to create a MultiThreadedSpinner
and implement the callback like so. Where stop
is a global variable.
void callback(const std_msgs::UInt8::ConstPtr &msg) {
if (msg->data == 1) {
stop = true;
return;
}
// else start the loop
stop = false;
while (!stop) {
//simple serial connection code
// sleep 500ms
}
}
When the messages is received it would create a blacking callback. Then when a new message is received it would set the stop variable and the first started callback would then end. But from what I seem to have figured out the MultiThreadedSpinner
will not call the same callback again while one is already running.
Hopefully that makes some sense. Any thoughts on how to do this?
EDIT - Bigger Picture My input device sends int as messages. Let's say it can be 0, 1 or 2. Where 0 is no action, 1 is action 1 and 2 is action 2. The way the device works is that it only sends a message on action change. Read differently, there are no messages when an action is held.
After action 1 or 2 you are guaranteed to receive action 0 first before anything else.
My output device needs to incrementally move a small delta (forward for 1 and reverse for 2) while an action is being performed and stop moving when the action stops being performed. Essentially I have to manually jog the robot by small increments when the first message is sent until the next message is sent.
Could you perhaps tell us what it is that you are trying to achieve exactly? Trying to use loops in msg callbacks is often a sign of larger issues with the design of a node.
I understand that callbacks should not be blocked, but I really can't see any other way to do this. I've update the question with more information.
Also: what kind of robot are we talking about here? Perhaps there is an easier / better way of controlling it?
Using a crs a255 5 axis robot. It doesn't have a continuous mode, only incremental or final destination. To move it while the action is happening I need to continuously send small increments.
I've no experience with those robots, but from the RAPL-3 manual it looks like there may be some things possible. Have you considered writing a ROS driver for it?
I've read through all the documentation i can find. This page from another document sums it up nicely. https://dl.dropboxusercontent.com/u/2... . There's no continuous motion for the RAPL-3 or ASH interface. I only have access to the jog type command
What about using
c(t)path(..)
withploc
s asteachable
s? I don't know about velocity, but that does seem to allow you to map a JointTrajectory msg to a trajectory for your ctrlr.