Tuning the IRTF TCS3 Servo System

1. Type of motion 

   For Slewing/MP, use J=STEP to perform a point-to-point move.

   For Tracking, adjust velocity using 'Ixx22=vel J+' to keep pmac 
   position close to tcs3 vtcs position at 20Hhz.

2. Tuning Goals 

   For tracking we wanted to keep the motor following error inside a 0.2
   arcsecond band 95% of the time, And inside 0.1, 70% of the time.
  
      Following error peak-to-peak  values under 0.20 arcsec. 
      Following error standard dev. values under 0.03 arcsec. 

   We also wish to keep the velocity stable: not varying by more that 1.5 arcsecond/sec.

      Velocity  peak-to-peak  values under 1.50 arcsec/sec. 
      Velocity  standard dev. values under 0.30 arcsec. 

   During tracking, we used 30 arcseond offset as the standard value to tune
   to. Our setting time goal is 2 seconds.

   Based on TCS1 servo performance was measured in hist/0710/11oct_tcs1_data/.
      Following error peak-to-peak value under 0.20 arcsec (most of the time).  [0.15]
      Following error standard dev value is: 0.05                               [0.03]
      Velocity  peak-to-peak value under 1.40 arcsec (most of the time).        [1.30]
      Velocity  standard dev value is: 0.46                                     [0.30]
      
   The offset deadtime is 2.0 seconds for offset 60 arcseconds and under.

3. HA tracking (track & MV mode) 

   Auto PID values are 160000 15000 50

   P can be as low as 75000 up to 200000. 150000 give stiffer responds.
   Beyond a 140,000 the tracking following error stats starts to increase.

   High D is need to dampen offsets. 
   Lower D give better offset performance.
   Higher D give better tracking performance.
   A value of 50 balances tracking and offset performance.

   Lots of I is good to settle the motor after an offset. Looks like
   ~2000 is needed since tracking East need lots of I to setting.
   So we use high I gain, and Integrator limit of 2500 to keep the servo stable.

   After PID, the velocity Feedforward had the bigger impact on imporving
   the servo. HA uses a value of 23000

   Ix63, Motor XX integration Limit, doesn't help performance.
   However, the system is unstable at high I-terms . A value of Ix63=2000 is 
   a value with doen't affect performance during tracking+offset. 
   (I-value counts settles to about 1800 during tracking - tcs3 cand display 
   the integrator value).
   A suggest value of I163=2000 is used for safety.

   Need to modifiy the default Jog/Home S-Curve Time (Ix21) of 50 for
   tracking. 50ms will cause a ~50ms latency when an offset occures.
   For immediate response to offset, rtcs sets Ix21=1.

   Tried the  deadband feature but, it isn't very helpful during offsets. The
   motor_following_error cross back and forth zero during offset.
   Using deadband make it offshoot more.

   Ix35 (accel FeedForward) default is 0. Setting higher doesn't seem to help
   tracking or offsetting much. At values above 7000, it make offset worse
   (axis goes to fast, and starts overshooting). Maybe a value of 1000 is OK.

   Acceleration is controlled using Ixx19. Track allow for 800 as/s^2.

   The PC will limit the PMAC velocity to 400 as/s.

   We were toggling Ix34=1 (turning off the integrator) when rtcs_ferr is > 0.2
   arcsec; This effectly turns off I during an offset. Without this the I-term 
   would need to be lower: > 2500. However, once we set the integrator limit
   The stop toggling Ix34.

4. HA Slewing (slew & MP mode)

   PID values are 80000 5 50. Vel FF is 1280

   During slew we don't care about following error, so minimal I-gain of 5 is used. 

   acceleration is controlled using Ix21 (Jog/Home S-curve time)
      if( vel < 400 as/s)
         ix21 = 2000 (2 seconds)
      else
         ix21 = 4000 (4 seconds)

   At speeds above 400 as/s the pmac is unable to maintain a stable
   velocity. Use are using the S-Curve to provide a very relaxed acceleration
   curve for the telescope.
   Once the slew reaches 1800 as/s, the velocity should varies under 20 as/s, 
   and the following error should be peak-to-peak should be < 10 as.

   The PC will limit the PMAC velocity to 1800 as/s.

