pepijndevos / spacefox

A 6dof diy hid
Apache License 2.0
172 stars 10 forks source link

Using spacefox in ROS #6

Closed suitendaal closed 11 months ago

suitendaal commented 11 months ago

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:

Kind regards, Sven

pepijndevos commented 11 months ago

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.

suitendaal commented 11 months ago

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();
}
pepijndevos commented 11 months ago

Yes. Does spacenavd have access to the USB device? The brute force method would be running it as root.

suitendaal commented 11 months ago

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.

suitendaal commented 11 months ago

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.