Setting up the msg_range object

The distance sensor uses the message type defined in the Range class of the sensor_msgs.msg library, whose structure is as follows:

uint8 ULTRASOUND=0
uint8 INFRARED=1

std_msgs/Header header
uint8 radiation_type
float32 field_of_view
float32 min_range
float32 max_range
float32 range

These are the fields that will be part of any message involving the data flow from the sensor, and its syntax is explained in detail in the documentation (http://docs.ros.org/api/sensor_msgs/html/msg/Range.html). All the fields are specific characteristics of the sensor except for the measurement itself, range. Hence, the following snippet gives a particular definition for our distance sensor:

msg_range = Range()

msg_range.header.frame_id
= "distance"
msg_range.radiation_type = Range.INFRARED
msg_range.min_range = 0.02
msg_range.max_range = 3.0

Here, the first line initiates the msg_range variable to be of the Range() type. In the header.frame_id field, we indicate the physical magnitude we are going to measure, which is distance.

The radiation type is set to INFRARED (there is no option to set this to LASER, but specifying it as INFRARED is more adequate than the other option, ULTRASOUND, for which you would have a wide field of view instead of a straight ray). LASER is directional, as is INFRARED, so it is better to use this type.

The last two lines specify the maximum (3 meters) and minimum (2 centimeters) distances the sensor can measure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset