Skip to content

Commit d494834

Browse files
committed
initial commit
0 parents  commit d494834

14 files changed

+1024
-0
lines changed

.github/workflows/format.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Format
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
pre-commit:
12+
name: pre-commit
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v3
17+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# To use:
2+
#
3+
# pre-commit run -a
4+
#
5+
# Or:
6+
#
7+
# pre-commit install # (runs every time you commit in git)
8+
#
9+
# To update this file:
10+
#
11+
# pre-commit autoupdate
12+
#
13+
# See https://github.com/pre-commit/pre-commit
14+
15+
repos:
16+
# Standard hooks
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v5.0.0
19+
hooks:
20+
- id: check-ast
21+
- id: check-case-conflict
22+
- id: check-docstring-first
23+
- id: check-merge-conflict
24+
- id: check-symlinks
25+
- id: debug-statements
26+
- id: end-of-file-fixer
27+
- id: mixed-line-ending
28+
- id: fix-byte-order-marker
29+
- repo: https://github.com/psf/black
30+
rev: 24.10.0
31+
hooks:
32+
- id: black
33+
- repo: https://github.com/codespell-project/codespell
34+
rev: v2.3.0
35+
hooks:
36+
- id: codespell
37+
args: ['--write-changes']
38+
exclude: CHANGELOG.rst

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(realsense2_gz_description)
3+
4+
# find dependencies
5+
find_package(ament_cmake REQUIRED)
6+
7+
install(
8+
DIRECTORY urdf launch rviz world
9+
DESTINATION share/${PROJECT_NAME}
10+
)
11+
12+
ament_package()

