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

相关推荐
沫儿笙4 小时前
FANUC发那科焊接机器人厚板焊接节气
人工智能·机器人
Agilex松灵机器人8 小时前
持续更新|从零到玩转Moveit机械臂控制(一)
人工智能·python·机器人·学习方法
大唐荣华9 小时前
机器人落地“首台套”补贴,到底指什么?
人工智能·机器人
诗远Yolanda9 小时前
EI国际会议-通信技术、电子学与信号处理(CTESP 2026)
图像处理·人工智能·算法·计算机视觉·机器人·信息与通信·信号处理
不做无法实现的梦~11 小时前
PX4怎么使用使用PlotJuggler分析PX4日志
linux·嵌入式硬件·机器人·自动驾驶
码农三叔11 小时前
(3-3)机器人身体结构与人体仿生学:四肢结构设计原则
机器人
AiTEN_Robot11 小时前
机器人叉车的技术落地与效率挖掘:仓储自动化的效能提升方案
运维·机器人·自动化
zP1nG12 小时前
Gemini 全能 QQ 机器人部署手册 (V1.0 Release)
语言模型·机器人
weixin_4029399913 小时前
【机器人】机器人方向的顶会--自用
人工智能·机器学习·机器人
飞睿科技13 小时前
解析ESP-SparkBot开源大模型AI桌面机器人的ESP32-S3核心方案
人工智能·嵌入式硬件·物联网·机器人·esp32·乐鑫科技·ai交互