The difference when using "ros2 launch" and "ros2 run"


I can use “ros2 run teleop_twist_keyboard teleop_twist_keyboard” to move a robot. It works very well
But I want to run by a launch file for convenience, I use the launch file as:

import os

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import TimerAction

from ament_index_python.packages import get_package_share_directory

def generate_launch_description():

# region teleop_twist_keyboard
teleop_twist_keyboard_node = Node(
    name        = "teleop_twist_keyboard_node",
    package     = "teleop_twist_keyboard",
    executable  = "teleop_twist_keyboard",
    output      = "screen",
    emulate_tty = True,
# endregion

return LaunchDescription(

But an error happens, How to fix it?


Hi @NguyenDuyDuc ,

The commands ros2 launch ... and ros2 run ... cannot be interchangeably used.

If a package does not have a launch file, then you cannot launch that program.
You can use run command to execute any executables that are available in a package.

Due to a specific dependency in teleop_twist_keyboard program that depends on inputs from the terminal, that program does not have a launch file and only a run file. This is because the mentioned dependency is not a ROS2 package and also does not have a ROS2 package. Also, ROS2 does not support inputs from the terminal, which makes it difficult to make a teleop program purely using ROS2 packages / dependencies.

There are some work-arounds to get it working purely with ROS2, but that is quite tedious and not a simple solution (as far as I know), but it is doable.

Therefore, you don’t have a launch command for teleop. Only run command.


1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.