[ros-users] Problem synchronizing between nodes
John Daly
jmdaly at gmail.com
Fri Dec 3 05:38:45 UTC 2010
Hi everyone,
I'm new to ROS, and having some trouble implementing a robot
controller. So I was hoping someone could point me in the right
direction! I've been through the tutorials on the ROS wiki, but am
still having some trouble.
At the moment we don't have access to the actual robot, so I've
written a ROS node (this is all in Python using rospy) to simulate the
robot dynamics (call it node A). This node publishes the robot state
to a topic. Then I've written another node (node B) that subscribes to
the topic where the state is published. This node computes the control
law for the robot, and publishes that signal to a different topic.
Node A subscribes to this topic, so that it gets the control signal,
and applies it to the robot dynamics.
I've written callbacks in each of the nodes that simply take the
message coming in from the topic and assign it to a variable that is
local to the node.
In the main loop of each node, I have something similar to the following:
rate = rospy.Rate(UPDATE_HZ)
while not rospy.is_shutdown():
rate.sleep()
# Do the work. In node A, this is integrating dynamics. In node B,
this is computing a control law.
# After the work is done, publish the suitable message (robot
state in Node A, control signal in node B).
The problem I'm having is that I don't think the two nodes are at all
synchronized, and I think this is causing trouble with the values
computed in each node. For example, node A might get executed a couple
of times before node B does.
So I'm wondering, is there an existing pattern within rospy for
synchronizing among nodes that are passing messages back and forth? Or
should I look to Python for synchronization mechanisms? If anyone can
point me to some references on this, that would be great. Also, is
each node run as its own process, or are all nodes run as threads in
some other process?
Thanks for your help!
-John
More information about the ros-users
mailing list