Confused about PID Loop

I am one person middle school team I have a dual wheel flywheel with two speed motors that does ok.   I heard we could get more consistant if we used a pid loop. I use Robot C.  I have read all posts on how to write one but I don't really understand it. The examples of code seam way to involved.  Is there a simpler way.  We would like to make sure that both sides of the flywheel are going at the same speed and stay at the speed regardless of battery level.

I had a similar issue at the start of this year, I had never done anything other than wait1Msec and Motor Power. I also had no one to show me how to code.
I created this code after some research and used it to learn PID, although technically its just an "I"control.

#pragma config(Motor,  port5,           IntakeMotor,   tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port2,           FlyM1,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port3,           frontRightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           backRightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port7,           backLeftMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port8,           frontLeftMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port9,           FlyM2,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port10,          TurretMotor,   tmotorServoContinuousRotation, openLoop)
#pragma config(Sensor, dgtl1,  Rotationsensor, sensorQuadEncoder)

int target; // The target velocity 
int integrator; // The integrater 
int Sensor_last; // The last sensor reading 
int Sensor_Currant; // The current sensor reading 
int Velocity_Currant; // The current velocity
int Velocity_Error;  // The diffence between the currant velocity and the target velocity.
int Motor_Out;       // the final power value given to the motors
float KI = 0.0;            // Change this value to get a faster or slower recovery time, adust it by 0.05 at a time 

task Flywheel_System(){

while(true)

while(1){ //Loop starts



	//This code creates the current velocity using the sensor value
	Sensor_Currant = SensorValue[Rotationsensor]; //Make "Sensor_Current" the value of the sensor,if the sensor is backwards, reverse this value
	Velocity_Currant = Sensor_Currant - Sensor_last; //Make "Velocity_Current" the difference bettween the current sensor readingand the last sensor reading
	Sensor_last = Sensor_Currant; //This gives us the last sensor reading, which will change at speed due to the 25 Millisecond wait at the end of the task 

	//Error Calculation
	Velocity_Error = target - Velocity_Currant; //Set the error as the difference between the target and the actual velocity

	//Add to the integrator
	integrator += (Velocity_Error * KI); //This will add to or subtract from, the integrator using the error multiplied by the constant every time the loop runs, 

	//Cap the Integrator at 0 & 127
	if (integrator > 127){ integrator = 127;} //Do not let the integrator go past 127
	if (integrator < 0){integrator = 0;} //Do not let the motors run backwards

	//Set integrator to motors
	Motor_Out = integrator;
	motor[FlyM1] = Motor_Out;
	motor[FlyM2] = Motor_Out;

	wait1Msec(25);
}//ends loop


}

//Task starts
task main()
{
	while (true)
	{
startTask(Flywheel_System);//Start the Velocity Control task
while(1 == 1)
{
	//Flywheel control code, sets target to adjust firing distance, values set for testing
	      if( vexRT Btn7L ] == 1 )
            target = 65;
        if( vexRT Btn7D ] == 1 )
            target = 60;
        if( vexRT Btn7R ] == 1 )
            target = 55;
        if( vexRT Btn7U ] == 1 )
            target = 50;//Lowest
        if( vexRT Btn8U ] == 1 )
            target = 0;//Off
        if( vexRT Btn8R ] == 1 )
            target = 80;//Highest
}
wait1Msec(10); 
}
}//end of task main

It’s far from perfect, but it worked really well, and I annotated it as I was creating is so I could better understand it. I think you could write something like this, and then copy and paste it with new variables so you had two versions, one for each flywheel. But with the same target.
This is the simplest velocity control code I’m aware of, but it does all the things you want it to do.
I use a full PID now and it allows for better speed adjustments while doing field driving.
If you haven’t seen this Introduction to PID Control , then I would suggest doing so. Its really usefull.

Pressed Enter after typing one letter :stuck_out_tongue:

Can I recommend taking a look at post 3 of this thread:
https://vexforum.com/t/what-exactly-is-velocity-control/31863/1

It contains some really helpful videos on the basics of PID, how it works and why we use it.