ubuntu 配置 spacemouse以及通过python/robosuite使用spacemouse

一 前言

3dconnexion 早在2014年就不更新对linux系统的驱动,因此安装驱动需要参考另一个网站:https://spacenav.sourceforge.net/

二 安装步骤

1 安装 spacenavd

先安装依赖库

shell 复制代码
sudo apt install libxext-dev libxrender-dev libxmu-dev libxmuu-dev
sudo apt-get install libxtst*
sudo apt-get install libx11*
sudo apt-get install libxi-dev

在自定义的安装目录下,执行以下命令下载源码并安装

shell 复制代码
git clone https://github.com/FreeSpacenav/spacenavd.git
cd spacenavd
./configure
make
sudo make install

执行以下命令将该驱动设为开机启动

shell 复制代码
sudo ./setup_init
sudo /etc/init.d/spacenavd start

过程中可能会输出以下像报错的信息,是正常输出,不用理会

shell 复制代码
cat: /etc/inittab: 没有那个文件或目录
default runlevel detection failed.

2 安装 libspnav

执行以下命令下载源码并安装

shell 复制代码
git clone https://github.com/FreeSpacenav/libspnav.git
cd libspnav
./configure
make
sudo make install

3 验证驱动安装是否正确

将spacemouse通过附带的USB线连接到电脑USB。libspnav程序包中给了几个测试用例,执行以下命令进行测试

shell 复制代码
cd libspnav/examples/simple
make
./simple_af_unix

此时移动spacemouse的摇杆,应该能看到以下输出:

shell 复制代码
spacenav AF_UNIX protocol version: 1
Device: 3Dconnexion SpaceMouse Wireless
Path: /dev/input/event6
Buttons: 2
Axes: 6

got motion event: t(0, 0, 0) r(-15, 0, 0)
got motion event: t(0, -5, 0) r(-32, 0, 0)
got motion event: t(-2, -21, 0) r(-58, 0, 0)
got motion event: t(-6, -17, 0) r(-60, 0, 0)
got motion event: t(-3, 0, 0) r(-60, 0, 0)
got motion event: t(0, 0, 0) r(-8, 0, 0)
got motion event: t(0, 0, 0) r(-16, 0, 0)
got motion event: t(0, 0, 0) r(0, 0, 0)
got motion event: t(0, 0, 9) r(-19, 0, 0)
got motion event: t(-45, 0, 56) r(-78, 0, -38)
got motion event: t(-92, 0, 78) r(-99, 0, -78)
got motion event: t(-122, 0, 80) r(-105, 0, -104)
got motion event: t(-123, 0, 75) r(-103, 0, -105)
got motion event: t(-128, 0, 86) r(-123, -10, -115)
got motion event: t(-143, 0, 105) r(-142, -31, -131)

表明驱动安装完成。

三 在python/robosuite中使用spacemouse

1 读取spacemouse设备id

连接设备后,在终端输入lsusb查看哪一行后面有spacemouse字样的就是连接的设备;没有的话,连接设备前后分别运行lsusb看多了哪一个设备信息。我的spacemouse信息如下:

shell 复制代码
Bus 001 Device 010: ID 256f:c62e

其中冒号前面的256fVendor_id,后面的c62eProduct_id,后面会用到。

2 配置hid

python的hid库(pip install hidapi )可以用来读取usb设备信号,但设备的默认权限仅允许root用户访问,一种方法是执行python程序时前面加sudo,但sudo python默认执行的是ubuntu原装的py2。如果想用任意的python的hid库读取信号,需要提高spacemouse设备的权限,步骤如下:

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

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

shell 复制代码
SUBSYSTEM=="usb", ATTRS{idVendor}=="256f",  ATTR{idProduct}=="c62e", MODE="0666"

将其中的256fc62e替换为自己使用的spacemouse的Vendor_idProduct_id

3 robosuite使用spacemouse

下载robosuite

shell 复制代码
git clone https://github.com/ARISE-Initiative/robosuite.git

修改robosuite/demos/demo_device_control.py中的下面两行,主要是修改设备为spacemouse,以及修改vendor_idproduct_id

shell 复制代码
parser.add_argument("--device", type=str, default="spacemouse", choices=['spacemouse', 'keyboard'])
device = SpaceMouse(vendor_id=0x256f,product_id=0xc62e, pos_sensitivity=args.pos_sensitivity, rot_sensitivity=args.rot_sensitivity)

之后运行demo_device_control.py即可使用spacemouse控制仿真环境中的机械臂。

完~

相关推荐
wzyannn17 小时前
Ubuntu24.04下ROS2和MoveIt2控制六轴机械臂(持续更新)
ros·机械臂·ros2
WWZZ20252 天前
Isaac Sim入门——基础用法
机器人·大模型·机械臂·ros2·具身智能·isaac sim
具身智能之心11 天前
上海交大发布U-Arm:突破成本壁垒,实现超低成本通用机械臂遥操作系统
arm开发·机械臂·具身智能
远创智控研发部13 天前
EtherNet/IP转CC-Link IE FB:协议转换网关在汽车焊装线的7×24稳跑样本
机械臂·数据采集·三菱plc·协议转换网关·网关模块·总线协议
Better Bench16 天前
Ubuntu 系统安装 Gym-Fetch-v2以及通过游戏Xbox手柄控制机械臂采集演示数据
ubuntu·游戏·机械臂·fetch·gym·xbox
TTGGGFF1 个月前
具身智能:零基础入门睿尔曼机械臂(六)——手眼标定代码库详解,从原理到实践
数码相机·机械臂·具身智能
TTGGGFF1 个月前
具身智能:零基础入门睿尔曼机械臂(五)—— 手眼标定核心原理与数学求解
机械臂·手眼标定·具身智能
TTGGGFF1 个月前
具身智能:零基础入门睿尔曼机械臂(四)—— 夹爪无响应?官方例程踩坑与排错实战
机械臂·具身智能·睿尔曼
boss-dog2 个月前
UR robot ROS2 Driver 快速入门使用
机械臂·ros2·urdf·moveit2·ur
WWZZ20252 个月前
ROS2——基础4(通信接口、参数说明、分布式通信)
机械臂·ros2·具身智能·通信接口·参数创建·分布式通信