rover
cluster/cmd_vel
and /odom
cmd_vel
: sent to a robot to command it to move (locomotion)odom
: received from a robot to report where (it thinks) it isTwist
message is used for cmd_vel
cmd_vel
it is asking the robot to movemotor_control
) which subscribes to cmd_velmotor_control
comes with the robot and is run automaticallymotor_control
is connected to the motors.motor_control
exists and runs even if no other node is publishing cmd_vel
cmd_vel
odom
constantly (say 30 times per second)
subs = rospy.Subscriber("/odom", Odometry, odom_callback)
def odom_callback(msg):
x_position = msg.pose.pose.position.x
def scan_callback(self, msg):
indices = list(range(350, 360)) + list(range(0, 11))
relevant_ranges = [msg.ranges[i] for i in indices]
valid_ranges = [r for r in relevant_ranges if msg.range_min < r < msg.range_max]
if valid_ranges:
self.average_distance = sum(valid_ranges) / len(valid_ranges)
def main():
rospy.init_node('scan_subscriber', anonymous=True)
rospy.Subscriber("/scan", LaserScan, scan_callback)
rospy.spin()
Queues
Latched Topics
~/catkin_ws/src/cosi119_src/src/topic_publisher.py
catkin_make
roscore
in another terminal
$ roscore
# open a new tab
$ roslanch cosi119_src pubsubexample.launch
# open a new tab
$ rostopic list
$ rostopic echo counter -n 5
rostopic
)rqt_graph
to see the publisher/subscriber relationships for node and topicssamples
topic_subscriber.py
# shell commands
$ roscd samples
$ chmod +x scripts/topic_subscriber.py
$ rosrun samples topic_subscriber.py