I’ve been working on a drivetrain simulator similar to the ILITE simulator, but with a few key differences. First, it’s capable of simulating drivetrain motion over time with a shifting drive using the two sets of characterization constants for each state. It’s also written in MATLAB, which I apologize for as that may reduce accessibility.
The math behind the paper is outlined here:
Mechanism_Simulation_with_Characterization_Constants (2).pdf (108.1 KB)
But to summarize, I use the three drivetrain characterization constants described in the FRC Drivetrain Characterization paper: intercept voltage (which I call kC), the volt per free speed (kV), and the volt per acceleration (kA). Every “tick” the simulation gets an input from the “driver,” which is generally +12V, and that input is then first filtered through a voltage ramp and then through an acceleration limit that prevents wheel slip. Once we get a ramped, non-slipping voltage to apply to the drivetrain motors, the simulator determines the acceleration given by that voltage and does a simple Euler step to find the new velocity and new displacement.
Starting in low gear, the robot drives forward with driver input +12V. Once the robot reaches the velocity where low gear acceleration is equal to high gear acceleration, it shifts to high gear and continues from there until the robot reaches the specified target distance. Once it arrives the simulation ends and the program creates some plots.
I also implemented a bang-bang control for stopping, where each tick the simulator asks “If I were to constantly negatively accelerate at the acceleration limit from here on out, would I arrive at my destination?” and if so it reverses the driver input to -12V until it arrives at its destination. I’m not exactly sure that I implemented this part correctly, particularly with how to treat the current draw and intercept voltage when reversing, but I think it should still be fairly accurate (except for maybe the total power draw).
Finally, now that I have a simulation to find the sprint distance times for a 2 speed drivetrain (or single speed if you set low gear = high gear), I created a script that iterates through every possible gearing between 2:1 and 20:1 on an interval of .1 for both low gear and high gear to figure out the optimal gearings for both DS and SS drivetrains for that specific sprint distance. The simulations were stopped if it took more than 5 seconds to reach the destination to save time.
Here are some results with DS on the top right and SS on the bottom right:
20 ft sprint with no stopping
20 ft sprint with stopping
40 ft sprint with no stopping
40 ft sprint with stopping
The plotted shifter spreads are the three available spreads for the VexPro 3 CIM Ballshifter.
Some quick observations on the results make me think that the implementation for the direction reversal is incorrect (note the motor voltage on the 2-speed drives spiking above 12V when reversing). Aside from that, it seems like overall the sprint-optimized single-speed drive is only about 7% slower than its corresponding sprint-optimized double-speed drive. The current draw for the DS drives is a little lower than for the SS drives when accelerating.
The left plots also suggest that as long as you pick a good high gear, the low gear does not matter quite as much for sprint distance times, so you might as well go ahead and pick a slower low-gear than what is time-optimal and protect yourself from brownouts for little to no cost. For example, all of these simulations gave that the sprint distance optimal gearing lies right around the 2.65x shifter spread mark, but if you kept the same high gear and moved over to 3.60x spread you would obviously have less brownout risk and higher pushing power while remaining in the dark-blue region and being slower by less than a tenth of a second.
The code is at https://github.com/rafchuk21/Mechanism-Simulators, please feel free to look it over and give feedback.