February 2020
Intermediate to advanced
432 pages
10h 50m
English
If you have understood how the requirement, distance-sensor.py, publisher script works, then the following subscriber script should be pretty straightforward to follow:
#!/usr/bin/env pythonimport rospyfrom sensor_msgs.msg import Rangedef callback(msg): print msg.data rospy.loginfo(rospy.get_caller_id() + 'GoPiGo3 measures distance %s mm', msg.data*1000)rospy.init_node('distance_sensor_subscriber')sub = rospy.Subscriber('distance_sensor/distance', Range, callback)rospy.spin()
This snippet corresponds to the distance-sensor_subscriber.py file in the ./pkg_mygopigo/src folder of the code for this chapter. The main difference in the subscriber script is that, since we are listening to a topic, ...
Read now
Unlock full access