Ascend
Coding
Ascend
  • 🚀Introduction
  • VEX Robotics
    • 🛠️Building
      • 📏CAD Design
      • 🔧Best Practices
      • 🏎️Drive Trains
        • 🔩Screw Joints
        • 🥊Boxing
        • 🔵Bearing flats
        • 🛤️Fixing Friction
        • 🔥450 RPM on 2.75"
      • 🏍️Motors
      • 🪨Metal
      • Plastic
      • 🎈Pneumatics
      • ➕Additional Mechanisms
        • 🖨️3D Printing
        • ↔️Ratchets
        • 🏹Catapults
        • 🎣Intakes
        • 🏋️Lifts
    • 💻Coding
      • ⚖️Choosing Your Coding Environment
      • 🔴VEXCode Pro
        • 🖥️Getting Started
        • 🚗Drive Code
        • 🚴Coding Motors
        • 🌬️Coding Pneumatics
        • 🎛️Advanced
          • 📡Coding Autonomous
          • 📈Coding PIDs
            • ⬆️Drive PID Tutorial
            • ↩️Turn PID Tutorial
            • 🎸Tuning PIDs
              • 🔢Ziegler-Nichols Method
              • 📊Graphing PIDs
          • 📋Tasks
          • 🚝Advanced Drive Code
      • 🟡PROS
    • 📗Engineering Notebook
      • 📔Formatting
      • ⭐Notebook Walkthrough
      • 💠Decision Matrices
        • 📌Decision Point
      • ➕Additional Resources
    • 🏆Tournaments
      • 🗣️Team Interviews
        • 🪙Interview Tips
        • ⛳Interview Scoring
        • 🤽‍♀️Interview Practice Questions
      • 🤹Skills
      • ℹ️Ranking and Stats
      • 📷Filming Matches
  • Other
    • 🧑‍💼Management
      • 🕑Time Management
      • 👨‍👩‍👧‍👦Team Management
        • 👮Delegation
        • ⚓Optimal Team Size
      • 🖇️Code Management (GitHub)
      • 🚋Resource Management
      • ⁉️Stuck?
    • 🍎Physics
      • ⚙️Torque
      • 😑Stress Forces
    • 👾Extra stuff
      • 📸96504 Gallery
      • ⛑️VEX Team Resources (High Stakes)
      • 🏎️Driving Simulator
Powered by GitBook
On this page

Was this helpful?

  1. VEX Robotics
  2. Coding
  3. VEXCode Pro
  4. Advanced

Coding PIDs

Worth it.

PreviousCoding AutonomousNextDrive PID Tutorial

Last updated 1 year ago

Was this helpful?

A PID (proportional integral derivative) controller is an advanced coding technique to make the robot's motion consistent, reliable, and efficient.

Theory

PIDs are used everywhere in industrial robotics--car factories, robot vacuums, and more. If a robot moves, it likely uses PIDs to move.

But why? PIDs do one thing, and they do it really well. They move a robot from point A to point B:

But how? This is where the PID algorithm comes in. There are three parts to a PID controller, given by the acronym. Each part applies a specific power to the drive motors based on certain factors:

  • P (Proportional): Update motor power based on the present

  • I (Integral): Update motor power based on the past

  • D (Derivative): Update motor power based on the future

What each part really does
  • P: if the robot is far from point B, set the motor power high so the robot gets there faster. If the robot is close, set the motor power low so the robot doesn't overshoot.

  • I: if the robot is close to point B, but not quite there, increase the motor power so the robot doesn't stall.

  • D: if the robot is rapidly approaching point B, apply the brakes so the robot doesn't go too far (overshoot).

The motor power is calculated by the following line of code, which is the heart of the PID algorithm:

float motorPower = (kP * proportional) + (kI * integral) + (kD * derivative);

That is, each part of the PID is added together to calculate motor power. kP, kI, and kD are constants that determine the relative weights of each portion of the PID.

Error

Error refers to how far the robot is from the target point. If the robot wants to go forward 20 inches, the PID algorithm would calculate the following errors.

Error plays a major factor in the PID algorithm; we'll see how later. If you want some more explanation, here's a good eight-minute video explaining the theory behind PIDs:

Now, let's start by coding your drive PID!

💻
🔴
🎛️
📈
⬆️Drive PID Tutorial
See these robots? They use PIDs
That's a PID. Yep, it's not that bad.
Figure 3