Using spacefox in ROS
suitendaal opened this issue · 5 comments
Hi,
I came across this spacemouse project where, unlike other DIY spacemouse projects where they just move your mouse with an Arduino, you can actually register the device as spacemouse. Now I want to use this spacemouse in ROS using the spacenav_node.
I have uploaded a simplified version of your code to an Arduino Micro, where I just send constant values over the joystick. I registered the device to /etc/spnavrc
and launched the spacenav_node
in ROS, but I don't get any spacemouse values there. I have a couple of questions:
- Where does the
device-id
of1b4f:9206
come from? - How do I verify that the Arduino Micro is actually running as spacemouse device in spacenavd?
- Do you know how to get these values in the ROS
spacenav_node
?
Kind regards,
Sven
The device ID comes form the Arduino and can be seen in lsusb
.
I'm not familiar with ROS spacenav, but you can run spnavcfg
to see if the spacenavd
daemon is running and the device is registered.
Thank you for your help and reponse! I have now installed spacenavd
, libspnav
and spnavcfg
and I can indeed see that the device is registered.
Am I supposed to see the joystick's values in spnavcfg
? Because TX
, TY
, TZ
, RX
, RY
and RZ
are all 0. Also, I don't see my button values at the Buttons tab. A snipped of the code on the Arduino looks like this:
void loop() {
// Simulate buttons
joystick.setButton(0, true);
joystick.setButton(1, false);
joystick.setButton(2, true);
joystick.setButton(3, false);
// Simulate axes
joystick.setXAxis(200);
joystick.setYAxis(300);
joystick.setZAxis(-400);
joystick.setRxAxis(0);
joystick.setRyAxis(10);
joystick.setRzAxis(-20);
// Send state
joystick.sendState();
}
Yes. Does spacenavd have access to the USB device? The brute force method would be running it as root.
Hi, I think I found the issue. Spacenav only reacts to events. With my hardcoded constant values there were no events. Now my loop looks like this:
void loop() {
int x = 512.0 * sin(millis() / 1000.0);
digitalWrite(LED_BUILTIN, x > 0.0);
joystick.setButton(0, x > 400);
joystick.setButton(1, x <= 400);
joystick.setButton(2, x > 0);
joystick.setButton(3, x <= 0);
joystick.setXAxis(x);
joystick.setYAxis(400);
joystick.setZAxis(-300);
joystick.setRxAxis(0);
joystick.setRyAxis(10);
joystick.setRzAxis(-20);
joystick.sendState();
}
And indeed I see the TX
and the buttons change, but not TY
, TZ
, RX
, RY
and RZ
, because they remain constant in the Arduino code.
What helped me was running evtest /dev/input/event4
(with eventX the HID channel on which the Arduino is sending the data, in my case 4). There you can read the current values (which are my constant hardcoded values) and if spacenavd
is not running, you also receive all the events here.