WPILibPi Romi Experience So Far (drivetrain, encoders, gyro)

Loving the Romi so far! Shout out to all of those involved in making it happen and continuing to improve the software. With our robot stuck in our workshop and the school closed I have found it essential to being able to test code. To be honest our team has always had issues not being able to test code outside of school hours, meaning we waste our precious build time in school debugging trivial code problems. I’m confident we’ll be using the Romi for years.

I was able to put together a few examples on my own after reading through some of the examples our awesome WPILib project collaborators have put together https://github.com/wpilibsuite/allwpilib/tree/master/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference:

  1. Some basic commands using drivetrain with/without encoders
  2. Using the gyro to turn a specific number of degrees
  3. Adding PID on top of it to turn an exact angle and have experimented with driving straight with gyro angle correction using PID.

The examples I put together and tested are on my Github repo for anyone that is interested: GitHub - michaellee1019/FRC7272-Romi-Examples. I’m planning on adding some more commits with code comments and documentation when time permits.


Thank you for this. It is incredibly helpful as it highlights many of the foundational skills we are using the Romi (and the other at-home robots) to learn. I have a few quick questions if you do not mind indulging us.

  1. In the DriveTrain subsystem, is the constant surfaceFactor for wheel scrub? How did you calculate it?
  2. I am impressed with the drift constants in the Gyro class. How did you calculate those?
  3. I am also curious if you do not mind sharing a bit about the process your team uses to tune PID on the Romi.

If all of these will be in the docs, please disregard these questions. Regardless, I feel the snapshot in this repo is vital to a team in a position like ours in understanding how to move from being proficient with basic and consistent robot control to becoming proficient with more complex algorithms. Thank you for sharing.


No problem! Our team in past years has written very basic code. This is the first code our team has written using encoders, gyro, and PID. Im sure there are some better way of doing it and I’m going to continue researching

  1. That is a good point about SURFACE_FACTOR, forgot about that. I was noticing that when relying on the encoder calculations provided by the romi drivetrain in the java template, the distance and turning degrees was overshooting. I tested it by driving 90deg (encoder dist calc, no gyro) and a set number of inches, measuring the incorrectness, and using this as an offset. I have been driving on both hardwood floors and carpet so not sure if its actually a surface factor or more of an offset (reason for it I still need to understand).
  2. Yeah the drift issue was annoying me a lot. When trying todo long running PID with the gyro I felt like I was getting a lot of drift and was interfering with reaching the setpoint. Take a look at FRC7272-Romi-Examples/Robot.java at main · michaellee1019/FRC7272-Romi-Examples · GitHub. I start printing an average per second drift based on the program start time. This assumes you have just started your program with the romi leveled and stationary. Whatever is printed out when robot is disabled, after running for a while to average out the values, are the constants I put into the file.
  3. This is the first I’ve used PID ever to be honest. I have seen a few presentations on it. I experimented with a ton of different values. It seems like a lot of FRC teams don’t bother to set the I & D values and only do if the robot never reaches target. Seems like for the romi you need a really high P (.7-1 which is almost full power), and have to manually correct the range of the pid output since the romi drivetrain doesn’t move at speed values lower than .3 (sometimes .25).

At this point I’m still testing things out but not opposed to helping write/improve some WPI lib docs and exampltes :slight_smile: