Setting Up and Using a 3Dconnexion SpaceMouse on Ubuntu with Python and Robosuite
The official 3Dconnexion Linux drivers have not been updated since 2014. Instead, use the open-source spacenav project available at https://spacenav.sourceforge.net/.
Install spacenavd
First, install required system dependencies:
sudo apt install libxext-dev libxrender-dev libxmu-dev libxmuu-dev libxtst-dev libx11-dev libxi-dev
Then build and install spacenavd from source:
git clone https://github.com/FreeSpacenav/spacenavd.git
cd spacenavd
./configure
make
sudo make install
Enable the service to start on boot:
sudo ./setup_init
sudo /etc/init.d/spacenavd start
Ignore messages like cat: /etc/inittab: No such file or directory—they are harlmess on modern systems.
Install libspnav
Next, install the client library:
git clone https://github.com/FreeSpacenav/libspnav.git
cd libspnav
./configure
make
sudo make install
Verify Installation
Connect your SpaceMouse via USB. Test the setup using the example program:
cd libspnav/examples/simple
make
./simple_af_unix
Moving the device’s cap should produce real-time output showing translation (t) and rotation (r) values across six axes, confirming successful driver integration.
Use SpaceMouse in Python and Robosuite
Identify Device IDs
Run lsusb to locate your device. Example output:
Bus 001 Device 010: ID 256f:c62e
Here, 256f is the vendor ID and c62e is the product ID.
Configure USB Permissions
By default, only root can access HID devices. To allow user-level access, create a udev rule:
sudo nano /etc/udev/rules.d/99-spacemouse.rules
Add the following line (replace IDs with your own):
SUBSYSTEM=="usb", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62e", MODE="0666"
Reload udev rules:
sudo udevadm control --reload-rules && sudo udevadm trigger
Unplug and reconnect the device for changes to take effect.
Integrate with Robosuite
Clone the repository:
git clone https://github.com/ARISE-Initiative/robosuite.git
Editt robosuite/demos/demo_device_control.py. Set the default device to spacemouse and instantiate it with your hardware IDs:
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)
Now run the demo to control a simulated robot arm using the SpaceMouse.