LogoLogo
  • Welcome!
  • Mission Statement
  • Contributing Guidelines
    • Embed CADs in Wiki Articles
  • VEX Worlds Livestream Archive
    • VEX U
    • V5RC High School
    • V5RC Middle School
    • VIQRC Middle School
    • VIQRC Elementary School
    • JROTC
  • ⚙️Hardware
    • Design Fundamentals
      • Gear Ratios
      • Internal Forces (Stress)
      • Torque
      • RPM
      • Center of Mass
    • Introduction to VEX Parts
      • Structure
        • C-Channels and Angles
        • Fasteners
        • Retainers
        • Gussets and Brackets
        • Bearings
        • Plate Metal and Flat Bars
      • Motion
        • High Strength Components
        • Gears and Sprockets
        • Traction Wheels
        • Mecanum Wheels
        • Omnidirectional Wheels
        • Flex Wheels
    • Robot Decorations
      • Part Dyeing
      • Metal Coloring
      • License Plate Holders
    • Lifts
      • Double Reverse Four Bar (DR4B or RD4B)
      • Four Bar
      • Scissor Lift
      • Six Bar
      • Other Lifts
      • Best Practices
    • Shooting Mechanisms
      • Catapult
      • Flywheel
      • Linear Puncher
    • Drivetrains
      • Tank Drive
      • Mecanum Drive
      • Holonomic Drive
      • Designing a Drivetrain
      • Best Practices
    • Pivots & Joints
    • Pneumatics
      • Best Practices - Pneumatics
    • Intakes
    • Flip Out Mechanisms
    • Defensive Mechanisms
    • Misc. Building Techniques
    • VexU
      • Common Manufacturing Techniques
        • 3D Printing
        • Laser Cutting
      • Custom Manufactured Parts Library
      • Commercial Off The Shelf Parts Library
  • 👑Team Administration
    • New Team Resources
      • Creating The Team
      • Gaining Interest for Robotics Teams
      • Attending Competitions
        • Elimination Bracket
    • Team Dynamics
      • Organization Structure and Longevity
      • Member Allocation and Management
      • How *Not* To Run a Team
    • Team Finances
      • One-Year Team Financial Breakdown
      • Funding Your Teams
    • Hosting Competitions
      • Live Streaming
      • Tournament Manager
        • Competition Electronics
        • Creating a Tournament
        • Tools
          • Field Set Control
          • Connecting Mobile Devices
          • Connecting Raspberry Pis
        • Match Control
          • Inputting Match Scores
          • Inputting Skills Scores
          • Inputting Scores on TM Mobile
        • Displays
        • Alliance Selection
      • Additional Event Partner Resources
    • VexU Organization Management
      • Getting Started in VexU
      • Team / Personnel Management
      • Volunteering At Local Events
  • 📚The Judging Process
    • The Engineering Design Process
      • Test and Refine
    • The Engineering Notebook
      • Segments of the Notebook
      • BLRS2 '23-'24 Engineering Notebook
      • Integrating Inventor Models into Documentation
      • Engineering Notebook Rubric Breakdown
    • The Interview
      • Interview Rubric Breakdown
    • Using Notion for an Engineering Notebook
      • How to Setup a Notebook
      • How to Create Entries
      • How to Export a Notebook
      • Purdue SIGBots Notion Template
        • Game Analysis
        • Identify The Problem
        • Brainstorm Solution
        • Select Best Approach & Plan
        • Build Log
        • Programming Log
        • Testing Solution
        • Tournament Recap
        • Innovative Feature
  • 🖥️VEX CAD
    • CAD Programs
      • Inventor
      • Fusion 360
      • Solidworks
      • OnShape
      • Protobot
    • Making a Chassis
      • Inventor Chassis: The Basics
        • Installation
        • User Interface Overview
        • Dark Mode
        • Assemblies
        • Placing Parts
        • Navigating CAD
        • Changing Visual Style
        • Grounding
        • Connecting Two C-Channels
        • Modifying Existing Constraints
        • Toggling Visibility on Existing Parts
        • Completing Half of the Chassis
          • Inner Drive Channel
          • Bearing Flats
          • Motors
          • Wheels
          • Sprockets
          • Spacers, Washers and Standoffs
          • Spacers Cont.
        • Creating Mid-Plane
        • Mirroring
      • Inventor Chassis: Best Practices
        • File Structure
        • Subassemblies
        • Wheel Subassembly
        • Origin Planes
        • Cross Brace
        • Drive Channels
        • Simple Motor iMates
        • Replacing Simple Electronics
        • Completing Half of the Drive
          • Bearing Flats (Best Practice)
          • Wheels
          • Powered Gear
          • Spacer Boxing
          • Spacers, Washers and Standoffs (Best Practice)
        • Model Browser Folders
        • Mirroring (Best Practice)
        • Model Browser Folder (Right)
        • Main Assembly
      • Fusion 360 Chassis
      • Solidworks Chassis, Chain, and Custom Plastic
    • Remembering The Best
      • 62A Skyrise
      • 400X Nothing But Net
      • 2587Z Nothing But Net
      • 365X Starstruck
      • 62A In The Zone
      • 202Z In The Zone
      • 5225A In The Zone
      • 169A Turning Point
      • 929U Turning Point
      • 7K Tower Takeover
      • 5225A Tower Takeover
      • 62A Change Up
    • Scuff Controller
  • 💻Software
    • Odometry
    • Path Planning
    • Robotics Basics
      • Arcade Drive
      • Tank Drive
      • Joystick Deadzones
      • Curvature (Cheesy) Drive
      • Subsystem Toggling
    • Organizing Code
      • Code Style
      • Code Styling Guide
      • Writing Good Comments
      • Version Control
    • Control Algorithms
      • Bang Bang
      • PID Controller
      • Basic Pure Pursuit
      • Flywheel Velocity Control
      • Kalman Filter
      • Take Back Half (TBH) Controller
      • RAMSETE Controller
    • Competition Specific
      • Operator Control
      • Autonomous Control
    • C++ Basics for VEX Robotics
      • Basic Control Flow
      • Enumerations
      • Namespaces (::)
      • Multiple Files (C/C++)
    • VEX Programming Software
      • PROS
        • OkapiLib
      • vexide
      • Robot Mesh Studio (RMS)
      • EasyC
      • RobotC
      • VEXcode
      • Midnight C
    • General
      • Stall Detection
      • Register Programming
      • Sensors and Odometry in Autonomous
      • Embedded Programming Tips
      • Debugging
      • Bit Shift
      • Bit Mask
      • Autoformatting
      • Finite State Machine
      • Data Logging
    • Object Recognition
      • Red Green Buoy
      • AMS
      • OpenCV
      • OpenNI
    • 🤖AI in VRC: Pac-Man Pete
  • ⚡VEX Electronics
    • V5 ESD Protection Board
    • VEX Electronics
      • VEX V5 Brain
        • V5 Electronics Observations and Issues
      • VEX Controller
      • VEXnet and V5 Robot Radio
      • VEX Battery
      • VEX Motors
    • VEX Sensors
      • 3-Pin / ADI Sensors
        • Encoder
        • Potentiometer
        • Limit Switch
        • Bumper Switch
        • Accelerometer
        • Gyroscope
        • Ultrasonic
        • Line Tracker
        • LED Indicator
      • Smart Port Sensors
        • GPS Sensor
        • Rotation Sensor
        • Vision Sensor
        • Optical Sensor
        • Distance Sensor
        • Inertial Sensor (IMU)
        • 3-Wire Expander
    • V5 Brain Wiring Guide
    • Legacy
      • VEX Cortex
      • Power Expander
      • VEX Motor Controller
      • VEX Cortex Wiring Guide
  • General Electronics
    • General Topics
      • External Boards
        • ASUS Tinker Board S
        • Arduino
        • Beagleboard
        • Leaflabs Maple
        • LattePanda
        • Meadow F7 Micro
        • Netduino
        • ODROID-XU4
        • Pandaboard
        • Raspberry Pi
      • Analog-Digital Converter (ADC)
      • Bit-Bang
      • GPIO
      • I2C
      • Jitter
      • Line Noise
      • List of Tools
      • Output Drive
      • Power Consumption
      • Radius Array
      • Resettable Fuse (PTC)
      • SPI
      • Slew Rate
      • Stalling
      • USART
      • UART
      • 5 Volt Tolerant
      • DC Motor Basics
