Changes between Version 16 and Version 17 of MotorControl


Ignore:
Timestamp:
Mar 26, 2016, 11:57:38 AM (9 years ago)
Author:
kosborn
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MotorControl

    v16 v17  
    2222
    2323__Closed Loop Control__
    24 Talons use encoders to achieve "closed-loop" control: your program sets the Talon to achieve a particular speed or position and the Talon automatically and continuously adjusts power to the motor, measures the speed or position with an encoder, and adjusts power again to keep the motor at the desired speed or position.
     24Talons use encoders to achieve "closed-loop" control: your program sets the Talon to achieve a particular speed (rate) or position (displacement) and the Talon automatically and continuously adjusts power to the motor, measures the speed or position with an encoder, and adjusts power again to keep the motor at the desired speed or position.
    2525
    26 In the real world, closed-loop control is tricky: the Talon must account for changing loads on the motor and the inertia of its mechanisms (arm, entire robot, etc.).  If motor power is adjusted too quickly, the motor can overshoot its goal; if power is adjusted too slowly, the mechanism may not respond to changes in a timely fashion.
     26In the real world, closed-loop control is tricky: the Talon must account for changing loads on the motor and the inertia of its mechanisms (arm, entire robot, etc.).  If motor power is adjusted too quickly, the motor can overshoot its goal; if power is adjusted too slowly, the mechanism may not respond to changes in a timely fashion. The control loop can even become unstable and oscillate around its target.
    2727
    2828__PID Control__
    29 Closed-loop motor control (including the Talons) typically uses PID control loops to achieve the mechanism's control objectives: balancing responsiveness with stability.  PID control considers 3 factors (P, I, D) when deciding how to adjust motor power to balance responsiveness (how fast the motor responds to changes) with stability (not over/under shooting the target).  Because motors drive different mechanisms with different loads, inertia, speeds, and responsiveness requirements, you must tune the PID factors properly for each Talon when you configure it for close-loop control; this page discusses in plain language what that means.
     29Closed-loop motor control (including the software built into the Talons) typically uses PID control loops to achieve the mechanism's control objectives: balancing responsiveness with stability.  PID control considers 3 factors (P, I, D) when deciding how to adjust motor power to balance responsiveness (how fast the motor responds to changes) with stability (not over/under shooting the target).  Because motors drive different mechanisms with different loads, inertia, speeds, and responsiveness requirements, you must tune the PID factors properly for each Talon when you configure it for close-loop control; this page discusses in plain language what that means.
    3030
    3131__The problems PID is intended to solve__
    32 If you want a motor to spin at 100rpm and it was stopped, taking the simplest approach, you might apply full power to the motor and then measure again, but with no load, full power might get it spinning at 2000rpm before you can measure again - severely overshooting your goal.  Conversely if the motor is under heavy load and was running a bit too fast (e.g. 110rpm at last measurement), cutting all power to the motor might cause it to drop to 0rpm before you measure again - severely undershooting the goal.  A system like this is very responsive to changes but is not stable: it over/undershoots goals by adjusting power too much and can even oscillate (never stabilize on the desired goal).
     32You might want to move a mechanism to a particular position and then stop and hold it at that position.  To move the mechanism, you apply power to the motor, ramping it up until the motor overcomes the mechanism's inertia and starts moving; the trick then is to get the mechanism to stop in the desired position and then continuously adjust power to the motor to hold it there.  PID must account for many factors; for example, it can't just cut power to the motor when it reaches the target position because the inertia of the mechanism will carry it past (overshoot).  Moreover, in many cases, the motor must have continuous power applied or the mechanism will backdrive and fall away from its target position. PID control must ramp power to the motor so the mechanism quickly reaches the target position, but ramp down the power as it approaches the target position and then continuously adjust power to maintain position.  It's tricky.
     33
     34Similarly, if you want a motor to spin at 100rpm, taking the simplest approach, you might apply full power to the motor to get it started and then measure again, but with no load, full power might get it spinning at 2000rpm before you can measure again - severely overshooting your goal.  Conversely if the motor is under heavy load and was running a bit too fast (e.g. 110rpm at last measurement), cutting all power to the motor might cause it to drop to 0rpm before you measure again - severely undershooting the goal.  A system like this is very responsive to changes but is not stable: it over/undershoots goals by adjusting power too much and can even oscillate (never stabilize on the desired goal).
    3335
    3436Rather than turning power entirely on or off, you might slowly ramp power to the motor, measuring frequently, until you hit your target speed and then monitoring and adjusting power gradually and continuously to maintain that speed.  However, slow changes in speed might make the mechanism insufficiently responsive: taking too long to get up to speed or respond to external changes.  If the motor suddenly encountered a load that slowed it down (e.g. driving up a hill), it might take a long time to get back up to speed only to have crested the hill and be going down hill too fast...until the control loop caught up.  This system is very stable, but is not adequately responsive.
     
    3739
    3840__What PID means__
    39 PID is used to balance responsiveness and stability using factors P, I, D, and sometimes F that you can tune.  When you configure your PID control loop (in the Talon or RoboRio), you will need to set those 3 factors.  There is no perfect setting, it's always going to be a trade off between responsiveness, overshoot, and stability, but you should experiment with different values to tune your mechanism properly (there are also mathematical approaches to tuning that you can find with some googling).
     41PID is used to balance responsiveness and stability using factors P, I, D, and sometimes F that you can tune.  When you configure your PID control loop (in the Talon or !RoboRio), you will need to set those 3 factors.  There is no perfect setting, it's always going to be a trade off between responsiveness, overshoot, and stability, but you should experiment with different values to tune your mechanism properly (there are also mathematical approaches to tuning that you can find with some googling).
    4042
    4143   * Proportion (P): Power is increased/decreased in proportion to how far the last measurement was from its goal (i.e. the instantaneous error): if far from goal, add a lot of power, if close to goal, add a little power).  Adjusting P determines how responsive the system is.  Adding P increases responsiveness, but too much P will cause oscillation around the steady state point.
     
    4446   * !FeedForward (F): Adds a constant to the output to keep it from going to zero
    4547
    46 PID control loops are an important concept and the basics are explained in [https://en.wikipedia.org/wiki/PID_controller Wikipedia] and [http://www.expertune.com/tutor.aspx this tutorial] and [http://www.csimn.com/CSI_pages/PIDforDummies.html PID for Dummies].  You can implement a PID control loop using the Talon SRX or withthe RoboRio; you should refer to the [https://www.ctr-electronics.com/Talon%20SRX%20Software%20Reference%20Manual.pdf Talon software manual] section 12.4 (page 75) for a detailed explanation of how to configure the Talon for PID control with Java example code.  In cases where PID control can't be implemented via the TalonSRX (e.g. for a non-Talon-controlled motor or when the feedback mechanism can't connect to the Talon), the !RoboRio can also implement PID control using the PIDController and PIDSubsystem classes; see [https://wpilib.screenstepslive.com/s/4485/m/13809/l/241901-pidsubsystems-for-built-in-pid-control here] and [http://cntsoftware.com/robotics/pdf/WPILib_programming.pdf here], and [https://www.assembla.com/spaces/rbhsrobotics/documents/cS2tESqASr45PGacwqjQYw/download/cS2tESqASr45PGacwqjQYw# here].
     48PID control loops are an important concept and the basics are explained in [https://en.wikipedia.org/wiki/PID_controller Wikipedia] and [http://www.expertune.com/tutor.aspx this tutorial] and [http://www.csimn.com/CSI_pages/PIDforDummies.html PID for Dummies].  You can implement a PID control loop using the Talon SRX or with the !RoboRio; you should refer to the [https://www.ctr-electronics.com/Talon%20SRX%20Software%20Reference%20Manual.pdf Talon software manual] section 12.4 (page 75) for a detailed explanation of how to configure the Talon for PID control with Java example code.  In cases where PID control can't be implemented via the TalonSRX (e.g. for a non-Talon-controlled motor or when the feedback mechanism can't connect to the Talon), the !RoboRio can also implement PID control using the PIDController and PIDSubsystem classes; see [https://wpilib.screenstepslive.com/s/4485/m/13809/l/241901-pidsubsystems-for-built-in-pid-control here] and [http://cntsoftware.com/robotics/pdf/WPILib_programming.pdf here], and [https://www.assembla.com/spaces/rbhsrobotics/documents/cS2tESqASr45PGacwqjQYw/download/cS2tESqASr45PGacwqjQYw# here].
    4749
    4850[http://www.orientalmotor.com/technology/articles/motor-sizing-calculations.html Motor Sizing Calculations]