Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gazebo_static_camera: allow setting resolution and update-rate #172

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# and limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

import tempfile
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration
from launch.substitutions.path_join_substitution import PathJoinSubstitution

Expand All @@ -29,6 +29,15 @@

DeclareLaunchArgument('world_name', default_value='default',
description='World name'),

DeclareLaunchArgument('update_rate', default_value='5',
description='Update rate of the sensor'),

DeclareLaunchArgument('image_width', default_value='320',
description='Width of camera image'),

DeclareLaunchArgument('image_height', default_value='240',
description='Height of camera image'),
]

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

camera_name = LaunchConfiguration('camera_name')
world_name = LaunchConfiguration('world_name')
update_rate = LaunchConfiguration('update_rate')
image_width = LaunchConfiguration('image_width')
image_height = LaunchConfiguration('image_height')
camera_sdf = tempfile.NamedTemporaryFile(prefix='gazebo_static_camera_', suffix='.sdf', delete=False)

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

camera_sdf_xacro = ExecuteProcess(
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'])])

camera_bridge = Node(
package='ros_gz_bridge',
executable='parameter_bridge',
Expand Down Expand Up @@ -80,11 +96,12 @@ def generate_launch_description():
'-R', roll,
'-P', pitch,
'-Y', yaw,
'-file', PathJoinSubstitution([gazebo_static_camera_dir, 'models', 'camera.sdf'])],
'-file', camera_sdf.name],
output='screen'
)

ld = LaunchDescription(ARGUMENTS)
ld.add_action(camera_sdf_xacro)
ld.add_action(camera_bridge)
ld.add_action(spawn_camera)
return ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version='1.0'?>
<sdf version="1.4">
<sdf version="1.4" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:arg name="image_width" default="320"/>
<xacro:arg name="image_height" default="240"/>
<xacro:arg name="update_rate" default="5"/>

<model name="camera">
<static>true</static>
<link name="link">
Expand Down Expand Up @@ -30,16 +34,16 @@
<camera>
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>320</width>
<height>240</height>
<width>$(arg image_width)</width>
<height>$(arg image_height)</height>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
</camera>
<always_on>1</always_on>
<update_rate>5</update_rate>
<update_rate>$(arg update_rate)</update_rate>
<visualize>true</visualize>
</sensor>
</link>
Expand Down
1 change: 1 addition & 0 deletions simulation/gazebo/gazebo_static_camera/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<exec_depend>rclpy</exec_depend>
<exec_depend>ros_gz_bridge</exec_depend>
<exec_depend>ros_ign_gazebo</exec_depend>
<exec_depend>xacro</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
Expand Down