Simulation example using Falcon internal PID control?

I am working on trying to implement simulation for our past year’s robot. Right now, I am trying to get a simple arm working. I can get it working in terms of visualising and some simple control, but not using the “same” code as we used on the robot.

For the arm, we used a TrapezoidalSubsytem. It is driven by Falcon500 motors, and we used the PID control in Position mode, within the Falcon/TalonFX to actually handle controlling the arm. When I try to do that in the simulation, the motor does not get any input. That is, the “internal” control is not doing anything.

Does anyone have a working example of a simulation which used internal controller PID control? Falcon and NEO would be appreciated (we NEOs elsewhere). Can it be done, with out completely re-writing (faking) the internal PID controller?

Have you looked at this?

3 Likes

Thanks. I had seen the drivetrain simulation, but not this one. However, unless I am missing something, that so called “PhysicsSim” has nothing to do with what is in the “real” robot code. The real robot control will do drive to a position under PID within the Falcon, but (unless I am misreading it), the simulation just ramps the motors up to some really fast value in equal steps.

I was hoping there was something already written, but I guess we will have to create a simulation with pure WPILib classes.

1 Like

Is this closer to what you’re looking for?

Thank you!!

It seems to actually do the PID in the simulation. My error was I was using “motor.get()” to get the speed. Switching to “motor.getMotorOutputVoltage()” works.

I think a better example of using our simulation APIs with WPILib is our Phoenix 6 Motion Magic example. We also cover a lot more information about integrating our API with physics simulators like WPILib’s sim classes in our Phoenix 6 docs. The APIs are slightly different compared to Phoenix 5 (namely with the new Orientation field), but overall the same principles apply.

In the old Phoenix 5 example linked here previously, we just wrote a very simple function that used the motor output voltage to ramp towards a proportion of the max possible velocity. It doesn’t just ramp to a really fast value because eventually PID will output a lower voltage, causing it to ramp back down to a slower velocity.

In the new Phoenix 6 example, we replaced all that math with more realistic physics simulation provided by WPILib’s DCMotorSim, just as team 4201’s code linked here does. But the principle is still the same: pass in the motor’s output voltage, and get back the new position and velocity to apply to the motor.

1 Like

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