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

相关推荐
ARM+FPGA+AI工业主板定制专家17 小时前
基于JETSON/RK3588机器人高动态双目视觉系统方案
人工智能·机器学习·fpga开发·机器人·自动驾驶
哈泽尔都18 小时前
运动控制教学——5分钟学会PRM算法!
人工智能·单片机·算法·数学建模·贪心算法·机器人·无人机
孤独野指针*P1 天前
MoveIt 机械臂碰撞检测:从环境搭建到障碍物规避
linux·3d·机器人
搬砖的小码农_Sky1 天前
人形机器人:Tesla Optimus的AI集成细节
人工智能·ai·机器人
xwz小王子2 天前
Science Robotics 研究综述:基于学习方法的机器人操作动力学模型
机器人·学习方法
悠哉悠哉愿意2 天前
【智能系统项目开发与学习记录】bringup功能包详解
学习·机器人·ros2
siliconstorm.ai2 天前
阿里下场造“机器人”:从通义千问到具身智能,中国AI正走向“实体化”阶段
人工智能·自然语言处理·chatgpt·机器人·云计算
@LetsTGBot搜索引擎机器人2 天前
用 Python 打造一个 Telegram 二手交易商城机器人
开发语言·python·搜索引擎·机器人·.net·facebook·twitter
扫地的小何尚2 天前
Isaac Lab 2.3深度解析:全身控制与增强遥操作如何重塑机器人学习
arm开发·人工智能·学习·自然语言处理·机器人·gpu·nvidia
铮铭3 天前
【论文阅读】具身竞技场:面向具身智能的全面、统一、演进式评估平台
论文阅读·人工智能·机器人·世界模型