Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 6f05d87

Browse files
author
fred-labs
authored
gazebo_static_camera: allow setting resolution and update-rate (#172)
1 parent f18623f commit 6f05d87

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

simulation/gazebo/gazebo_static_camera/launch/spawn_static_camera_launch.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# and limitations under the License.
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
16-
16+
import tempfile
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import DeclareLaunchArgument
20+
from launch.actions import DeclareLaunchArgument, ExecuteProcess
2121
from launch.substitutions import LaunchConfiguration
2222
from launch.substitutions.path_join_substitution import PathJoinSubstitution
2323

@@ -29,6 +29,15 @@
2929

3030
DeclareLaunchArgument('world_name', default_value='default',
3131
description='World name'),
32+
33+
DeclareLaunchArgument('update_rate', default_value='5',
34+
description='Update rate of the sensor'),
35+
36+
DeclareLaunchArgument('image_width', default_value='320',
37+
description='Width of camera image'),
38+
39+
DeclareLaunchArgument('image_height', default_value='240',
40+
description='Height of camera image'),
3241
]
3342

3443
for pose_element in ['x', 'y', 'z', 'roll', 'pitch', 'yaw']:
@@ -41,10 +50,17 @@ def generate_launch_description():
4150

4251
camera_name = LaunchConfiguration('camera_name')
4352
world_name = LaunchConfiguration('world_name')
53+
update_rate = LaunchConfiguration('update_rate')
54+
image_width = LaunchConfiguration('image_width')
55+
image_height = LaunchConfiguration('image_height')
56+
camera_sdf = tempfile.NamedTemporaryFile(prefix='gazebo_static_camera_', suffix='.sdf', delete=False)
4457

4558
x, y, z = LaunchConfiguration('x'), LaunchConfiguration('y'), LaunchConfiguration('z')
4659
roll, pitch, yaw = LaunchConfiguration('roll'), LaunchConfiguration('pitch'), LaunchConfiguration('yaw')
4760

61+
camera_sdf_xacro = ExecuteProcess(
62+
cmd=['xacro', '-o', camera_sdf.name, ['update_rate:=', update_rate], ['image_width:=', image_width], ['image_height:=', image_height], PathJoinSubstitution([gazebo_static_camera_dir, 'models', 'camera.sdf.xacro'])])
63+
4864
camera_bridge = Node(
4965
package='ros_gz_bridge',
5066
executable='parameter_bridge',
@@ -80,11 +96,12 @@ def generate_launch_description():
8096
'-R', roll,
8197
'-P', pitch,
8298
'-Y', yaw,
83-
'-file', PathJoinSubstitution([gazebo_static_camera_dir, 'models', 'camera.sdf'])],
99+
'-file', camera_sdf.name],
84100
output='screen'
85101
)
86102

87103
ld = LaunchDescription(ARGUMENTS)
104+
ld.add_action(camera_sdf_xacro)
88105
ld.add_action(camera_bridge)
89106
ld.add_action(spawn_camera)
90107
return ld

simulation/gazebo/gazebo_static_camera/models/camera.sdf renamed to simulation/gazebo/gazebo_static_camera/models/camera.sdf.xacro

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?xml version='1.0'?>
2-
<sdf version="1.4">
2+
<sdf version="1.4" xmlns:xacro="http://ros.org/wiki/xacro">
3+
<xacro:arg name="image_width" default="320"/>
4+
<xacro:arg name="image_height" default="240"/>
5+
<xacro:arg name="update_rate" default="5"/>
6+
37
<model name="camera">
48
<static>true</static>
59
<link name="link">
@@ -30,16 +34,16 @@
3034
<camera>
3135
<horizontal_fov>1.047</horizontal_fov>
3236
<image>
33-
<width>320</width>
34-
<height>240</height>
37+
<width>$(arg image_width)</width>
38+
<height>$(arg image_height)</height>
3539
</image>
3640
<clip>
3741
<near>0.1</near>
3842
<far>100</far>
3943
</clip>
4044
</camera>
4145
<always_on>1</always_on>
42-
<update_rate>5</update_rate>
46+
<update_rate>$(arg update_rate)</update_rate>
4347
<visualize>true</visualize>
4448
</sensor>
4549
</link>

simulation/gazebo/gazebo_static_camera/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<exec_depend>rclpy</exec_depend>
1212
<exec_depend>ros_gz_bridge</exec_depend>
1313
<exec_depend>ros_ign_gazebo</exec_depend>
14+
<exec_depend>xacro</exec_depend>
1415

1516
<test_depend>ament_copyright</test_depend>
1617
<test_depend>ament_flake8</test_depend>

0 commit comments

Comments
 (0)