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

相关推荐
boss-dog1 天前
curobo——CUDA加速的机器人库
机器人·轨迹规划·避障·curobo
思通数科多模态大模型1 天前
门店 AI 清洁系统:AI 语义分割 + 机器人清洁
大数据·人工智能·算法·目标检测·计算机视觉·自然语言处理·机器人
GAOJ_K1 天前
滚柱导轨精度等级如何匹配应用场景?
人工智能·科技·机器人·自动化·制造
RPA机器人就选八爪鱼1 天前
RPA在银行IT运维领域的应用场景与价值分析
大数据·运维·数据库·人工智能·机器人·rpa
具身智能之心1 天前
美团 “全能突破”:RoboTron-Mani +RoboData实现通用机器人操作
机器人·具身智能
Software攻城狮1 天前
机器人伺服
机器人
信鸽爱好者1 天前
Windows +VM虚拟机安装github服务器
服务器·windows·ubuntu·机器人·github
具身智能之心1 天前
从长时程推理到精准操纵:LoLA 破解机器人多步任务执行难题
机器人·具身智能
机器人行业研究员1 天前
破局与重构:2025年中国六维力传感器产业的价值升维之路
人工智能·机器人·人机交互·六维力传感器·关节力传感器
点云SLAM1 天前
点云配准算法之- GICP算法点云配准概率模型推导和最大似然求解(MLE)
算法·机器人·slam·点云配准·最大似然估计·点云数据处理·gicp算法