Simulating a Robot While Testing

As of right now, our team is only testing code by deploying to an actual hardware robot. However, we are looking into other forms of testing, specifically using software simulations. Where should we start with using software-based test harnesses? What software test harnesses do you all use? How did you set them up? Thanks.

GradleRIO allows you to easily test your code by either running ./gradlew test or by running WPILib: Test Robot Code from VS Code. I’m pretty sure there’s a way to connect a driver station to that, but I haven’t done it and I don’t think the documentation on how to do it is great yet.

While testing code like this, you can check RobotBase.isReal() or RobotBase.isSimulation() to see if you are testing this on a robotRIO or your own computer.

If you want to test a smaller piece of code, unit tests are great. The thing with unit tests is that you have to try not to use certain parts of WPILib like SmartDashboard or something else that needs to be initialized.

This year, the logic for the positioning of our swerve modules was completely separate from the code that actually told the talons what to do. That made it pretty easy to unit test.

I’m not aware of a way to fully simulate your robot without abstracting most of your code to not use WPILib or libraries such as CTRE. Theoretically, if you abstracted everything you could be able to test your drive code with a 2D simulation. I plan on doing something like this later this summer.

RobotPy has pyfrc, Java has snobot.

2 Likes

I found this video from 971 really helpful: https://www.youtube.com/watch?v=uGtT8ojgSzg&t=3276s.

1 Like

Interesting! I’ll definitely look into unit testing and the GradleRIO simulation. Thanks for your response!

Oh wow. I’ll definitely look into snobot! Thanks for you reply as well as your work on RobotPy!!

Another cool thing to try is Autodesk Synthesis. It lets you actually simulate your code in a virtual field using a CAD model of your robot. I will admit that I haven’t tried the code simulation feature yet, but it looks pretty cool. And, it’s free and open-source. And who doesn’t love open-source stuff?

Even if you don’t like the code emulation, it’s still super fun :grin:

1 Like

The Synthesis emulator is “work-in-progress” and has yet to deliver on some promises. But, another cohort of interns will continue working on improving it this coming Summer and it will be interesting to see what they release come August.
Some of the flaws I have noted to the development team:

  1. cannot be deployed via GradleRIO the the “emulated” robot;
  2. Has very limited sensor simulations, e.g. although the simulator allows one to install one simulated camera on the robot, the video signal cannot be routed to a signal processing program;
  3. no ability to integrate off-board processors with the emulated RoboRio;
  4. the Synthesis Driver Station is a rather poor simulation of the actual Driver Station. I don’t understand why the actual Driver Station cannot interface to the emulated RoboRio;
  5. the Talon SRX capabilities are not covered by the emulator, yet, the simulator allows one’s code to connect to the controllers CAN or PWM ports.

The Autodesk Synthesis team is working dilligently every year to improve the emulator… so, it is definitely a capability we need to keep an eye out for.

1 Like

That’s true, it’s not a full robot simulator. It’s a very different way to test code, so it definitely has a lot of caveats. I can see it being used quite a bit in the near future, though.

It works pretty well for driver practice on a decent machine, too.

1 Like

Indeed. we typically import the first few iterations of our robot designs into Synthesis and have the drivers get a first hack at the robot handling and get comfy with driving around on the simulated field. We also perform initial assessments of the positioning, field-of-view and possible mechanism obstruction of the drive cameras.

Figured my post on this thread was relevant;

+1 for SnobotSim

I’ve done this, most certainly not the most efficient way, but it really was worth it.

Hey everyone. The Synthesis Summer Internship just got underway at the Portland Autodesk offices last week!

One of the main features we’re working hard on this year is improving our code emulator - adding more modules you can test and bringing Java support.

If you have any other suggestions, please do reach out! We’re always looking for feedback.

If you are so inclined, you could also join our beta program and help steer our direction.

Stay tuned, and get in touch with me at andrei.stoica@autodesk.com

Andrei <3

3 Likes