← Back to Docs

Bluetooth Gamepad Teleoperation

Install controller packages, set up a custom teleop package and drive the robot with a Bluetooth gamepad.
1

Use a Bluetooth Gamepad for Teleoperation

Install the ROS2 joy and teleop packages, create a custom package and launch file to read a Bluetooth gamepad, build the workspace and verify that velocity commands are published.

This module guides you through installing the necessary ROS2 packages to interface with a Bluetooth gamepad, creating a new workspace and package to store your launch and configuration files, building the workspace and launching the teleoperation node. You will need a paired Bluetooth controller connected to your Raspberry Pi.

bash
sudo apt update
sudo apt install ros-${ROS_DISTRO}-joy ros-${ROS_DISTRO}-teleop-twist-joy
bash
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_cmake common_robot
cd common_robot
mkdir launch
mkdir config

Create a YAML configuration file under config/joystick.yaml with the mapping for your controller. The contents will vary by device; refer to the ROS2 teleop-twist-joy documentation for details. For example:

axis_linear: 1
axis_angular: 0
scale_linear: 0.5
scale_angular: 1.0

Create a launch file launch/joystick.launch.py that loads the joy and teleop_twist_joy nodes with your configuration file. An example launch file:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(package='joy', executable='joy_node', name='joy_node'),
        Node(package='teleop_twist_joy', executable='teleop_node', name='teleop_twist_joy',
             parameters=[{'config_file': 'config/joystick.yaml'}],
             remappings=[('/cmd_vel', '/${ROS_NAME}/cmd_vel')])
    ])

```

bash
cd ~/ros2_ws
colcon build --symlink-install
bash
source install/setup.bash
bash
ros2 launch common_robot joystick.launch.py

Subscribe to our newsletter

The latest educational robotics news and articles, sent to your inbox weekly.