Another mentor and myself are trying to learn closed-loop motion control so we can teach our students next year. We have been going through the CTRE documentation and sample code but we have a question.
We are using a E4T encoder with a drive train with a 6-CIM Evo shifter.
Our first question is how many “pulses” per revolution for that encoder. If we spin the tire about 1 revolution, we get a change in the call to “double encoderPosition = _rightMaster.getSensorCollection().getQuadraturePosition();” of about 600. What is this number? I thought it was supposed to be 4096.
We are using the “high” gear on the gearbox, which is 6:1. 4096/6 = 682. 67. Is that the number we should be expecting?
The number of counts per revolution is dependent on where the encoder is placed. We often place our CTRE MagEncoder at the end of our shaft. This means that one rotation will always be 4096. In your case, it seems that the encoder is placed in a position before the gears move. I think your estimate of 4096 / 6 is correct.
E4T is 360 CPR according to the product page, so you should get 1,440 “counts” per rotation of the encoder shaft.
The 4096 number is for the 1024 CPR SRX Mag Encoders.
Note that you should really just measure your “distance/count” constant empirically. Move your robot 10ft forward and see exactly how much the encoders changed.
Thanks for the help. I should have read the page for the EVO shifter.
" Encoder Ratio:
When programming for the encoders, please know that the ratio between the Output Shaft and Encoder Shaft of the EVO Shifter is 3:1. The Output Shaft’s 20T 32DP gear mates with a 60T 32DP gear on the Encoder Shaft."
So our counts should 480. I will do some more testing and get back to you.
And we will definitely measure empirically as well.
What are some of the controlModes are you looking to learn?
Velocity?
Position?
MotionMagic?
Thats the order I would proceed with if you have no previous experiences.
Download the samples from CTRE github and the major part you will need to change and check is the .configSelectedFeedbackSensor( FeedbackDevice.??) Looking now they even have samples that use a QuadEncoder.
Their 2019 documentation is still improving and I have seen big changes in the past few week. The walkthroughs for the different modes are also getting better too.
In most cases the steps are
1 make sure sensor is in phase with output
2 calculate Feedforward (Not for Position mode)
3 calculate PID
For the basic sample the test code for collecting the information to get these calculation is included.
Thanks for the advice. We started with position first. We will move to velocity next. Our ultimate goal for this project is learning MotionMagic with encoder and NavX feedback.
Can you tell us what is sensor phase and Feedforward?
Sensor phase is the direction which the encoder perceived as forward. This way when the wheels spin forward the encoder count increases and when the wheels spin backwards the encoder count decreases. In an out of phase setup the encoder count would decrease (into the negatives ) when the wheels spin forward and vice versa.
It’s tough for me to link to all the documents but the CTRE documents have good articles that help through these processes.
Most of the single motor samples when holding no buttons will use the joystick to jog the motor in openloop. Use the pheonix tuner plot tool to watch the motor. When commanded to run positive confirm PID0 velocity is positive and encoder is increasing.
Record the PID0 max velocity when running the motor at 100%. Kf = (100% × 1024) / maxObserved
Here is a link to our Motion Magic Calculators that has step one Feed forward https://tinyurl.com/GCGH-MM-WS