key_teleop

This file is ai generated. Do not edit this file directly. Instead, edit the node source code and run the generate-node-docs command to update this file.

Description

The key_teleop node provides a terminal-based keyboard teleoperation interface for controlling robot velocity using arrow keys. It uses curses to create a text-based interface in the terminal, allowing users to control linear and angular velocities with simple key presses.

Publishers

Topic

Type

Description

key_vel

geometry_msgs/msg/TwistStamped or geometry_msgs/msg/Twist

Publishes velocity commands based on arrow key inputs. Type depends on twist_stamped_enabled parameter

Parameters

Parameter

Type

Default

Description

twist_stamped_enabled

bool

true

If true, publishes TwistStamped messages; if false, publishes Twist messages

hz

int

10

Publishing rate in Hz

forward_rate

double

0.8

Linear velocity scale factor for forward movement (m/s)

backward_rate

double

0.5

Linear velocity scale factor for backward movement (m/s)

rotation_rate

double

1.0

Angular velocity scale factor for rotation (rad/s)

Example Usage

Basic Launch

ros2 run key_teleop key_teleop

Launch with Parameters

ros2 run key_teleop key_teleop --ros-args \
  -p hz:=20 \
  -p forward_rate:=1.0 \
  -p backward_rate:=0.5 \
  -p rotation_rate:=2.0 \
  -p twist_stamped_enabled:=false

Launch with Configuration File

ros2 run key_teleop key_teleop --ros-args --params-file /path/to/config.yaml

Example Configuration File

key_teleop:
  ros__parameters:
    hz: 10
    forward_rate: 0.8
    backward_rate: 0.5
    rotation_rate: 1.0
    twist_stamped_enabled: true

Example Launch File

from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import os

def generate_launch_description():
    config_file = os.path.join(
        get_package_share_directory('key_teleop'),
        'config', 'key_teleop.yaml'
    )
    
    return LaunchDescription([
        Node(
            package='key_teleop',
            executable='key_teleop',
            parameters=[config_file],
            output='screen',
            emulate_tty=True  # Important for curses to work properly
        )
    ])

Remap Output Topic

ros2 run key_teleop key_teleop --ros-args -r key_vel:=cmd_vel

Operation

Keyboard Controls

Key

Action

(Up Arrow)

Move forward

(Down Arrow)

Move backward

(Left Arrow)

Rotate left (counterclockwise)

(Right Arrow)

Rotate right (clockwise)

q

Quit the node

Behavior

  • Multiple arrow keys can be pressed simultaneously for combined motion

  • Key presses are effective for 0.5 seconds; hold the key to maintain velocity

  • Linear velocity is multiplied by forward_rate when moving forward, backward_rate when moving backward

  • Angular velocity is multiplied by rotation_rate

  • The terminal displays current linear and angular velocities in real-time

Notes

  • The node requires a terminal that supports curses (most Linux/Unix terminals)

  • The node uses a text-based interface, so it runs directly in the terminal without a separate window

  • Velocity commands are published at the rate specified by the hz parameter

  • Keys have a 0.5-second timeout; if not pressed again within that time, the velocity component becomes zero

  • The frame_id in published TwistStamped messages is set to “key_teleop”

  • Linear velocities are in m/s, angular velocities are in rad/s

  • For proper operation in launch files, use emulate_tty=True and output='screen'