1. 运行环境
操作系统: Ubuntu 14.04
ROS版本: ROS Indigo
2. 安装手柄驱动和包
依次输入以下命令安装
sudo apt-get install ros-indigo-joy(ROS相关项,Jetson TK1只安装这一个)
sudo apt-get install ros-indigo-joystick-drivers
rosdep install joy
rosmake joy
3. 使用步骤
3.1 将游戏手柄接口的用户群组更改为dialout群组
电脑插上游戏手柄后默认情况下游戏手柄接口名称为js0,其默认的所有者和群组都是root,即需要root权限才能进行操作。可以输入以下命令进行查看:
ls -l /dev/input/js0
输入以下命令更改js0的root群组为dialout群组:
sudo chgrp dialout /dev/input/js0
再次输入:ls -l /dev/input/js0 查看,若输出以下信息,则表示更改成功:
crw-rw-r--+ 1 root dialout 13, 0 10月 5 09:03 /dev/input/js0
3.2 测试手柄是否设置成功
确保在电脑上插上手柄接收器后,输入以下命令进行测试:
sudo jstest /dev/input/js0
按下手柄按键,终端上会显示按键信息,若没有出现则执行以下命令:
sudo apt-get install joystick
信息显示如下:
Driver version is 2.1.0.
Joystick (Xbox 360 Wireless Receiver) has 4 axes (X, Y, Rx, Ry)
and 17 buttons (BtnX, BtnY, BtnTL, BtnTR, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR, ?, ?, ?, (null), (null), (null), (null)).
Testing ... (interrupt to exit)
Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11:off 12:off 13:off 14:off Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11:off 12:off 13:off 14:off Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11:off 12:off 13:off 14:off Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:o
3.3 运行手柄节点
分别在两个终端下依次输入以下命令来开启ROS和joy_node节点:
roscore
rosrun joy joy_node
下面命令可以查看话题内容:
rostopic echo joy
按下按键可收到如下信息则表示成功,做项目时只需订阅这个话题:
header:
seq: 1
stamp:
secs: 1525826012
nsecs: 692879198
frame_id: ''
axes: [0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 2
stamp:
secs: 1525826012
nsecs: 696846275
frame_id: ''
axes: [0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 3
stamp:
secs: 1525826012
nsecs: 700968664
frame_id: ''
axes: [0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]