LICENSE.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2024, Marques Rasmussen.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Realsense Gazebo description
2+
3+
[![Format Status](https://github.com/MarqRazz/realsense2_gz_description/actions/workflows/format.yaml/badge.svg)](https://github.com/MarqRazz/realsense2_gz_description/actions/workflows/format.yaml)
4+
5+
Description: This ROS 2 package is designed to be used in unison with [realsense2_description](https://github.com/IntelRealSense/realsense-ros/tree/ros2-master/realsense2_description) and allows for easy definition of Realsense cameras that can be simulated in Gazebo Fortress and newer. It may support other versions of Ignition Gazebo but this has not been tested.
6+
7+
## Running Example Launch
8+
9+
This package includes a launch file to start Gazebo, bridge the data to ROS 2 and display the simulated camera data in Rviz.
10+
11+
Once you have built this package and sourced your workspace you can run
12+
```bash
13+
ros2 launch realsense2_gz_description example_realsense_gazebo.launch.py
14+
```
15+
16+
> Note: you can specify `headless:=false` and it will also open the Gazebo GUI.
17+
18+
Which should start a simulated camera in Gazebo with a few objects in front of it. In the Rviz window that launches you can see the RGB images streaming along with the point cloud in the main view.
19+
20+
<img src="doc/realsense_gazebo.png" width="50%" >
21+
22+
23+
# Example Usage in URDF
24+
25+
In your robots urdf.xacro include the desired Realsense model along with its gazebo description.
26+
```xml
27+
<xacro:include filename="$(find realsense2_description)/urdf/_d415.urdf.xacro" />
28+
<xacro:include filename="$(find realsense2_gz_description)/urdf/_d415.gazebo.xacro" />
29+
30+
```
31+
Then call the xacros and specify the same `name` and other optional arguments.
32+
```xml
33+
<!-- URDF xacro-->
34+
<xacro:sensor_d415 parent="world" name="$(arg camera_name)" ...>
35+
<origin xyz="0 0 0" rpy="0 0 0"/>
36+
</xacro:sensor_d415>
37+
<!-- Gazebo xacro-->
38+
<xacro:gazebo_d415 name="$(arg camera_name)" .../>
39+
```
40+
41+
> Note: Gazebo plugins can only be included once so the xacros in this repo assume that a parent will include/run the required Sensors plugin when starting simulation.
42+
This plugin can be started from your URDF or world.sdf file.
43+
```xml
44+
<gazebo>
45+
<plugin filename="libignition-gazebo-sensors-system.so" name="ignition::gazebo::systems::Sensors">
46+
<render_engine>ogre2</render_engine>
47+
</plugin>
48+
</gazebo>
49+
```
50+
51+
you can also refer to the the [example.urdf.xacro](./urdf/example_d415_gazebo.urdf.xacro) included.
52+
53+
## Contributing
54+
55+
pre-commit is a tool to automatically run formatting checks on each commit, which saves you from manually running them.
56+
This repo requires formatting to pass before changes will be accepted.
57+
58+
Install pre-commit like this:
59+
60+
```
61+
pip3 install pre-commit
62+
```
63+
64+
Run this in the top directory of the repo to set up the git hooks:
65+
66+
```
67+
pre-commit install
68+
```

doc/realsense_gazebo.png

256 KB
Loading
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Author: Marq Rasmussen
2+
3+
from launch import LaunchDescription, LaunchContext
4+
from launch.actions import (
5+
DeclareLaunchArgument,
6+
IncludeLaunchDescription,
7+
OpaqueFunction,
8+
)
9+
from launch.launch_description_sources import PythonLaunchDescriptionSource
10+
from launch.conditions import IfCondition
11+
from launch.substitutions import (
12+
Command,
13+
FindExecutable,
14+
LaunchConfiguration,
15+
PathJoinSubstitution,
16+
)
17+
from launch_ros.actions import Node
18+
from launch_ros.substitutions import FindPackageShare
19+
from ament_index_python.packages import get_package_share_directory
20+
21+
22+
def launch_gz(context: LaunchContext):
23+
gz_world_file = (
24+
get_package_share_directory("realsense2_gz_description") + "/world/example.sdf"
25+
)
26+
# -r is to run the simulation on start
27+
# -v is the verbose level
28+
# 0: No output, 1: Error, 2: Error and warning, 3: Error, warning, and info, 4: Error, warning, info, and debug.
29+
sim_options = "-r -v 3"
30+
if LaunchConfiguration("headless").perform(context) == "true":
31+
sim_options += " -s" # -s is to only run the server (headless mode).
32+
gz_launch_description = IncludeLaunchDescription(
33+
PythonLaunchDescriptionSource(
34+
[FindPackageShare("ros_gz_sim"), "/launch/gz_sim.launch.py"]
35+
),
36+
launch_arguments=[("gz_args", [f"{sim_options} {gz_world_file}"])],
37+
)
38+
return [gz_launch_description]
39+
40+
41+
def generate_launch_description():
42+
declared_arguments = []
43+
declared_arguments.append(
44+
DeclareLaunchArgument("rviz", default_value="true", description="Launch RViz?")
45+
)
46+
declared_arguments.append(
47+
DeclareLaunchArgument(
48+
"headless", default_value="true", description="Launch Gazebo headless?"
49+
)
50+
)
51+
52+
# Initialize Arguments
53+
launch_rviz = LaunchConfiguration("rviz")
54+
55+
rviz_config_file = PathJoinSubstitution(
56+
[FindPackageShare("realsense2_gz_description"), "rviz", "example.rviz"]
57+
)
58+
59+
robot_description_content = Command(
60+
[
61+
PathJoinSubstitution([FindExecutable(name="xacro")]),
62+
" ",
63+
PathJoinSubstitution(
64+
[
65+
FindPackageShare("realsense2_gz_description"),
66+
"urdf",
67+
"example_d415_gazebo.urdf.xacro",
68+
]
69+
),
70+
" ",
71+
"camera_name:=gz_camera",
72+
" ",
73+
]
74+
)
75+
76+
robot_state_publisher_node = Node(
77+
package="robot_state_publisher",
78+
executable="robot_state_publisher",
79+
output="both",
80+
parameters=[
81+
{
82+
"use_sim_time": True,
83+
"robot_description": robot_description_content,
84+
}
85+
],
86+
)
87+
88+
rviz_node = Node(
89+
package="rviz2",
90+
executable="rviz2",
91+
name="rviz2",
92+
output="log",
93+
parameters=[{"use_sim_time": True}],
94+
arguments=["-d", rviz_config_file],
95+
condition=IfCondition(launch_rviz),
96+
)
97+
98+
ignition_spawn_entity = Node(
99+
package="ros_gz_sim",
100+
executable="create",
101+
output="screen",
102+
arguments=[
103+
"-string",
104+
robot_description_content,
105+
"-name",
106+
"realsense_camera",
107+
"-allow_renaming",
108+
"true",
109+
"-x",
110+
"0.0",
111+
"-y",
112+
"0.0",
113+
"-z",
114+
"0.0",
115+
"-R",
116+
"0.0",
117+
"-P",
118+
"0.0",
119+
"-Y",
120+
"0.0",
121+
],
122+
)
123+
124+
# Bridge the camera data to ROS and match the default topics that the real camera would publish
125+
# Note the gz_topic_name comes from _realsense_model.gazebo.xacro defaults which defaults to `camera` here.
126+
gazebo_bridge = Node(
127+
package="ros_gz_bridge",
128+
executable="parameter_bridge",
129+
parameters=[{"use_sim_time": True}],
130+
arguments=[
131+
"/camera/image@sensor_msgs/msg/Image[ignition.msgs.Image",
132+
"/camera/depth_image@sensor_msgs/msg/Image[ignition.msgs.Image",
133+
"/camera/points@sensor_msgs/msg/PointCloud2[ignition.msgs.PointCloudPacked",
134+
"/camera/camera_info@sensor_msgs/msg/CameraInfo[ignition.msgs.CameraInfo",
135+
"/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock",
136+
],
137+
remappings=[
138+
(
139+
"/camera/image",
140+
"/camera/camera/color/image_raw",
141+
),
142+
(
143+
"/camera/depth_image",
144+
"/camera/camera/depth_registered/image_rect",
145+
),
146+
(
147+
"/camera/points",
148+
"/camera/camera/depth/color/points",
149+
),
150+
(
151+
"/camera/camera_info",
152+
"/camera/camera/color/camera_info",
153+
),
154+
(
155+
"/camera/camera_info",
156+
"/camera/camera/depth_registered/camera_info",
157+
),
158+
],
159+
output="screen",
160+
)
161+
162+
nodes_to_start = [
163+
robot_state_publisher_node,
164+
rviz_node,
165+
OpaqueFunction(function=launch_gz),
166+
ignition_spawn_entity,
167+
gazebo_bridge,
168+
]
169+
170+
return LaunchDescription(declared_arguments + nodes_to_start)

package.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>realsense2_gz_description</name>
5+
<version>0.0.1</version>
6+
<description>URDF xacro(s) that enable simulating Realsense Cameras in Gazebo</description>
7+
<maintainer email="[email protected]">Marq Rasmussen</maintainer>
8+
<license>BSD</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>robot_state_publisher</depend>
13+
<depend>realsense2_description</depend>
14+
<depend>ros_gz_bridge</depend>
15+
<depend>ros_gz_sim</depend>
16+
<depend>rviz2</depend>
17+
<depend>sensor_msgs</depend>
18+
<depend>xacro</depend>
19+
20+
<export>
21+
<build_type>ament_cmake</build_type>
22+
</export>
23+
</package>

0 commit comments

Comments
 (0)