Flywheel Velocity Control
Methods for getting an accurate and robust velocity output for high speed mechanisms, such as flywheels.
Last updated
Was this helpful?
Was this helpful?
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
}
}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::);
}
}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);
}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);
}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);
}
}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);
}