getRate() equivalent for Mag Srx Encoders

Hello everyone,
I have been working with the new trajectories and I was not able to find an equivalent getRate() function for the Mag Srx Encoders. I was thinking of having a custom function to return me the rate of the encoder but I wanted to check with the community to see if there is a function included in the Phoenix library that I missed.

1 Like

Are you running them through the Talons?
You can use talon.getSelectedSensorVelocity and convert it from encoder edges per decisecond to m/s.

Yes, I am running them through talons.

So the formula would be multiplying the value from talon.getSelectedSensorVelocity by:


Is this the correct way to do it or am I missing out on something here?

That looks good, but I would avoid hard coding numbers more than once in your code.

1 Like

Watch out there, doing 1/4096 will give you 0. You should do 1.0/4096.0 or just divide by 4096 at the end.

I usually end up putting a .0 at the end of all my numbers so the math Iā€™m doing is for doubles instead of integers.

1 Like

This was a major issue I faced a couple of months ago. Apparently, I forgot it again :sweat_smile: Thanks!

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