Hi all, just wanted to open a thread for general discussion on the new CTRE simulation support.
I want to be able to teach my students how to implement the new Talon’s simulation support easily.
I will put here my understanding of it here and hopefully, we (I) could understand how to integrate it into the java/c++ command base framework while supporting real code execution when the time comes.
New release info:
The example that I will analyze here (motion magic)
My understanding - points:
Creating a SimProfile class, all motor’s profiles will extend this class which includes run
method (should be abstract prob) that will update the SimCollection about the motor’s current state based on specific physic’s profile implementation Example
Creating a class that represents the specific motor physic’s profile which extends the SimProfile class for each motor (unless they are in follower more) in each system in our robot (different physics for each system so different profile) Example
PhysicsSim class, manager class, creates and holds all of our motors profiles, will be updated (run) in Robot.javasimulationPeriodic method. Example
Initializing PhysicsSim: pushing talons so PhysicsSim will create and hold the appropriate profile in simulationInit at Robot.java Exmaple
Updating PhysicsSim: in simulationPeriodic at Robot.java update (run) PhysicsSim to update all active profiles Example
Physics dive in: (I will add a dive in on how to tweak the physics params if this thread will be active) TBC
So the provided example shows a way to update the TalonSRXSimCollection , which is all we need to run a close loop control in simulation mode (?)
That is correct. In order for closed loop control, soft limits, current limiting, etc. to work in simulation, users need to call into the SimCollection during simulationPeriodic() and update the appropriate values. The provided example simply demonstrates how users can do that.
Users that are simulating a robot remotely using the WebSocket interface, such as in Unity, should not call into the SimCollection, as values sent through the WebSocket interface are handled in our WPI_* classes.
This would treat your FX like an SRX during simulation, and most of the methods are common.
You just wouldn’t be able to use anything that’s device specific, like stator current limiting or anything API calls that directly reference the integrated sensor (though selected sensor would be fine) - except within the IsReal() check. Also make sure you null check the SimCollection object just in case.
I went this route in my SimulationPeriodic I do this:
for my encoder reading I tried these:
when I test this… the GetSelectedSensorPosition() updates every 20ms, and for GetQuadraturePosition() it only updates every 100-200ms. I have not yet tested this on a real motor, but want to know how to set in simulation and get updates every 10ms if possible, without having to resort to simulation read variables. Thanks.
This matches what I expect - the update rates for signals match the update rates from CAN data on real devices. You can use the SetStatusFramePeriod function as normal if you want to change this update rate.
If the integrated sensor is the selected sensor, then changing the update rate of Status 2 will change the update rate of the value returned by the getSelectedSensorPosition/Velocity functions (which in this case will the the values for integrated sensor).
Changing the update rate of Status 2 will not change the update rate of any other signal groups, however, so the update rate of values returned by SensorCollection’s specific getter for integrated sensor will not change.
Keep in mind these are two completely separate functions - the Selected Sensor value is what you should use most of the time; that’s the value being used by your closed loop and reflects any inverts or phasing. The sensor collection methods exist to verify the raw value of the sensor and as a method to get raw sensor data when a given sensor is not the selected sensor.
Are you asking about additional device support or something else sim related?
We have an internal version of sim support for Talon FX, CANcoder, and Pigeon. These will likely be released with this year’s FRC beta testing but should for sure be available by the start of the season.
Yes, I was wondering specifically about Talon FX support for simulation. We were hoping to practice simulating bots using the Talon FX this Fall, so I’ve been searching for a workaround for the time being.