From 54269463816faa53ec5bcba9fdfa9d62184293ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Wed, 6 Nov 2024 19:39:22 +0100 Subject: [PATCH 1/2] Refactor magnetometer demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- ros_gz_sim_demos/CMakeLists.txt | 6 ++ ros_gz_sim_demos/README.md | 2 +- ros_gz_sim_demos/config/magnetometer.yaml | 9 +++ .../launch/magnetometer.launch.py | 63 ------------------- .../launch/magnetometer.launch.xml | 6 ++ 5 files changed, 22 insertions(+), 64 deletions(-) create mode 100644 ros_gz_sim_demos/config/magnetometer.yaml delete mode 100644 ros_gz_sim_demos/launch/magnetometer.launch.py create mode 100644 ros_gz_sim_demos/launch/magnetometer.launch.xml diff --git a/ros_gz_sim_demos/CMakeLists.txt b/ros_gz_sim_demos/CMakeLists.txt index 8e0f580a..9b69104b 100644 --- a/ros_gz_sim_demos/CMakeLists.txt +++ b/ros_gz_sim_demos/CMakeLists.txt @@ -9,6 +9,12 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() endif() +install( + DIRECTORY + config/ + DESTINATION share/${PROJECT_NAME}/config +) + install( DIRECTORY launch/ diff --git a/ros_gz_sim_demos/README.md b/ros_gz_sim_demos/README.md index c404a4dc..8360cc92 100644 --- a/ros_gz_sim_demos/README.md +++ b/ros_gz_sim_demos/README.md @@ -126,7 +126,7 @@ Publishes IMU readings. Publishes magnetic field readings. - ros2 launch ros_gz_sim_demos magnetometer.launch.py + ros2 launch ros_gz_sim_demos magnetometer.launch.xml ![](images/magnetometer_demo.png) diff --git a/ros_gz_sim_demos/config/magnetometer.yaml b/ros_gz_sim_demos/config/magnetometer.yaml new file mode 100644 index 00000000..3af2e370 --- /dev/null +++ b/ros_gz_sim_demos/config/magnetometer.yaml @@ -0,0 +1,9 @@ +# Magnetometer configuration. +- ros_topic_name: "/magnetometer" + gz_topic_name: "/magnetometer" + ros_type_name: "sensor_msgs/msg/MagneticField" + gz_type_name: "gz.msgs.Magnetometer" + subscriber_queue: 5 + publisher_queue: 6 + lazy: false + direction: GZ_TO_ROS diff --git a/ros_gz_sim_demos/launch/magnetometer.launch.py b/ros_gz_sim_demos/launch/magnetometer.launch.py deleted file mode 100644 index e35b8487..00000000 --- a/ros_gz_sim_demos/launch/magnetometer.launch.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2019 Open Source Robotics Foundation, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os - -from ament_index_python.packages import get_package_share_directory - -from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument -from launch.actions import IncludeLaunchDescription -from launch.conditions import IfCondition -from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration - -from launch_ros.actions import Node - - -def generate_launch_description(): - - pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim') - - gz_sim = IncludeLaunchDescription( - PythonLaunchDescriptionSource( - os.path.join(pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py')), - launch_arguments={ - 'gz_args': '-r sensors.sdf' - }.items(), - ) - - # RQt - rqt = Node( - package='rqt_topic', - executable='rqt_topic', - arguments=['-t'], - condition=IfCondition(LaunchConfiguration('rqt')) - ) - - # Bridge - bridge = Node( - package='ros_gz_bridge', - executable='parameter_bridge', - arguments=['/magnetometer@sensor_msgs/msg/MagneticField@gz.msgs.Magnetometer'], - output='screen' - ) - - return LaunchDescription([ - gz_sim, - DeclareLaunchArgument('rqt', default_value='true', - description='Open RQt.'), - bridge, - rqt - ]) diff --git a/ros_gz_sim_demos/launch/magnetometer.launch.xml b/ros_gz_sim_demos/launch/magnetometer.launch.xml new file mode 100644 index 00000000..065e57da --- /dev/null +++ b/ros_gz_sim_demos/launch/magnetometer.launch.xml @@ -0,0 +1,6 @@ + + + + + + From a6d2421e9b0f050265cb656f2aee75e77e397a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Fri, 22 Nov 2024 18:19:44 +0100 Subject: [PATCH 2/2] Tweak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- ros_gz_sim_demos/config/magnetometer.yaml | 7 ++----- ros_gz_sim_demos/launch/magnetometer.launch.xml | 10 ++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ros_gz_sim_demos/config/magnetometer.yaml b/ros_gz_sim_demos/config/magnetometer.yaml index 3af2e370..e5d38d2e 100644 --- a/ros_gz_sim_demos/config/magnetometer.yaml +++ b/ros_gz_sim_demos/config/magnetometer.yaml @@ -1,9 +1,6 @@ # Magnetometer configuration. -- ros_topic_name: "/magnetometer" - gz_topic_name: "/magnetometer" +- topic_name: "/magnetometer" ros_type_name: "sensor_msgs/msg/MagneticField" gz_type_name: "gz.msgs.Magnetometer" - subscriber_queue: 5 - publisher_queue: 6 - lazy: false + lazy: true direction: GZ_TO_ROS diff --git a/ros_gz_sim_demos/launch/magnetometer.launch.xml b/ros_gz_sim_demos/launch/magnetometer.launch.xml index 065e57da..10639b43 100644 --- a/ros_gz_sim_demos/launch/magnetometer.launch.xml +++ b/ros_gz_sim_demos/launch/magnetometer.launch.xml @@ -1,6 +1,12 @@ - - + +