PID Tuning Practice - Arm
Overview
This lesson demonstrates PID tuning for an arm mechanism. Arms are more complex than elevators due to their rotational nature and varying gravity effects. You'll learn how to tune kG precisely, tune kP, and use motion profiling (trapezoidal profiles) to achieve smooth, accurate control.
Video Tutorial
Watch this video for a complete walkthrough of arm PID tuning:
Prerequisites
Before starting this lesson, you should have:
• Completed the Setup lesson
• Completed the Elevator tuning lesson (for basic tuning concepts)
• Arm mechanism selected in SmartDashboard
• Live tuning enabled in Elastic
• Position and velocity graphs set up in AdvantageScope
• Completed the Setup lesson
• Completed the Elevator tuning lesson (for basic tuning concepts)
• Arm mechanism selected in SmartDashboard
• Live tuning enabled in Elastic
• Position and velocity graphs set up in AdvantageScope
Tuning Steps
- Set the setpoint to a position within the arm's range. Watch for the red line (soft limit) showing the maximum allowed position. Avoid setting the setpoint too close to or beyond it, as this can cause glitches in simulation. Find a position that works well for your arm mechanism.
- Find the smallest kG value that holds position without moving:
- Start with kG = 0.2, then 0.4, then 0.8 (doubling values)
- Watch the position graph (blue line) - it should stay completely flat
- When you see movement, set kG to a negative value to reset the position
- Use binary search (narrowing between the last good value and the first value that moves)
- Example progression: 0.75 (good) → 0.8 (too high) → 0.76 (good) → 0.77 (good) → 0.78 (good) → 0.79 (too high)
- For finicky mechanisms, continue to 3-4 decimal places
- Example: 0.785 (moving) → 0.782 (not moving) → 0.7815 (good, flat line)
- Test slightly above (e.g., 0.7817) to check for wiggles - if wiggles appear, use the lower value
- Verify kG precision:
- Position line should be completely flat with no movement
- Check for any wiggles or small movements
- For arms with lower gear ratios (how motor rotation translates to mechanism movement), 2-3 decimal place precision is important
- Small velocity changes may be due to simulation limitations
- Start tuning kP using the doubling method:
- Begin with kP = 0.1
- Command the arm to move to the target position
- Watch the position graph - arms with high inertia (resistance to changes in motion) may move slowly initially
- Double kP values: 0.1 → 0.2 → 0.4 → 0.8 → 1.6, etc.
- Continue until the arm reaches the target position
- Heavy arms with high inertia require more force to move, so you may need higher kP values
- Watch for overshoot:
- Overshoot appears as the position graph traveling past the target position before settling
- This means the arm is moving too fast and overshooting the target
- Overshoot is dangerous if the arm has hard stops (physical limits) - it could ram into them
- The goal is to minimize or eliminate overshoot
- Configure motion profiling in the arm subsystem code. Find the closed loop controller settings (motion profiling constraints):
- Max Velocity: Maximum speed the arm can move (degrees per second in this example)
- Max Acceleration: How quickly the arm can change speed (degrees per second per second)
- Set max velocity:
- Consider the distance the arm needs to travel and desired completion time
- Example: Moving from position 8 to -10 (about 60 degrees) in less than 1 second including acceleration → set max velocity around 90 degrees per second
- Test different values and observe the effect on motion smoothness
- Lower values (e.g., 45) create smoother, slower motion
- Setting to zero (default) means immediate jump to max velocity, which is not how motors actually work - motors need time to ramp up
- Set max acceleration:
- Max acceleration should typically be higher than max velocity
- This allows the mechanism to accelerate to max velocity in less than 1 second
- If acceleration is lower than velocity, it takes more than 1 second to reach max speed
- Higher values create sharper, more rectangular motion profiles
- Lower values reduce the initial "jump" and make movement smoother
- Adjust to reduce noticeable jumps at the start of movement
- Fine-tune motion profile and kP together:
- Work with both max velocity and max acceleration to eliminate overshoot
- You may need to slightly decrease kP if there's still a small jump
- Test different combinations of values
- Goal: virtually no overshoot and smooth motion
- Evaluate the final motion profile. The ideal motion should look rectangular/boxy in the position graph:
- Sharp transition up: Quick acceleration to target
- Flat hold: Maintains position at target
- Sharp transition down: Quick return when commanded to a new position
- Avoid motion that looks "all over the place" with oscillation or overshoot
- Compare before and after motion profiling. Without motion profiling, the position graph may show erratic movement that takes longer and is less efficient. With proper tuning, you should see clean, rectangular transitions.
Arm Tuning Process Summary
Complete workflow:
- Set setpoint to appropriate position (within soft limits)
- Tune kG to 2-3 decimal places precision - position line must be flat
- Tune kP by doubling until arm reaches position
- Watch for overshoot in position graph
- Configure motion profiling (max velocity and max acceleration)
- Max acceleration should be higher than max velocity
- Fine-tune to achieve rectangular motion profile
- Motion should be sharp up, flat across, sharp down
Why Motion Profiling Matters
Motion profiling is crucial for arms because:
• Prevents overshoot: Controls acceleration to avoid ramming into hard stops
• Reduces jerkiness: Smooths out sudden movements that can break chains or damage mechanisms
• More efficient: Faster and more accurate than uncontrolled movement
• Protects hardware: Prevents the mechanism from being too energetic or extreme
Without motion profiling, mechanisms can experience sudden jerks that cause mechanical failures (like broken chains, as mentioned in the video).
• Prevents overshoot: Controls acceleration to avoid ramming into hard stops
• Reduces jerkiness: Smooths out sudden movements that can break chains or damage mechanisms
• More efficient: Faster and more accurate than uncontrolled movement
• Protects hardware: Prevents the mechanism from being too energetic or extreme
Without motion profiling, mechanisms can experience sudden jerks that cause mechanical failures (like broken chains, as mentioned in the video).
Trapezoidal vs Exponential Profiles
The video uses trapezoidal motion profiles because they're more intuitive. However, exponential profiles are often better because:
• Motors need time to ramp up - they don't instantly jump to max velocity
• Exponential profiles better match how motors actually behave
• They can provide even smoother motion
Trapezoidal profiles are a good starting point for learning, but consider exponential profiles for production code.
• Motors need time to ramp up - they don't instantly jump to max velocity
• Exponential profiles better match how motors actually behave
• They can provide even smoother motion
Trapezoidal profiles are a good starting point for learning, but consider exponential profiles for production code.
Applying to Physical Hardware
The same techniques apply when tuning with physical hardware:
• Phoenix Tuner: Use Config tab to adjust values. Graph "rotor position" and "velocity."
• REV Hardware Client: Similar configuration options available
• The tuning process is identical: precise kG, kP tuning, then motion profiling
• Watch for the same rectangular motion profile
Even though the tools look different, the principles and techniques you learn here apply directly to physical mechanism tuning.
• Phoenix Tuner: Use Config tab to adjust values. Graph "rotor position" and "velocity."
• REV Hardware Client: Similar configuration options available
• The tuning process is identical: precise kG, kP tuning, then motion profiling
• Watch for the same rectangular motion profile
Even though the tools look different, the principles and techniques you learn here apply directly to physical mechanism tuning.
Key Takeaways
The complete arm tuning process involves:
1. Precise kG tuning: Get it accurate to 2-3 decimal places for finicky mechanisms
2. kP tuning: Double until you reach the target, but watch for overshoot
3. Motion profiling: Use max velocity and max acceleration to create smooth, rectangular motion
4. Rectangular shape goal: The position graph should look like a rectangle, not a curve or oscillation
These skills apply to all mechanism tuning, whether using simulation tools or physical hardware tuning tools.
1. Precise kG tuning: Get it accurate to 2-3 decimal places for finicky mechanisms
2. kP tuning: Double until you reach the target, but watch for overshoot
3. Motion profiling: Use max velocity and max acceleration to create smooth, rectangular motion
4. Rectangular shape goal: The position graph should look like a rectangle, not a curve or oscillation
These skills apply to all mechanism tuning, whether using simulation tools or physical hardware tuning tools.