How distance sensors send messages
If you have uploaded the code correctly to Arduino and serial_node.py
, it's working well and we can see the topic name /range in the topic list:
$ rostopic list
You can learn about the type of the topic as usual by using the rostopic
type:
$ rostopic type /range std_msgs/Int16
If you want to check the data contained in the messages, we should type the following:
$ rostopic echo /range
You can play with this sensor, pointing it at objects at different distances.
Creating an example to use the ultrasound range
In this example, the ultrasound sensor will command the turtle of the turtlesim
node. The example is programmed to behave depending on the distance to objects. This way, it is possible to avoid obstacles, publishing geometry_msgs/Twist
in turtlesim1/cmd_vel
. When the ultrasound finds an object too close, that is, less than 20 cm, the turtle will go backward. If an obstacle is found at a middle distance, that is, between 20 and 40 cm, the turtle will turn...