Romi Gyro SimDevice

I am starting with the RomiReference project example shipped with WPILIb 2023. It has a file called RomiGyro.java that implements the RomiGyro class. I’m doing a code review of this class and cannot determine how the class gets the values from the gyro on the Romi.

I was able to refactor the TurnDegrees command to use the RomiGyro class, so this class is very clearly getting live data from the gyro on the Romi. But I cannot see how it is actually doing so. I would have expected that somewhere it would reference an IO channel or something.

It works, I think, but I would still like to understand how.

RomiGyro basically wraps a SimDevice instance that is used for HAL simulation (the Romi simulation extension uses this framework to facilitate communication with the actual Romi robot). SimDevices can also have data fields that can get updated from whichever simulation endpoint is being used (in this case, the Romi). allwpilib/romiVendordep/src/main/java/edu/wpi/first/wpilibj/romi/RomiGyro.java at main · wpilibsuite/allwpilib · GitHub

On the Romi side, the romi-web-service is running and is listening out for SimDevice messages via a RomiGyro class: wpilib-ws-robot-romi/src/robot/romi-robot.ts at main · wpilibsuite/wpilib-ws-robot-romi · GitHub

This gyro object wraps around the LSM6 I2C interface and is used to provide gyro data from the hardware IMU, over websockets, to the RomiGyro SimDevice on the WPILib side

1 Like

Thank you so much. This makes much more sense. I found this link:

Which says:

WPILib Hardware Support

  • Onboard LEDs and pushbuttons exposed as DIO channels 0-3
  • 2 motors (left/right) exposed as PWM channels 0/1
  • 2 encoders (left/right) exposed as Encoders with channels 4/5 and 6/7
  • 3-axis gyro exposed as a SimDevice
  • 3-axis accelerometer exposed as a BuiltInAccelerometer
  • Battery voltage reporting

I see now that the SimDevice class is an encapsulation of the Romi Web Service.

A few follow up questions:

  1. Why is the gyro a SimDevice instead as opposed to how they simulated the the motors through simulated PWI channels?
    • I would seem to make more sense to make the code look like it would if it were actually running on the robot.
    • That is what they are doing with the motors and encoder, correct?
  2. Is there documentation anywhere on the Romi Web Service?
    • It might be interesting to see what else is supported.

The Gyro and Accelerometer are exposed as SimDevices to provide a richer set of data without using up too many I/O channels. This also fits in a little closer with how the newer IMUs that teams are using (e.g NavX, Pigeon) behave, where they communicate over a CAN bus, and can provide more information than might be possible using purely analog/digital I/O.

Unfortunately, the Romi Web Service isn’t as well documented as I’d like it to be, since it was meant to be a “install-and-forget-about-it” kind of system. If you dig around in that repo, you’ll see how most of the logic is implemented. The actual hardware bits are in the firmware folder, and this is the actual firmware running on the 32u4 Romi control board. The web service communicates with this over an I2C link.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.