同ROS1一样我们只需要安装相应的包后就可以使用teleop_twist_keyboard
包发出cmd_vel
topic控制我们的机器人小车
sudo apt-get install ros-galactic-teleop-twist-keyboard
➜ ros2 launch pibot_bringup bringup_launch.py
➜ ros2 run teleop_twist_keyboard teleop_twist_keyboard
sudo apt-get install ros-galactic-teleop-twist-joy
对照teleop-twist-joy
源码,只需要下面2步
launch
文件config
文件teleop_twist_joy_node:
ros__parameters:
axis_linear: # 遥感索引1的值表示控制linear 索引rostopic echo joy可以看出axes数字
x: 1
scale_linear: # 低速运动linear最大值
x: 0.25
scale_linear_turbo: # 高度速运动linear最大值
x: 0.6
axis_angular: # 遥感索引0的表示angular方向
yaw: 0
scale_angular: # 低速运动angular最大值
yaw: 1.0
scale_angular_turbo: # 高度速运动angular最大值
yaw: 1.2
enable_button: 0 # 实现低速运动使能键
enable_turbo_button: 1 # 实现高速度运动使能键
其他型号可以修改该文件
➜ ros2 launch pibot_bringup bringup_launch.py
➜ ros2 launch pibot_bringup joystick_launch.py
[INFO] [launch]: All log files can be found below /home/pibot/.ros/log/2022-05-09-00-17-47-423105-david-ThinkPad-E420-168918
[INFO] [launch]: Default logging verbosity is set to INFO
[WARNING] [launch_ros.actions.node]: Parameter file path is not a file: /home/pibot/ros2_ws/install/pibot_bringup/share/pibot_bringup/config/joystick.config.yaml
[INFO] [joy_node-1]: process started with pid [168920]
[INFO] [teleop_node-2]: process started with pid [168922]
[teleop_node-2] [INFO] [1652026667.796153667] [TeleopTwistJoy]: Teleop enable button 5.
[teleop_node-2] [INFO] [1652026667.797377697] [TeleopTwistJoy]: Linear axis x on 5 at scale 0.500000.
[teleop_node-2] [INFO] [1652026667.798254571] [TeleopTwistJoy]: Angular axis yaw on 2 at scale 0.500000.
提示有个警告,配置文件没有找到,显然是编译安装的时候没有配置,同launch文件一样需要在CMakeLists.txt
新增
install(
DIRECTORY launch config
DESTINATION share/${PROJECT_NAME}
)
再次编译后运行,没有警告了
因为配置了enable key
,需要按住button X
,再同时控制左遥感即可控制小车
对于全向机器人小车,我们可以配置不同遥感,分别控制xy线速度和角速度
teleop_twist_joy_node:
ros__parameters:
axis_linear: # 遥感索引1的值表示控制linear 索引rostopic echo joy可以看出axes数字
x: 1
y: 0
scale_linear: # 低速运动linear最大值
x: 0.25
y: 0.25
scale_linear_turbo: # 高度速运动linear最大值
x: 0.6
axis_angular: # 遥感索引0的表示angular方向
yaw: 3
scale_angular: # 低速运动angular最大值
yaw: 1.0
scale_angular_turbo: # 高度速运动angular最大值
yaw: 1.2
enable_button: 0 # 实现低速运动使能键
enable_turbo_button: -1 # 实现高速度运动使能键
运行是只需要使用该文件配置即可
➜ ros2 launch pibot_bringup joystick_launch.py joy_config:=joystick-holonomic
本文代码https://gitee.com/pibot/pibot_bringup/tree/dfd86ed8fa3f038d69dc28a6cf8b4d8a54f7e35a