Powered by GitBook
LogoLogo

This work is licensed under a Attribution-ShareAlike 2.0 Generic License

On this page
  • Effects of Problems
  • Inconsistencies reaching and maintaining speeds
  • Programming Solution

Was this helpful?

Edit on GitHub
Export as PDF
  1. Software
  2. Control Algorithms

Flywheel Velocity Control

Methods for getting an accurate and robust velocity output for high speed mechanisms, such as flywheels.

PreviousBasic Pure PursuitNextKalman Filter

Last updated 1 month ago

Was this helpful?

have been a fundamental scoring mechanism throughout the history of VEX. They were dominant in the VRC/VEXU games of Nothing But Net and Turning Point, and are on track to be a powerhouse in the 2022-2023 game Spin Up. However, many teams that build flywheels will run into two common problems:

  1. Flywheels do not consistently reach and maintain their desired speed.

  2. Flywheels lose a lot of speed after firing and take time to get back up to their desired speed.

The purpose of this article is to demonstrate the effects of these problems, explain and write code to help limit the effects of these problems, and demonstrate the impact this code has.

Effects of Problems

As described above, flywheels suffer two major problems. Each problem has its own unique effect on the robot's ability to fire game objects, but they both can have a significant impact on your team's match performance.

Inconsistencies reaching and maintaining speeds

Based on our knowledge of flywheels, we know that their purpose is to efficiently store rotational energy. When a game object comes in contact with the flywheel, the stored rotational energy is transferred to the game object and launched the object forward. The lost energy in the flywheel causes its rotational speed to drop, requiring time in between shots to get back up to speed.

Programming Solution

