ubuntu 16.04 + ros kinetic
1. 测试手柄
首先将手柄的接收器插到笔记本usb上
ls /dev/input/
可以看到下面多了一个叫js×的家伙,我这里是js0
➜ ~ ls /dev/input/
by-id/ event10% event14% event18% event21% event6% js0% mouse2%
by-path/ event11% event15% event19% event3% event7% mice%
event0% event12% event16% event2% event4% event8% mouse0%
event1% event13% event17% event20% event5% event9% mouse1%
然后使用jstest 测试,
sudo jstest /dev/input/js0
注意手柄要选择direct 模式 也就是手柄前侧xd切换按钮那里。
操作手柄的控制键或按钮可以看到打印信息的变化。
查看手柄的操作权限
ls -l /dev/input/js0
crw-rw---- 1 root dialout 13, 0 1月 20 09:35 /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
通过sudo chown 用户名 /dev/input/js0 命令可以改变所属用户:
2. 安装joy ROS 包
接下来安装ros的joy包 和joystick_driver
sudo apt install ros-kinetic-joy
sudo apt install ros_kinetic-joystick_driver
安装完成,启动joy节点之前要先设定一下这个节点所读取的手柄设备:
rosparam set joy_node/dev "/dev/input/js0"
然后开启joy节点
rosrun joy joy_node
如果能通过rostopic list看到joy主题,并通过echo看到内容
---
header:
seq: 148
stamp:
secs: 1547954326
nsecs: 706369210
frame_id: ''
axes: [1.0, 0.4140446186065674, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 149
stamp:
secs: 1547954326
nsecs: 710290891
frame_id: ''
axes: [1.0, 0.3706119656562805, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 150
stamp:
secs: 1547954326
nsecs: 714100347
frame_id: ''
axes: [1.0, 0.3380695879459381, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 151
stamp:
secs: 1547954326
nsecs: 718256244
frame_id: ''
axes: [1.0, 0.2946690618991852, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 152
stamp:
secs: 1547954326
nsecs: 722273356
frame_id: ''
axes: [1.0, 0.2186940312385559, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 153
stamp:
secs: 1547954326
nsecs: 726173242
frame_id: ''
axes: [1.0, 0.16443534195423126, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 154
stamp:
secs: 1547954326
nsecs: 730159527
frame_id: ''
axes: [1.0, 0.08846031129360199, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
---
header:
seq: 155
stamp:
secs: 1547954326
nsecs: 734090517
frame_id: ''
axes: [1.0, 0.012485282495617867, -0.0, -0.0, 0.0, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
在运行 rosrun joy joy_node 的时候报错
Couldn't find executable named joy_node below /opt/ros/kinetic/share/joy
可以查看 https://blog.csdn.net/p942005405/article/details/86560370解决