get data from sensor - willinum/SPEC21 GitHub Wiki
-
add plugin to your sensor in your sensors .sdf file eg.: for a 'ray' sensor add 'libgazebo_ros_ray_sensor.so' from the gazebo_ros_pkgs package. make sure to select the fitting branch (eg branch foxy if you use ros2 foxy)
-
the following parameters can be tweaked:
SDF parameters: <output_type>: Optional. The message type of the plugin's output. Can be any of the following:
- sensor_msgs/PointCloud2: 3D cloud of points, Default
- sensor_msgs/PointCloud: 3D cloud of points
- sensor_msgs/LaserScan: 2D scan, uses center vertical ray if there are multiple
- sensor_msgs/Range: Single distance value, minimum of all ray ranges of parent sensor
<frame_name>: TF Frame id of output header. If not set, frame id will be name of sensor's parent link
<min_intensity>: Clip intensity values for output to this value. Default: 0.0
<radiation_type>: The radiation type to publish when the output type is sensor_msgs/Range. Can be either "infrared" or "ultrasonic". Default: "infrared".
-
for this example you would add the following lines of code to your .sdf file(like this):
<sensor type="ray" name="sensor"> ... some sensor related stuff ... <plugin name="my_ray_sensor_plugin" filename="libgazebo_ros_ray_sensor.so"> <ros> <!-- Configure namespace and remap to publish to /ray/range --> <namespace>/ray</namespace> <remapping>~/out:=range</remapping> </ros> <!-- Output as a Range, see aplugin sepcs for other types --> <output_type>sensor_msgs/Range</output_type> <!-- Clip intensity values so all are above 100, optional --> <min_intensity>100.0</min_intensity> <!-- Frame id for header of output, defaults to sensor's parent link name --> <frame_name>ray_link</frame_name> <!-- --> </plugin> </sensor>
-
this publishes the range data from the sensor to the ros2 topic /ray/range (
ros2 topic list
) -
to print data to screen input following into terminal:
ros2 topic echo /ray/range
-
visualize in rviz2:
- run in terminal
ros2 run tf2_ros static_transform_publisher 0 0 0 0 0 0 map <frame_name (eg. ray_link)>
(changes fixed frame in rviz2 to eg. ray_link) - start rviz2 via terminal command (
rviz2
)- 1 change fixed frame to your frame_name
- 2 in bottom left corner of rviz2 interface select 'add' and choose according type eg. Range
- 3 click in column besides topic and select desired topic
- run in terminal
In the picture below you can see the simulation with the iris_clone2 drone running in gazebo and the visualization of the range data of the sensor in rviz2