[3/9/24]
Teleoperation
https://articulatedrobotics.xyz/tutorials/mobile-robot/applications/teleop/
- Teleoperation usually consist of two parts:
- A way to send command signals (typically velocities) TO the robot
- A way to receive sensor data FROM the robot (this may be optional if you are physically present with the robot)
Connecting to Joysticks/Gamepads in ROS
- Display the controllers that ROS can see
ros2 run joy joy_enumerate_devices
ID : GUID : GamePad : Mapped : Joystick Device Name
-------------------------------------------------------------------------------
0 : 03000000d62000003520000067010000 : true : false : Generic X-Box pad
- Run
joy_node
ros2 run joy joy_node # <-- Run in first terminal
- Check messages coming in through /joy
ros2 topic echo /joy # <-- Run in second terminal
Joystick Tester GUI
-
Optionally install
joy_tester
, a GUI program that displays button/axis numbers for testing joysticks in ROSsensor_msgs/Joy
messages are displayed in a more user-friendly format than usingtopic echo
-
Clone the repo and build the package
git clone https://github.com/joshnewans/joy_tester.git
cd ..
colcon build
- Run
joy_tester
source install/setup.bash
ros2 run joy_tester test_joy
Create launch file
- Create
joystick.launch.py
in the launch directory This specifies the path to a params file, declares a joy node that uses the params file, and launches the joy node
joystick.launch.py
joystick.launch.py
from launch import LaunchDescription from launch_ros.actions import Node import os from ament_index_python.packages import get_package_share_directory def generate_launch_description(): joy_params = os.path.join(get_package_share_directory('articubot_one'),'config','joystick.yaml') joy_node = Node( package='joy', executable='joy_node', parameters=[joy_params], ) return LaunchDescription([ joy_node ])
Create params file
- Create a
joystick.yaml
file in config directory- parameters specified are a subset of the full parameter list (See ROS 2 Driver for Generic Joysticks and Game Controllers )
joystick.yaml
joystick.yaml
joy_node: ros__parameters: device_id: 0 deadzone: 0.05 autorepeat_rate: 20.0
- Rebuild to add the new files and launch
# cd workspace
colcon build --symlink-install
source install/setup.bash
ros2 launch articubot_one joystick.launch.py
Convert Joy to Twist
- Convert raw joystick data coming through on /joy to a Twist message using teleop_twist_joy package
- Add teleop_node to launch file
teleop_node = Node(
package='teleop_twist_joy',
executable='teleop_node',
name = 'teleop_node',
parameters=[joy_params],
# remappings=[('/cmd_vel', '/diff_cont/cmd_vel_unstamped')]
)
- Set the Twist parameters
- This allows you to specify:
- Which joystick axis to use
- Max speed in regular mode
- Max speed in turbo mode
- This allows you to specify:
# ... below the joy parameters
teleop_node:
ros__parameters:
axis_linear: # Left thumb stick vertical
x: 1
scale_linear:
x: 0.5
scale_linear_turbo:
x: 1.0
axis_angular: # Left thumb stick horizontal
yaw: 0
scale_angular:
yaw: 0.5
scale_angular_turbo:
yaw: 1.0
require_enable_button: true
enable_button: 6 # Left shoulder button
enable_turbo_button: 7 # Right shoulder button
-
rerun the launch file
-
See the values in another terminal
- When we move the sticks by themselves there should be nothing, when we hold the regular speed button down, we should get those regular speeds, and likewise the higher speeds with the turbo button.
ros2 topic echo /cmd_vel