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

3 篇文章 0 订阅
2 篇文章 0 订阅

一 前言

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

二 安装步骤

1 安装 spacenavd

先安装依赖库

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

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

git clone https://github.com/FreeSpacenav/spacenavd.git
cd spacenavd
./configure
make
sudo make install

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

sudo ./setup_init
sudo /etc/init.d/spacenavd start

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

cat: /etc/inittab: 没有那个文件或目录
default runlevel detection failed.

2 安装 libspnav

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

git clone https://github.com/FreeSpacenav/libspnav.git
cd libspnav
./configure
make
sudo make install

3 验证驱动安装是否正确

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

cd libspnav/examples/simple
make
./simple_af_unix

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

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信息如下:

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设备的权限,步骤如下:

cd /etc/udev/rules.d
sudo touch 99-spacemouse.rules
sudo gedit 99-spacemouse.rules

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

SUBSYSTEM=="usb", ATTRS{idVendor}=="256f",  ATTR{idProduct}=="c62e", MODE="0666"

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

3 robosuite使用spacemouse

下载robosuite

git clone https://github.com/ARISE-Initiative/robosuite.git

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

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控制仿真环境中的机械臂。

完~

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值