ubuntu20 使用 pyspacemouse获取 spacemouse wireless 输入

1. 设置设备权限

(1) 默认情况下,普通用户可能没有权限访问 HID 设备,可以通过设置 udev 规则解决:

bash 复制代码
cd /etc/udev/rules.d
sudo touch 99-spacemouse.rules
sudo gedit 99-spacemouse.rules

在新建的99-spacemouse.rules中添加以下内容

bash 复制代码
SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62b", MODE="0666"

idVendoridProduct 的值可以通过运行以下命令找到:

bash 复制代码
lsusb

找到类似 Bus 001 Device 013: ID 256f:c652 3Dconnexion 3Dconnexion Universal Receiver 的设备,这里的 256f 是 Vendor ID,c652 是 Product ID。

(2) 重新加载 udev 规则:

bash 复制代码
sudo udevadm control --reload-rules
sudo udevadm trigger

(3) 断开并重新连接 SpaceMouse Wireless

确保当前用户属于 input 组:

bash 复制代码
sudo usermod -a -G input $USER

(4) 注销并重新登录ubuntu

2. 安装pyspacemouse

ubuntu20下按已下命令安装

bash 复制代码
pip install pyspacemouse
sudo apt-get install libhidapi-dev
pip install git+https://github.com/bglopez/python-easyhid.git

3. 测试pyspacemouse

运行以下程序:

python 复制代码
import pyspacemouse
import time

success = pyspacemouse.open(DeviceNumber=0)
if success:
    while 1:
        state = pyspacemouse.read()
        print(state.x, state.y, state.z)
        time.sleep(0.01)

终端会输出以下信息

bash 复制代码
3Dconnexion Universal Receiver found
3Dconnexion Universal Receiver found
3Dconnexion Universal Receiver found
3Dconnexion Universal Receiver found
3Dconnexion Universal Receiver found
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0.0 -0.005714285714285714 -0.08
0.0 0.0 -0.005714285714285714
0.011428571428571429 0.0 -0.03428571428571429
0.08857142857142856 0.0 0.0
0.04285714285714286 0.0 -0.002857142857142857
0.0 0.0 -0.05142857142857143
0.0 0.0 -0.05142857142857143
0.0 0.0 0.0

移动spacemouse的摇杆,终端会输出对应的xyz值。

如果终端提示easyhid.easyhid.HIDException: Failed to open device,尝试DeviceNumber0-4,应该会有一个能正常打开设备。

相关推荐
Bode_200213 小时前
新能源电池包的柔性智能装配质量控制方法
人工智能·机器人·汽车·制造
jinxindeep14 小时前
EgoLive:面向机器人操作学习的超大规模第一视角数据集
人工智能·学习·机器人
nshkfhwr15 小时前
可能的前景:有痛淘汰和无痛淘汰,都是淘汰
机器人·有痛淘汰·无痛淘汰·虚幻拟构的人
Deepoch15 小时前
Deepoc VLA开发板:实现采摘机器人动态生物适应与精准作业
大数据·人工智能·机器人·采摘机器人·deepoc
源代码杀手15 小时前
基于ROS2+Gazebo+RIVE的40项计算机视觉前沿机器人项目(含视觉算法原理与源码获取方式)
算法·计算机视觉·机器人
小O的算法实验室15 小时前
2024年IEEE/CAA JAS,复杂环境下避障 Voronoi 单元的多机器人协同围捕
机器人
Linlingu15 小时前
OpenClaw对接飞书机器人完整配置教程(长连接模式)
windows·机器人·飞书·办公自动化·数字员工·小龙虾
kyle~16 小时前
ROS2---零拷贝
linux·c++·机器人·ros2
wx_jiuyun67817 小时前
渔夫Telegram群机器人系统详解
linux·服务器·机器人
沫儿笙1 天前
发那科机器人氩弧焊节气装置
人工智能·机器人