OpenDuckMini快速入门教程-手柄配置
文章说明
- 本教程主要介绍如何进行手柄配置
- 本教程中使用的是PS4进行测试,官方默认使用
XBOX ONE手柄 欢迎加入我们的openduckmini交流群,微信扫描右侧二维码立即进群交流
相关设备
OpenDuckMini套件: 采购地址
操作步骤
手柄匹对
- 启动蓝牙管理工具
$ bluetoothctl
- 开启蓝牙扫描
[bluetooth]# scan on
请确保手柄处于“配对模式”:
- Xbox 手柄:按住配对键(靠近 USB 口的小按钮)
- PS4 手柄:同时按住
Share+PS键,直到灯快速闪烁
- 当扫描到手柄信号时,终端会输出以下类似信息:
[NEW] Device 84:17:66:E8:84:88 Wireless Controller - 配对手柄设备
[bluetooth]# pair 84:17:66:E8:84:88
- 信任该设备
[bluetooth]# trust 84:17:66:E8:84:88
- 连接设备
[bluetooth]# connect 84:17:66:E8:84:88
一般情况下,比如PS4手柄匹对上后,原来快速闪烁的灯会变成常亮状态
退出蓝牙管理工具
[bluetooth]# exit
如果配对了但设备没响应或者一直不能自动连接上树莓派,可以先
remove设备再重新进行上面配对步骤
[bluetooth]# remove 84:17:66:E8:84:88
手柄测试
- 前面匹对完之后,重新开机后按下匹对键,手柄会自动连上树莓派
- 使用jstest方法进行测试
$ ls /dev/input/
by-id/ by-path/ event0 event1 event2 event3 event4 event5 event6 event7 js0 mice mouse0
$ jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (Wireless Controller) has 8 axes (X, Y, Z, Rx, Ry, Rz, Hat0X, Hat0Y)
and 13 buttons (BtnA, BtnB, BtnX, BtnY, BtnTL, BtnTR, BtnTL2, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes: 0: 516 1: 0 2:-32767 3: -1807 4: 3096 5:-32767 6: 0 7: 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
- 由于官方代码中用的是xboxone手柄,故PS4的控制代码需要自己编写
- 本站已分享我们使用的PS4的控制代码上传到gitee供大家参考 | gitee地址
- 运行测试脚本,测试键位反馈状态
$ ~/open_duck_mini_ws/Open_Duck_Mini_Runtime/mini_bdx_runtime/mini_bdx_runtime
$ python ps4_controller.py
pygame 2.6.0 (SDL 2.28.4, Python 3.11.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Loaded joystick with 6 axes.
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.733, 0.502)
(array([0.001, 0.125, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 1.0, 0.392)
(array([0.001, 0.2 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 1.0, 0.494)
(array([0.015, 0.2 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.737, 0.545)
(array([ 0.001, -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.627)
(array([ 0.001, -0.013, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.329, 0.545)
(array([-0.126, -0.129, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.416)
(array([-0.149, -0.125, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0.314)
(array([-0.15 , -0.002, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.867, 0)
(array([-0.026, 0.2 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.996, 0.29)
(array([0.048, 0.2 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 1.0, 0.545)
(array([0.137, 0.09 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.784, 1.0)
(array([ 0.134, -0.089, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 1.0)
(array([ 0.002, -0.2 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.102, 0.847)
(array([ 0.001, -0.2 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0, 0.502)
(array([-0.088, -0.198, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.2, 0)
(array([-0.15 , -0.045, 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.471, 0)
(array([-0.15, 0.1 , 1. , 0. , 0. , 0. , 0. ]), <mini_bdx_runtime.buttons.Buttons object at 0x7fb14e9690>, 0.863, 0.129)
- 按下不同的键位,终端会给出对应的反馈
- 若使用
XBOX ONE手柄,则可以启动xbox_controller.py进行测试
FAQ
问题1:xbox或ps4手柄连接不上树莓派,连上就断线,如此反复
- 问题原因可能为:手柄固件或系统中的蓝牙驱动不适配导致
解决方法
- 先尝试在win下升级手柄的固件再继续测试
- 其次更新系统中的蓝牙驱动再进行测试
演示视频
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


















