From b6d17275b972244aea961f6d1babd348beef8938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20=C5=81agan?= Date: Thu, 19 Dec 2024 12:31:15 +0100 Subject: [PATCH] Add robot specific velocity presets (#3) --- README.md | 5 ++-- compose.yaml | 2 +- .../config/crsf_teleop_lynx.yaml | 4 +-- ...f_teleop.yaml => crsf_teleop_panther.yaml} | 4 +-- .../launch/teleop.launch.py | 28 +++++++++++++++++-- husarion_ugv_crsf_teleop/setup.py | 2 +- 6 files changed, 34 insertions(+), 11 deletions(-) rename config/crsf_teleop.yaml => husarion_ugv_crsf_teleop/config/crsf_teleop_lynx.yaml (64%) rename husarion_ugv_crsf_teleop/config/{crsf_teleop.yaml => crsf_teleop_panther.yaml} (63%) diff --git a/README.md b/README.md index 0349562..6b69f1f 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,12 @@ This ROS 2 package allows you to control robots using a CRSF compatible remote c ## Launch Files -- `teleop.launch.py`: Launches crsf_teleop_node node. Automatically respawns node if it exits. Node's namespace can be set using the `namespace` launch argument. +- `teleop.launch.py`: Launches crsf_teleop_node node. Automatically respawns node if it exits. Node's namespace can be set using the `namespace` launch argument. Custom parameters file can be provided by setting the `params_file` launch argument. ## Configuration Files -- [`crsf_teleop.yaml`](./config/crsf_teleop.yaml): Sets default parameter values for the crsf_teleop_node when `teleop.launch.py` is launched. +- [`crsf_teleop_panther.yaml`](./husarion_ugv_crsf_teleop/config/crsf_teleop_panther.yaml): Sets default Panther robot parameter values for the crsf_teleop_node when `teleop.launch.py` is launched. +- [`crsf_teleop_lynx.yaml`](./husarion_ugv_crsf_teleop/config/crsf_teleop_lynx.yaml): Sets default Lynx robot parameter values for the crsf_teleop_node when `teleop.launch.py` is launched. ## ROS Nodes diff --git a/compose.yaml b/compose.yaml index 1245f05..3434121 100644 --- a/compose.yaml +++ b/compose.yaml @@ -9,8 +9,8 @@ services: environment: - RMW_IMPLEMENTATION=${RMW_IMPLEMENTATION:-rmw_cyclonedds_cpp} - ROS_DOMAIN_ID=${ROS_DOMAIN_ID:-0} + - ROBOT_MODEL_NAME=${ROBOT_MODEL_NAME:-panther} volumes: - /dev:/dev - - ./config/crsf_teleop.yaml:/ros2_ws/install/husarion_ugv_crsf_teleop/share/husarion_ugv_crsf_teleop/config/crsf_teleop.yaml command: > ros2 launch husarion_ugv_crsf_teleop teleop.launch.py namespace:=panther diff --git a/config/crsf_teleop.yaml b/husarion_ugv_crsf_teleop/config/crsf_teleop_lynx.yaml similarity index 64% rename from config/crsf_teleop.yaml rename to husarion_ugv_crsf_teleop/config/crsf_teleop_lynx.yaml index 5a21742..54b86dd 100644 --- a/config/crsf_teleop.yaml +++ b/husarion_ugv_crsf_teleop/config/crsf_teleop_lynx.yaml @@ -5,5 +5,5 @@ baud: 576000 e_stop_republish: false enable_cmd_vel_silence_switch: false - linear_speed_presets: [0.5, 1.0, 2.0] - angular_speed_presets: [0.5, 1.0, 2.0] + linear_speed_presets: [0.5, 0.9, 1.5] + angular_speed_presets: [0.45, 0.9, 2.0] diff --git a/husarion_ugv_crsf_teleop/config/crsf_teleop.yaml b/husarion_ugv_crsf_teleop/config/crsf_teleop_panther.yaml similarity index 63% rename from husarion_ugv_crsf_teleop/config/crsf_teleop.yaml rename to husarion_ugv_crsf_teleop/config/crsf_teleop_panther.yaml index 5a21742..dfa039d 100644 --- a/husarion_ugv_crsf_teleop/config/crsf_teleop.yaml +++ b/husarion_ugv_crsf_teleop/config/crsf_teleop_panther.yaml @@ -5,5 +5,5 @@ baud: 576000 e_stop_republish: false enable_cmd_vel_silence_switch: false - linear_speed_presets: [0.5, 1.0, 2.0] - angular_speed_presets: [0.5, 1.0, 2.0] + linear_speed_presets: [0.4, 1.2, 2.0] + angular_speed_presets: [0.39, 0.78, 1.88] diff --git a/husarion_ugv_crsf_teleop/launch/teleop.launch.py b/husarion_ugv_crsf_teleop/launch/teleop.launch.py index 4d4be19..4adb9e6 100644 --- a/husarion_ugv_crsf_teleop/launch/teleop.launch.py +++ b/husarion_ugv_crsf_teleop/launch/teleop.launch.py @@ -20,6 +20,7 @@ EnvironmentVariable, LaunchConfiguration, PathJoinSubstitution, + PythonExpression, ) from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare @@ -28,6 +29,27 @@ def generate_launch_description(): husarion_ugv_crsf_teleop_dir = FindPackageShare("husarion_ugv_crsf_teleop") + robot_model = LaunchConfiguration("robot_model") + declare_robot_model_arg = DeclareLaunchArgument( + "robot_model", + default_value=EnvironmentVariable(name="ROBOT_MODEL_NAME", default_value="panther"), + description="Specify robot model.", + choices=["lynx", "panther"], + ) + + params_file = LaunchConfiguration("params_file") + declare_params_file_arg = DeclareLaunchArgument( + "params_file", + default_value=PathJoinSubstitution( + [ + husarion_ugv_crsf_teleop_dir, + "config", + PythonExpression(["'crsf_teleop_", robot_model, ".yaml'"]), + ] + ), + description="Path to the ROS2 parameters file to use for the launched node.", + ) + namespace = LaunchConfiguration("namespace") declare_namespace_arg = DeclareLaunchArgument( "namespace", @@ -39,9 +61,7 @@ def generate_launch_description(): package="husarion_ugv_crsf_teleop", executable="crsf_teleop_node", name="crsf_teleop", - parameters=[ - PathJoinSubstitution([husarion_ugv_crsf_teleop_dir, "config", "crsf_teleop.yaml"]), - ], + parameters=[params_file], namespace=namespace, emulate_tty=True, respawn=True, @@ -49,6 +69,8 @@ def generate_launch_description(): ) actions = [ + declare_robot_model_arg, + declare_params_file_arg, declare_namespace_arg, husarion_ugv_crsf_teleop_node, ] diff --git a/husarion_ugv_crsf_teleop/setup.py b/husarion_ugv_crsf_teleop/setup.py index f521755..20aaae9 100644 --- a/husarion_ugv_crsf_teleop/setup.py +++ b/husarion_ugv_crsf_teleop/setup.py @@ -25,7 +25,7 @@ packages=find_packages(exclude=["test"]), data_files=[ ("share/ament_index/resource_index/packages", ["resource/" + package_name]), - (os.path.join("share", package_name, "config"), ["config/crsf_teleop.yaml"]), + (os.path.join("share", package_name, "config"), glob(os.path.join("config", "*.yaml"))), (os.path.join("share", package_name), ["package.xml"]), ( os.path.join("share", package_name, "launch"),