SharpAI
/

How does PID control work on an FTC arm?

PID control on an FTC arm often involves compensating for the effect of gravity, which changes depending on the arm's angle . The relative force of gravity on an arm can be calculated as the cosine of the angle the arm makes with the horizontal, where zero degrees is straight to the side . This calculated gravity effect can then be used as a feedforward parameter for a PID controller .

A common approach for gravity-compensated feedforward involves adding a kF constant multiplied by the cosine of the arm's current angle to the PID output . The kF constant, which approximates the power needed to counteract gravity, is typically found empirically by setting PID gains to zero and adjusting kF until the arm can hold its position at any angle .

The angle of the arm can be determined using an encoder . The DEGREE_PER_TICK value, necessary for this calculation, is found by dividing 360 by the encoder's resolution and multiplying by the gear ratio . The pseudocode for calculating the current angle is current_angle = (TICKS_AT_ZERO - current_tick) * DEGREE_PER_TICK .

For controlling a single motor's velocity or position, the built-in PID controller can be used by setting the run mode to RUN_USING_ENCODER . However, the built-in PID controller has a fixed refresh rate of 20Hz (50ms sample rate) . For higher performance and more stable control, some teams use an external PID controller, which allows for higher sample rates, potentially up to 80Hz . When using an external PID controller, it is generally recommended to use RUN_WITHOUT_ENCODER mode .

While the proportional (Kₚ) and derivative (Kd) terms are often sufficient, the integral term (Kᵢ) can be used to correct for situations where the motor isn't supplied enough power to reach the target, by summing the error over time and increasing the output . To prevent lag from affecting the sum, the error is multiplied by the time taken for the previous loop iteration before being added to the integral term .

Was this right?

Generated from indexed documentation and can be wrong — check the source beside each claim. Follow-ups are not saved. Unofficial, not affiliated with FIRST. Quotes Game Manual 0 (CC BY-NC 4.0) and FTC Docs (BSD 3-Clause). Built by Sharp Face Robotics.