5. Dec tracking

   PID values are 95000 9000 35. VelFF is 25000

   P-term.
   Reasonable tracking (rates < 1as/s) can be achieved with P=80000. However, during offset
   the dec axis trails the pmac profile.  At the end of the offset, the following error
   can be many arcseconds away (relying on I to close the error). A higher P, 100000, is needed
   to keep this following error smaller.

   D-term.
   D is set to 35.

   I-term.
   After a N offset, I settles to about +200.
   After a S offset, I settles to about -600.
   The system work better with NoIOnOffset being ON, otherwise the I-values drifts away
   from its needed tracking value.
   When I is enabled, a higher I values allow the system to settle at it steady state.
   I=10000, allows the I to settle in about 1 second.

   Ix63, Motor XX integration Limit, is set to 1500 to limit the Dec axis tinegrator.

   The PC will limit the PMAC velocity to 400 as/s.

6. Dec Slewing

   PID values are 50000 5 10.

   acceleration is controlled using Ix21 (Jog/Home S-curve time)
   Ix21 = 1000 (1 seconds).

   The PC will limit the PMAC velocity to 1800 as/s.

6. Comment on D values when using the Tachometer as the velocity sensor.

   Because we are using the velocity loop, the TAC a provide better
   velocity data, but at a reduced resolution. It was estimated that
   switching between the encoder and TAC, the D would need to be reduce by
   120x. So a value of D=10,000 using the encoder would result in D=83
   when using the tachometer.

   In fact, during 2007-sept/oct, we (mistakenly) had the pmac configured
   to used the encoder (I104=$3501). Here is a note from then:
   "High D is need to dampen when offseting. Going over 10000 provides better
   damping, but the motor start to fighting with each other more, and we saw
   the motors fight each other after a slew. A value of 7000 is good as it
   balances good tracking with reasonable damping for offsets."
   When going to the velocity loop, the P general increased to 1.3x its values 
   verse the non-velocity loop value.

   Also see tachometer.txt.

7. Summary of PMAC tuning Ixx Variables

Maximum Jog/Home Accel     Ixx19  default=0.15625 count/m^2; *Set at begining of track/slew.
Jog/Home Accel time        Ixx20  default=0 (ixx21 is in control). (NOT USED BY TCS3)
Jog/Home S-curve time      Ixx21  default=50 *rtcs commands in realtime.        

PID Proportional Gain       Ixx30 * rtcs commands in realtime (if autopid is ON)
PID Integral Gain           Ixx33 * rtcs commands in realtime (if autopid is ON)
PID Integral Mode           Ixx34 * default=1; change to 0 in setup. 0 means On all the time.
PID Derivative Gain         Ixx31 * rtcs commands in realtime (if autopid is ON)

PID Velocity FF Gain        Ixx32 
PID Accel FF Gain           Ixx35 * suggested value 1000. default is 0.


Max Jog/Home Acceleration   Ixx19 *  rtcs commands in realtime (track, slew, mv,mp)
Max Jog/Home Accel Time     Ixx20 
Max Jog/Home S-Curve Time   Ixx21 *  rtcs commands in realtime (track, slew, mv, mp)
Max Jog Speed               Ixx22 *  rtcs commands in realtime (Track, Slew, MV, MP) 

Abort Deceleration Rate     Ixx15

Net Desired Pos Filter Gain Ixx40
Desired Positin Limit Band  Ixx41

Motor Integration Limit     Ixx63    default=4,194,304. For safety set to 4000.
                                     (about 2000 is used during tracking).

Deadband Gain Factor        Ixx64    default=0
Deadband Size               Ixx65    default=0

Position Error Limit        Ixx67    default=4,194,304 (=262,144 counts)

Motor Friction Feedforward  Ixx68    default=0

Output Command Limit        Ixx69 *  13106 -> we limit the DAC output to 4v..