How would you substitute a NEO’s name.getEncoder().getVelocity() for a Mag SRX encoder mounted to the data port of a Talon? For context this is for the Kinematic and Odometer classes. We were thinking about getRate() or getSelectedSensorVelocity() but we are just confused on what to do about them.
You don’t need to PID loop to call this method, AFAIK, it’s just that you can configure inside the Talon SRX more than one feedback loop.
However, if you use only one feedback sensor, you can use this version of the aforementioned method which uses the default slot ID.
Call configSelectedFeedbackSensor(TalonSRXFeedbackDevice. CTRE_MagEncoder_Relative) in the constructor for using the mag encoder in relative mode
Call getSelectedSensorVelocity() whenever you need to measure the velocity.
Keep in mind that velocity is in native units per 100ms. The native unit is 4096 per rotation for the mag encoder. You might want to convert units before using it.
If you’re doing this for odometry/kinematics/WPILib trajectories, your speeds will need to return in rotations per second. talon.getSelectedSensorVelocity() returns encoder units per 100 ms. Assuming you have a CTRE mag encoder attached to your talons (CTRE Mag encoders return 4096 units per rotation), your getSpeeds() function will look like this:
Note that in your code snippet 10 / 4096 won’t give you the result you expect, since it’s integer division, the result will be 0. At least one of the numbers needs to be floating point (e.g. 10.0 / 4096).