Skip to content

Commit 0334a79

Browse files
authored
Add RGBD, RGB and RGB triggered options (#2)
1 parent 06f2039 commit 0334a79

7 files changed

+370
-230
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Which should start a simulated camera in Gazebo with a few objects in front of i
2222

2323
# Example Usage in URDF
2424

25-
In your robots urdf.xacro include the desired Realsense model along with its gazebo description.
25+
In your robots urdf.xacro include the desired Realsense model along with its Gazebo description.
2626
```xml
2727
<xacro:include filename="$(find realsense2_description)/urdf/_d415.urdf.xacro" />
2828
<xacro:include filename="$(find realsense2_gz_description)/urdf/_d415.gazebo.xacro" />
@@ -50,6 +50,18 @@ This plugin can be started from your URDF or world.sdf file.
5050

5151
you can also refer to the the [example.urdf.xacro](./urdf/example_d415_gazebo.urdf.xacro) included.
5252

53+
## Gazebo only features
54+
55+
Gazebo offers a triggered based RGB camera that can be enabled by passing `triggered="true"` to the Gazebo description xacro.
56+
Currently this feature does not appear to not work with the RGBD sensor, but will hopefully be added soon.
57+
Switching the camera to only `trigger` when requested allows developers to better control the computation load required by each sensor.
58+
Note triggering is not a feature the Realsense hardware offers unfortunately.
59+
60+
To trigger the camera from the command line you can publish on the Gazebo topic `camera_name/trigger`.
61+
```bash
62+
ign topic -t "/name/trigger" -m Boolean -p "data: true" -n 1
63+
```
64+
5365
## Contributing
5466

5567
pre-commit is a tool to automatically run formatting checks on each commit, which saves you from manually running them.

urdf/_d405.gazebo.xacro

+41-77
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,62 @@
11
<?xml version="1.0"?>
22
<robot name="gazebo_d405" xmlns:xacro="http://www.ros.org/wiki/xacro" xmlns:ignition="http://gazebosim.org/schema">
33

4-
<!--
5-
Gazebo plugins can only be included once so this xacro assumes that a parent will include and configure them.
6-
This xacro requires Gazebo plugin:
7-
- ignition::gazebo::systems::Sensors
8-
to publish simulated RGBD camera data
4+
<xacro:include filename="$(find realsense2_gz_description)/urdf/rgb_camera.gazebo.xacro" />
5+
<xacro:include filename="$(find realsense2_gz_description)/urdf/rgbd_camera.gazebo.xacro" />
96

10-
For example:
11-
<gazebo>
12-
<plugin filename="libignition-gazebo-sensors-system.so" name="ignition::gazebo::systems::Sensors">
13-
<render_engine>ogre2</render_engine>
14-
</plugin>
15-
</gazebo>
7+
<!-- Xacro args
8+
name: should match the name value passed to realsense2_description sensor xacro
9+
type: valid values [rgb or rgbd]. Sensor type you would like to simulate
10+
fps: the target frame rate of the camera images
11+
gz_topic_name: the topic name the image and camera_info are published to Gazebo topics
12+
image_width: See Realsense documentation for what the physical sensor supports
13+
image_height: See Realsense documentation for what the physical sensor supports
14+
trigger: valid values [true, false]. Only supported with 'type=rgb' and will only publish a single image when triggered on Gazebo topic '${name}/trigger'
15+
example command line trigger
16+
ign topic -t "/name/trigger" -m Boolean -p "data: true" -n 1
1617
-->
1718
<xacro:macro name="gazebo_d405" params="
1819
name:=camera
20+
type:=rgbd
1921
fps:=15
2022
gz_topic_name:=camera
2123
image_width:=1280
22-
image_height:=720">
24+
image_height:=720
25+
triggered:=false">
2326

2427
<!-- Realsense D405 RGB properties
2528
Assumptions:
29+
Parent system (URDF or sdf) will start the Gazebo Sensors plugin. See notes in the camera.gazebo.xacros.
2630
Simulated RGB and Depth sensors are in the same location as the RGB sensor of the physical camera.
2731
Simulated RGB and Depth sensors and have the same FOV as the RGB physical sensor.
2832
Note: physical hardware publishes pointcloud in `camera_depth_optical_frame` where this sensor will use
2933
the referenced camera color_frame. -->
30-
<xacro:property name="realsense_h_fov" value="${69 * pi/180}" />
31-
<xacro:property name="realsense_v_fov" value="${42 * pi/180}" />
32-
<xacro:property name="fx" value="${image_width * 0.5 / tan(realsense_h_fov * 0.5)}" />
33-
<xacro:property name="fy" value="${image_height * 0.5 / tan(realsense_v_fov * 0.5)}" />
34-
<xacro:property name="cx" value="${image_width * 0.5}" />
35-
<xacro:property name="cy" value="${image_height * 0.5}" />
34+
<xacro:property name="realsense_h_fov" value="${87 * pi/180}" />
35+
<xacro:property name="realsense_v_fov" value="${58 * pi/180}" />
36+
<xacro:property name="min_depth" value="0.07" />
37+
<xacro:property name="max_depth" value="0.5" />
3638

37-
<gazebo reference="${name}_color_frame">
38-
<sensor name="${name}" type="rgbd_camera">
39-
<camera>
40-
<horizontal_fov>${realsense_h_fov}</horizontal_fov>
41-
<image>
42-
<width>${image_width}</width>
43-
<height>${image_height}</height>
44-
<format>RGB_INT8</format>
45-
</image>
46-
<clip>
47-
<near>0.028</near>
48-
<far>5</far>
49-
</clip>
50-
<distortion>
51-
<k1>0.0</k1>
52-
<k2>0.0</k2>
53-
<k3>0.0</k3>
54-
<p1>0.0</p1>
55-
<p2>0.0</p2>
56-
<center>0.5 0.5</center>
57-
</distortion>
58-
<lens>
59-
<intrinsics>
60-
<fx>${fx}</fx>
61-
<fy>${fy}</fy>
62-
<cx>${cx}</cx>
63-
<cy>${cy}</cy>
64-
<s>0</s>
65-
</intrinsics>
66-
<projection>
67-
<p_fx>${fx}</p_fx>
68-
<p_fy>${fy}</p_fy>
69-
<p_cx>${cx}</p_cx>
70-
<p_cy>${cy}</p_cy>
71-
<tx>0</tx>
72-
<ty>0</ty>
73-
</projection>
74-
</lens>
75-
<noise>
76-
<type>gaussian</type>
77-
<mean>0</mean>
78-
<stddev>0.00</stddev>
79-
</noise>
80-
<depth_camera>
81-
<clip>
82-
<near>0.028</near>
83-
<far>5</far>
84-
</clip>
85-
</depth_camera>
86-
<optical_frame_id>${name}_color_optical_frame</optical_frame_id>
87-
</camera>
88-
<ignition_frame_id>${name}_color_frame</ignition_frame_id>
89-
<always_on>1</always_on>
90-
<update_rate>${fps}</update_rate>
91-
<visualize>false</visualize>
92-
<topic>${gz_topic_name}</topic>
93-
<enable_metrics>false</enable_metrics>
94-
</sensor>
95-
</gazebo>
39+
<xacro:if value="${type == 'rgbd'}">
40+
<xacro:gazebo_rgbd name="${name}"
41+
fps="${fps}"
42+
gz_topic_name="${gz_topic_name}"
43+
image_width="${image_width}"
44+
image_height="${image_height}"
45+
h_fov="${realsense_h_fov}"
46+
v_fov="${realsense_v_fov}"
47+
min_depth="${min_depth}"
48+
max_depth="${max_depth}"/>
49+
</xacro:if>
50+
<xacro:if value="${type == 'rgb'}">
51+
<xacro:gazebo_rgb name="${name}"
52+
fps="${fps}"
53+
gz_topic_name="${gz_topic_name}"
54+
image_width="${image_width}"
55+
image_height="${image_height}"
56+
h_fov="${realsense_h_fov}"
57+
v_fov="${realsense_v_fov}"
58+
triggered="${triggered}"/>
59+
</xacro:if>
9660

9761
</xacro:macro>
9862
</robot>

urdf/_d415.gazebo.xacro

+39-75
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,62 @@
11
<?xml version="1.0"?>
22
<robot name="gazebo_d415" xmlns:xacro="http://www.ros.org/wiki/xacro" xmlns:ignition="http://gazebosim.org/schema">
33

4-
<!--
5-
Gazebo plugins can only be included once so this xacro assumes that a parent will include and configure them.
6-
This xacro requires Gazebo plugin:
7-
- ignition::gazebo::systems::Sensors
8-
to publish simulated RGBD camera data
4+
<xacro:include filename="$(find realsense2_gz_description)/urdf/rgb_camera.gazebo.xacro" />
5+
<xacro:include filename="$(find realsense2_gz_description)/urdf/rgbd_camera.gazebo.xacro" />
96

10-
For example:
11-
<gazebo>
12-
<plugin filename="libignition-gazebo-sensors-system.so" name="ignition::gazebo::systems::Sensors">
13-
<render_engine>ogre2</render_engine>
14-
</plugin>
15-
</gazebo>
7+
<!-- Xacro args
8+
name: should match the name value passed to realsense2_description sensor xacro
9+
type: valid values [rgb or rgbd]. Sensor type you would like to simulate
10+
fps: the target frame rate of the camera images
11+
gz_topic_name: the topic name the image and camera_info are published to Gazebo topics
12+
image_width: See Realsense documentation for what the physical sensor supports
13+
image_height: See Realsense documentation for what the physical sensor supports
14+
trigger: valid values [true, false]. Only supported with 'type=rgb' and will only publish a single image when triggered on Gazebo topic '${name}/trigger'
15+
example command line trigger
16+
ign topic -t "/name/trigger" -m Boolean -p "data: true" -n 1
1617
-->
1718
<xacro:macro name="gazebo_d415" params="
1819
name:=camera
20+
type:=rgbd
1921
fps:=15
2022
gz_topic_name:=camera
2123
image_width:=1280
22-
image_height:=720">
24+
image_height:=720
25+
triggered:=false">
2326

2427
<!-- Realsense D415 RGB properties
2528
Assumptions:
29+
Parent system (URDF or sdf) will start the Gazebo Sensors plugin. See notes in the camera.gazebo.xacros.
2630
Simulated RGB and Depth sensors are in the same location as the RGB sensor of the physical camera.
2731
Simulated RGB and Depth sensors and have the same FOV as the RGB physical sensor.
2832
Note: physical hardware publishes pointcloud in `camera_depth_optical_frame` where this sensor will use
2933
the referenced camera color_frame. -->
3034
<xacro:property name="realsense_h_fov" value="${69 * pi/180}" />
3135
<xacro:property name="realsense_v_fov" value="${42 * pi/180}" />
32-
<xacro:property name="fx" value="${image_width * 0.5 / tan(realsense_h_fov * 0.5)}" />
33-
<xacro:property name="fy" value="${image_height * 0.5 / tan(realsense_v_fov * 0.5)}" />
34-
<xacro:property name="cx" value="${image_width * 0.5}" />
35-
<xacro:property name="cy" value="${image_height * 0.5}" />
36+
<xacro:property name="min_depth" value="0.45" />
37+
<xacro:property name="max_depth" value="3.0" />
3638

37-
<gazebo reference="${name}_color_frame">
38-
<sensor name="${name}" type="rgbd_camera">
39-
<camera>
40-
<horizontal_fov>${realsense_h_fov}</horizontal_fov>
41-
<image>
42-
<width>${image_width}</width>
43-
<height>${image_height}</height>
44-
<format>RGB_INT8</format>
45-
</image>
46-
<clip>
47-
<near>0.45</near>
48-
<far>5</far>
49-
</clip>
50-
<distortion>
51-
<k1>0.0</k1>
52-
<k2>0.0</k2>
53-
<k3>0.0</k3>
54-
<p1>0.0</p1>
55-
<p2>0.0</p2>
56-
<center>0.5 0.5</center>
57-
</distortion>
58-
<lens>
59-
<intrinsics>
60-
<fx>${fx}</fx>
61-
<fy>${fy}</fy>
62-
<cx>${cx}</cx>
63-
<cy>${cy}</cy>
64-
<s>0</s>
65-
</intrinsics>
66-
<projection>
67-
<p_fx>${fx}</p_fx>
68-
<p_fy>${fy}</p_fy>
69-
<p_cx>${cx}</p_cx>
70-
<p_cy>${cy}</p_cy>
71-
<tx>0</tx>
72-
<ty>0</ty>
73-
</projection>
74-
</lens>
75-
<noise>
76-
<type>gaussian</type>
77-
<mean>0</mean>
78-
<stddev>0.00</stddev>
79-
</noise>
80-
<depth_camera>
81-
<clip>
82-
<near>0.45</near>
83-
<far>5</far>
84-
</clip>
85-
</depth_camera>
86-
<optical_frame_id>${name}_color_optical_frame</optical_frame_id>
87-
</camera>
88-
<ignition_frame_id>${name}_color_frame</ignition_frame_id>
89-
<always_on>1</always_on>
90-
<update_rate>${fps}</update_rate>
91-
<visualize>false</visualize>
92-
<topic>${gz_topic_name}</topic>
93-
<enable_metrics>false</enable_metrics>
94-
</sensor>
95-
</gazebo>
39+
<xacro:if value="${type == 'rgbd'}">
40+
<xacro:gazebo_rgbd name="${name}"
41+
fps="${fps}"
42+
gz_topic_name="${gz_topic_name}"
43+
image_width="${image_width}"
44+
image_height="${image_height}"
45+
h_fov="${realsense_h_fov}"
46+
v_fov="${realsense_v_fov}"
47+
min_depth="${min_depth}"
48+
max_depth="${max_depth}"/>
49+
</xacro:if>
50+
<xacro:if value="${type == 'rgb'}">
51+
<xacro:gazebo_rgb name="${name}"
52+
fps="${fps}"
53+
gz_topic_name="${gz_topic_name}"
54+
image_width="${image_width}"
55+
image_height="${image_height}"
56+
h_fov="${realsense_h_fov}"
57+
v_fov="${realsense_v_fov}"
58+
triggered="${triggered}"/>
59+
</xacro:if>
9660

9761
</xacro:macro>
9862
</robot>

0 commit comments

Comments
 (0)