1
ewpratten.com/_drafts/2020-01-07-RobotSimGUI.md
2020-01-19 21:05:52 -05:00

2.6 KiB

layout title description date categories redirect_from
post Graphical drivebase simulation for FRC robots Showcasing part of the frc5024 codebase 2020-01-07 22:13:00 frc
/post/vcv4101s90/
/vcv4101s90/

The 2020 FRC season has kicked off, and the @frc5024 software team is already hard at work developing the software that will power this year's robot. Throughout the season, I'm hoping to showcase cool things we work on.

Today, I built a little tool to provide a graphical simulation of our robot's drivebase in 2D space. This post will outline how I did it.

Robot simulation

As our code is developed with WPILib, we make use of HALSIM to test out code before pushing to real hardware. This tool is great for checking for null pointer exceptions, and ensuring telemetry data is correctly pushed, but has some limitations. Mainly, we use a fair amount of un-supported hardware, and our own robotics library does not integrate with WPILib's "Sendable" system.

Faking HAL device support

To give HALSIM support to our custom devices, we use WPILib's SimDevice wrapper. @PeterJohnson explained to me how to do this in this thread.

Simulating sensors

For drivebase simulation, we need to simulate two devices. Our encoders, and our gyroscope. Neither of these devices have HALSIM support, so I added my own [1] [2].

Now that the device I/O has been simulated, we need to simulate sensor readings.

Encoders

Encoder readings can be estimated, assuming we know these properties:

  • Current motor speed (percent output)
  • Max motor speed (RPM)
  • Encoder Pulses per Revolution
  • Gearing ratio between simulated motor and sensor

Inside a quickly-updating loop, I used this pseudocode to determine the reading for an encoder:

double current_time = getSeconds();

double dt = current_time - last_time;
last_time = current_time;


double rpm = (getMotorSpeed() * max_rpm) / gearbox_ratio;
double revs = (rpm / 60.0) * dt; 

encoder_ticks += (revs * tpr);

Gyroscope