my team is using CTRE mag encoders on our drive train for PID control. We’d like to input a specific distance and have the PID loop make the robot drive that distance. I’ve seen a lot of talk about distance per pulse and I was wondering how that is calculated for a drive train. I’ve seen that it has something to do with encoder ticks per revolution and the circumference of the wheel although I’m not sure how to input the wheel diameter in inches when the rest of the system works in encoder ticks? Has anyone had any luck with this in the past?
First things first are your mag encoders connected directly to the roborio, or to the srx ports?
Encoder “tick” notation is not always agreed upon, so sometimes it can be a bit confusing. The CTRE mag encoder has 4096 CPR in this case.
You are trying to find the relationship between your mechanism measurement(wheel meters traveled) and your encoder(measured with 4096 “ticks” per rotation). The “pulse” in setDistancePerPulse
refers to one of these “ticks”.
Basically:
(1 / 4096) = Encoder rotations per tick
(8.2) = Hypothetical gearbox (encoder rotations per mechanism rotations)
(0.1016 * PI) = Wheel circumference meters (4 inch wheel)
(1 / 4096) / (8.2) * (0.1016 * PI) = wheel distance per pulse in meters
the mag encoders will connect directly to the rio dio ports
so I have to input the wheel diameter in meters?
You can use whatever unit of distance you like, but you should be consistent across your program. Generally, meters are used since they are an SI unit and play nice with everything else. If you still like to measure stuff in other units, you can convert them wherever they’re used (in Java, Units.inchesToMeters(4)
for example).
perfect! so with the proper distance per pulse set, calling the getDistance()
method will output the distance the encoder has traveled in meters?
Yes, of the mechanism.
perfect. Thanks so much!
IF wired to the rio your resolution (encoder count) may be 1024.
If wired to your analog inputs your units would be in voltage.
double angle = ((1 - (m_turningEncoder.getVoltage() / RobotController.getVoltage5V())) * 2.0 * Math.PI
+ angleOffset + 2 * Math.PI);
Units are so fun!
What causes that difference?
I am not sure why the difference, maybe a bandwidth issue, but the manual has two different encoding types mentioned check page 7 CTRE Mag Encoder
One measures resolution in signal edges and the other in full quadrature cycles.
It’s not a resolution difference, it’s a scale difference. The roboRIO encoder class normalizes the decoding to cycles so that no matter whether you use 1x, 2x, or 4x decoding the scale doesn’t change. With 4x decoding 1 pulse will be 0.25 while on the Talon SRX it will be 1.
I’m not sure what you mean by this? Both take a measurement of encoder resolution, but they specify the measurement in different units.
You used the term units I used the term scale. But both have the same resolution (the smallest value that can be measured), one pulse or 1/4 cycle. Your original post said that the roboRIO doesn’t measure pulses but cycles.
I said that the API doesn’t measure pulses but cycles. What the hardware does isn’t important to the code question.
You’re still using terms that are confusing. The API outputs units of cycles. We both agree on that. Saying it measures cycles implies less resolution then it has.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.