ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
It seems the ros::spin()
is outside the while(1)
.
There is also no ros::Rate::sleep()
in the body of either of your while
-loops.
Finally: if you need to run a while
-loop, make sure to use something like while (ros::ok()) { .. }
. This makes your node check whether it has been requested to exit.
2 | No.2 Revision |
It seems the ros::spin()
is outside the while(1)
.
There is also no ros::Rate::sleep()
in the body of either of your while
-loops.
Finally: if you need to run a while
-loop, make sure to use something like while (ros::ok()) { .. }
. This makes your node check whether it has been requested to exit.
See also wiki/roscpp/Overview/Callbacks and Spinning.
Edit: (nested) while
-loops are not necessarily a good idea with an event-based, asynchronous framework such as ROS. You may want to re-evaluate your approach and possibly restructure your node.
3 | No.3 Revision |
It seems the ros::spin()
is outside the while(1)
.. That is ok, but I'm also slightly confused by the structure of your node: what is the while
-loop supposed to do?
There is also no ros::Rate::sleep()
in the body of either of your while
-loops.
Finally: if you need to run a while
-loop, make sure to use something like while (ros::ok()) { .. }
. This makes your node check whether it has been requested to exit.
See also wiki/roscpp/Overview/Callbacks and Spinning.
Edit: (nested) while
-loops are not necessarily a good idea with an event-based, asynchronous framework such as ROS. You may want to re-evaluate your approach and possibly restructure your node.
4 | No.4 Revision |
It seems the ros::spin()
is outside the while(1)
. That is ok, but I'm also slightly confused by the structure of your node: what is the while
-loop supposed to do?
There is also no ros::Rate::sleep()
in the body of either of your while
-loops.
Random other note: you have two calls to ros::init(..)
in there, I'm not sure that is going to work (or at the very least: it's not needed).
Finally: if you need to run a while
-loop, make sure to use something like while (ros::ok()) { .. }
. This makes your node check whether it has been requested to exit.
See also wiki/roscpp/Overview/Callbacks and Spinning.
Edit: (nested) while
-loops are not necessarily a good idea with an event-based, asynchronous framework such as ROS. You may want to re-evaluate your approach and possibly restructure your node.
5 | No.5 Revision |
It
and sending a message to the topic results in nothing
This is most likely caused by the fact that your node does not handle any incoming events (ie: msgs on topics).
To remedy that you'd need to either call ros::spin()
or periodically call ros::spinOnce()
.
Your node does the former, but only after it has progressed through the while
-loops. And this is the problem, as in order to get through the loops, your node needs to handle incoming events (otherwise message
will never be set to 1
). This
ros::spin()
I would suggest to avoid the two nested while
-loops, as I believe they are not needed and only complicate things.
What are you actually trying to do and what are the two while
-loops supposed to achieve?
Some other things I noticed:
while(1)
. That is ok, but I'm also slightly confused by the structure of your node: what is the while
-loop supposed to do? There is also
ros::Rate::sleep()
in the body of either of your while
Random other note:
ros::init(..)
in there, I'm not sure that is going to work (or at the very least: it's not Finally:
if you need to run aHowever, when i use this node, it cannot be close by crtl-c
while
-loop, make sure to use something like while (ros::ok()) { .. }
. This makes your node check whether it has been requested to exit. See also wiki/roscpp/Overview/Callbacks and Spinning.
Edit: (nested) while
-loops are not necessarily a good idea with an event-based, asynchronous framework such as ROS. You may want to re-evaluate your approach and possibly restructure your node.
6 | No.6 Revision |
and sending a message to the topic results in nothing
This is most likely caused by the fact that your node does not handle any incoming events (ie: msgs on topics).
To remedy that you'd need to either call ros::spin()
or periodically call ros::spinOnce()
.
Your node does the former, but only after it has progressed through the while
-loops. And this is the problem, as in order to get through the loops, your node needs to handle incoming events (otherwise message
will never be set to 1
). This seems to be a deadlock situation.
I would suggest to avoid the two nested while
-loops, as I believe they are not needed and only complicate things.
What are you actually trying to do and what are the two while
-loops supposed to achieve?
Some other things I noticed:
ros::Rate::sleep()
in the body of either of your while
-loops (busy-wait, 100% cpu usage)ros::init(..)
in there, I'm not sure that is going to work (or at the very least: it's not needed)final
for anything (unless you want to declare something as final). It is a C++11 keyword: final specifier (since C++11)However, when i use this node, it cannot be close by crtl-c
if you need to run a while
-loop, make sure to use something like while (ros::ok()) { .. }
. This makes your node check whether it has been requested to exit.
See also wiki/roscpp/Overview/Callbacks and Spinning.
Edit: (nested) while
-loops are not necessarily a good idea with an event-based, asynchronous framework such as ROS. You may want to re-evaluate your approach and possibly restructure your node.