REF#01: Talon SRX Motion Profile Reference Manual (see https://www.ctr-electronics.com/downloads/pdf/Talon%20SRX%20Motion%20Profile%20Reference%20Manual.pdf)
REF#02: Talon SRX Software Reference manual (see http://www.ctr-electronics.com/downloads/pdf/Talon%20SRX%20Software%20Reference%20Manual.pdf)
Closed Loop Position Control with Talon SRX Motor Controller and Magnetic Encoder
This is the approach we used to determine the PID values for the drive base on our 2017 FRC robot. The drive was based on 6 colson wheels, 3 per side linked by chain. Custom gearbox on each side driven by 2 standard CIMs (4 in total for the drive base). Each motor driven by a separate Talon SRX. Motor controllers arranged in two pairs, one master and one slave in each pair on each side. Two SRX Magnetic Encoders, one on centre wheel axel on each side. Encoder connected to Master Talon SRX.
Basically we followed instructions in the "Talon SRX Motion Profile Manual" - Section 6.
the first step is to confirm that the encoder is reporting positive when the speed is positive and negative when the speed is negative, if not then we must use the SetSenorDirection() in our code to reverse the default configuration.
With the robot drive motors running at full forward speed we can observe the speed reported by the encoders on the roboRIO web interface. The same interface reports the velocity in "native units per 100ms". Use Internet Explorer browse to http://172.22.11.2 (for USB) or http://roboRIO-XXXX-FRC.local (for an ethernet or wifi connection) where XXXX is your team number. Take several snapshots and average them to arrive at a full speed rpm. In our case we have 5.3:1 gearbox powered by standard CMs (5330 RPM) so the measured rpm should be approximately 5330 / 5.3 = 1000 rpm. In fact we observed an average of 803.67 rpm on the right side of the drive base and 807.04 rpm on the left.
We calculate the forward gain from the velocity in "native units per 100ms". The velocity is calculated by taking the full speed rpm, dividing by 60 to get the revolutions per second then dividing by 10 to get the revolutions per 100ms and then multiplying by the resolution of the magnetic encoder (4096 in this case).
For the right side this is: 803.67 x (1/60) x (1/10) x 4096 = 5486.36
For the left side this is: 807.38 x (1/60) x (1/10) x 4096 = 5509.38
The forward gain is then calculated by dividing the forward motor output (1023) by the velocity in native units per 100ms.
For the right side the feed forward gain is: 1023 / 5486.36 = 0.186462
For the left side the feed forward gain is: 1023 / 5509.38 = 0.185683
To determine the P, I and D values we take the general tuning strategy from the "Talon SRX Software Manual" - section 10.1 ...
For example if you want your mechanism to drive 50% throttle when the error is 4096 (one rotation when using CTRE Mag Encoder), then the calculated Proportional Gain would be (0.50 X 1023) / 4096 = ~0.125. To check our math, take an error (native units) of 4096 X 0.125 => 512 (50% throttle). Tune this until the sensed value is close to the target under typical load. Many prefer to simply double the P-gain until oscillations occur, then reduce accordingly. If the mechanism accelerates too abruptly, Derivative Gain can be used to smooth the motion. Typically start with 10x to 100x of your current Proportional Gain. If the mechanism never quite reaches the target and increasing Integral Gain is viable, start with 1/100th of the Proportional Gain.
... in our case we found that the drive stablesed with P only and we left I and D at zero.
Closed Loop Velocity Control with Talon SRX Motor Controller and Versa Planetary Integrated Encoder
This is the approach we used with the two 775pro shooter motors on our 2017 FRC robot. Each motor was driven independently with it's own Talon SRX motor controller and was driving a 3:1 versa planetary gearbox with an integrated encoder.
(a) Setting the sensor direction ...
with the power set to +1.0 the sensor produced +ve postion and +ve RPM with "SetSensorDirection(false);"
with the power set to +1.0 the sensor produced -ve postion and -ve RPM with "SetSensorDirection(true);"
result is that we use "SetSensorDirection(false);"
(b) The calculation for F-gain was arrived at as described in the above ...
5750 rpm divided by 60 to get 95.8 revs/sec
95.8 revs/sec divided by 10 to get 9.58 revs/100ms
each rev is 4096 units so 9.58 multiplied by 4096 gives 39253 native units per 100ms
suggested starting F-gain = 100% of 1023 / 39253 = 0.0261
(c) When we implemented this the resulting speed was 3100+ rpm when 3000rpm requested so we
tuned the F-gain back to 0.02525 to arrive at 3000rpm +/-12rpm.
(d) The calculation for P-gain was arrived at ...
12rpm was maximum error observed
this equates to 12 * 1/60 * 1/10 * 4096 = 81.92 native units per 100ms
suggested starting P-gain = 10% of 1023 / 81.92 = 1.248779
(e) Using this resulted in the motor maxing out at 5750 RPM!!!
(f) Updated Talon SRX firmware to version 2.23.
(g) Still a problem ... may be due to "Run();" being in Command "Execute();" method ... moved to Command "Initialise();" method
(h) Still a problem ... so reduced P-gain to 0.01
(i) We are now stable with motor running at 3004 to 3013 rpm over extended period (30 seconds) with P-gain = 0.01
(j) Stable at P-gain = 0.02