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,应该会有一个能正常打开设备。

相关推荐
REDcker2 小时前
RTCP 刀尖点跟随技术详解
c++·机器人·操作系统·嵌入式·c·数控·机床
飞睿科技4 小时前
UWB技术在机器人领域的创新应用与前景
网络·人工智能·机器人·定位技术·uwb技术
无忧智库5 小时前
深度解析:某应急救援中心特种人形机器人救援分队与装备保障建设方案(万字长文)
机器人
Angel Q.8 小时前
基于GS(Gaussian Splatting)的机器人Sim2Real2Sim仿真平台有哪些
机器人·仿真·3dgs·高斯泼溅·sim2real2sim
才兄说8 小时前
机器人租赁中的现场确认痛点
人工智能·机器人
瑞璐塑业peek注塑8 小时前
【精密传动】机器人反向行星滚珠丝杠PEEK注塑降本方案成量产关键
机器人
haing20199 小时前
3/1/3形七轴协作机器人解析解法及matlab实现
机器人
AIoT科技物语20 小时前
100%开源,国产Qmini双足机器人,从3D打印资源到软件系统、驱动算法全公开
机器人
气概20 小时前
法奥机器人学习使用
学习·junit·机器人
li24681357920 小时前
RoSeN 2026(EI)|第二届机器人与传感器网络国际会议,天津启幕!
机器人