There are three primary things we want our flywheel control to do:

  1. Accelerate as fast as possible while we are not at the desired speed.

  2. Maintain a close rpm to our desired speed.

  3. Self-correct the flywheel's true speed to minimize error.

We can use a different control algorithm to accomplish each of these goals. Those algorithms are , Feedforward, and , respectively.

Implementation of Bang Bang control for Flywheels

In this case, we will use a Bang Bang controller to accelerate quickly to our target flywheel speed. If our current flywheel's speed is significantly lower than our target speed, we will run the flywheel at max power to accelerate quickly. Similarly, if our current flywheel's speed is significantly faster than our target speed, we will supply no power to the motor so that it slows down quickly.

Example Bang Bang implementation in PROS

pros::Motor flywheel_motor(10); // flywheel in port 10
int threshold = 5;              // range to determine if we should use Bang Bang

void move_rpm(int target_speed) {
    int current_velocity = flywheel_motor.get_actual_velocity(); // get current rpm
    
    if(current_velocity < target_speed - threshold) { // if the flywheel is much too slow
        flywheel_motor.move_voltage(12000); // move at max power
    } else if(current_velocity > target_speed + threshold) { // if the flywheel is much too fast
        flywheel_motor.move_voltage(0); // move at 0 power
    }
}

Example Bang Bang implementation in VEXCode V5 Pro

vex::motor flywheel_motor(10); // flywheel in port 10
int threshold = 5;             // range to determine if we should use Bang Bang

void move_rpm(int target_speed) {
    int current_velocity = flywheel_motor.velocity(velocityUnits::rpm); // get current rpm
    
    if(current_velocity < target_speed - threshold) { // if the flywheel is much too slow
        flywheel_motor.spin(directionType::left, 12000, voltageUnits::mV);
    } else if(current_velocity > target_speed + threshold) { // if the flywheel is much too fast
        flywheel_motor.spin(directionType::left, 0, voltageUnits::);  
    }
}

Implementation of Feedforward control for Flywheels

Once our Bang Bang controller gets us near the desired speed, we need to be able to maintain that speed. Remember, we don't want to use the built-in motor velocity movement commands, as that will cause the Motor's built-in PID to kick in (and stacking multiple controllers is not a good thing in this case). We are going to need to find a way to convert an input rpm into an output voltage. That is where feedforward control comes in.

Feedforward is, put simply, an approximation to convert an input into an output with no sensor information. In this case, our input is the target rpm, and the output is the voltage we send to the motor. We can get an approximate value for this conversion by dividing the max voltage (12000 mV) by the motor's maximum rpm (200), resulting in an approximate constant of 60. This will vary from motor to motor, so it is recommended to output your motor's rpm at max voltage so you can get the best constant for your motor.

Example Feedforward implementation in PROS

pros::Motor flywheel_motor(10); // flywheel in port 10
float kF = 60;                  //conversion constant from rpm to voltage.
void move_rpm(int target_speed) {
    int output_voltage = target_speed * kF; // convert our rpm to voltage
    flywheel_motor.move_voltage(output_voltage);
}

Example Feedforward implementation in VEXCode V5 Pro

vex::motor flywheel_motor(10); // flywheel in port 10
float kF = 60;                 //conversion constant from rpm to voltage.
void move_rpm(int target_speed) {
    int output_voltage = target_speed * kF; // convert our rpm to voltage
    flywheel_motor.spin(directionType::left, output_voltage, voltageUnits::mV);
}

Implementation of PID control for Flywheels

With the Bang Bang and feedforward control, our flywheel is nearly perfect. However, there is a slight problem. The conversion from RPM to voltage is dependent on a long list of factors, including but not limited to friction and temperature. That is where we can leverage PID control to correct the error that feedforward has. In this use, we really only need the Proportional (P) component to get great results. Let's go ahead and combine all 3 controllers into a single function.

Example Bang Bang + Feedforward + P control implementation in PROS

pros::Motor flywheel_motor(10); // flywheel in port 10
int threshold = 5;              // range to determine if we should use Bang Bang
float kF = 60;                  // conversion constant from rpm to voltage.
float kP = 1;                   // how much of an impact the proportion will have on output
void move_rpm(int target_speed) {
    float current_velocity = flywheel_motor.get_actual_velocity(); // get current rpm
    
    if(current_velocity < target_speed - threshold) { // if the flywheel is much too slow
        flywheel_motor.move_voltage(12000); // move at max power
    } else if(current_velocity > target_speed + threshold) { // if the flywheel is much too fast
        flywheel_motor.move_voltage(0); // move at 0 power
    } else {
        float p_component = (target_speed - current_velocity) * kP;
        float f_component = target_speed * kF;
        flywheel_motor.move_voltage(p_component + f_component);
    }
}

Example Bang Bang + Feedforward + P control implementation in VEXCode V5 Pro

vex::motor flywheel_motor(10); // flywheel in port 10
float kF = 60;                 //conversion constant from rpm to voltage.
void move_rpm(int target_speed) {
    float output_voltage = target_speed * kF; // convert our rpm to voltage
    flywheel_motor.spin(directionType::left, output_voltage, voltageUnits::mV);
}
💻
Flywheels
Bang Bang
PID