FlywheelPID Help

Hey I’m having trouble with my flywheel PID
When I press my button to spin the flywheel and look at the input it is receiving a 50 rpm input for the flywheel instead of 330
Any help will be apricated

Hi! Welcome to the Forums! Two things: You’re currently using a PD controller, which is often great for drivetrain functions, because you don’t want them to move once they’re at the target. With something like a flywheel, the input power shouldn’t be zero when you’re at your target speed because the motors would simply stop spinning at that point. With a PD controller, you’re likely to hear the flywheel speed up, then fall back in speed, then speed up again, and continue oscillating until it is going far slower than you initially desired. The integral portion of PID solves this quite nicely. If you’re confused on what the integral portion is or how to implement it (or if my explanations here didn’t make sense) I would suggest checking out MATLAB’s understanding PID control. (It’s the first video in a series, don’t worry about going too deep down the rabbit hole.

I had integral before but it wasnt working for some reason but I added it back and the brain still says 50 rpm for the command

Could you share a snippet of the PID code with the integral in it?

Found it! When updating totalError, you’ll want to use += instead of just =, since you want to keep a running total (which is really all an integral is anyway).

i removed that thinking it was an error:(

Still no luck the brain says this when i view the motor graphs

What are your kp, ki, and kd values tuned to?

Havent tuned them yet but even when i change them around the command always says 50

Could you share all of your code, so we can see how the PID loop was integrated? My current theory is that the loop is only running once for some reason.

Ive had the biggest trouble with integrating it

I added into the while loop and it still doesnt work

I would recommend making it a void function instead of an integer function, then running it somewhere in your while loop in usercontrol. From there, messing with the amount of time you wait between cycles of code and tuning your k values should get you the results you want.

When i try and put the void function in i get an error that says function defenition not allowed here

idk if im just not understanding something but

Could you post your code in its entirety? You’re probably trying to define the PID loop inside of another function.

I just dont know how to run a void function inside of another void function or if thats even possible

Here’s a short example showing where to define and use functions and variables.
There’s also some amount of help to be found at vex’s VEXcode Pro V5 Library.


#include "vex.h"

using namespace vex;

//Define your functions and variables here
float kp = 1;
float ki = .5;
float kd = .1;
float varX;
int varY;
bool boolBoy;
char example;

void imAVoidFunction(){
  varX = 12;

int imAnIntegerFunction(){
  return varY;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  // This is also where usercontrol and auton are instanced
  // You can run functions inside of the main, though for competition code, I'd put code in usercontrol
  // For example, in usercontrol, you can call one of those functions
    varY += imAnIntegerFunction();