help programming problem

Can anyone take a look at our program and teach us what we need to do to make our fly wheel more consistent. We have tried to make two speeds one for preload and one for half court. the pre load is fairly consistent not great about 15 of 24. l
the half court
}

float//---------get speed----------------1
getSpeed()//--------------2
{
float speed = SensorValue[LeftEncoder]/10;
SensorValue[LeftEncoder] = 0;
return speed;
}

void stopFlywheels()
{
motor[RightWheel]=0;
motor[LeftWheel]=0;
}

void runFlywheels()
{
int low=(-70000-12*(8000-nImmediateBatteryLevel))/1000;
int high=(-77000-12*(8000-nImmediateBatteryLevel))/1000;
if(SensorValue[rightEncoder] < -(SensorValue[leftEncoder]))
{
motor[RightWheel] = high;
motor[leftWheel] = low;
SensorValue[RO] = 1;
SensorValue[MO] = 0;
SensorValue[LO] = 0;
}
else if(SensorValue[rightEncoder] > -(SensorValue[leftEncoder]))
{
motor[RightWheel] = low;
motor[leftWheel] = high;
SensorValue[RO] = 0;
SensorValue[MO] = 0;
SensorValue[LO] = 1;
}
else if(SensorValue[rightEncoder] == -(SensorValue[leftEncoder]))
{
motor[RightWheel] = high;
motor[leftWheel] = high;
SensorValue[RO] = 0;
SensorValue[MO] = 1;
SensorValue[LO] = 0;
}
else
{
motor[RightWheel] = 0;
motor[leftWheel] = 0;
SensorValue[RO] = 0;
SensorValue[MO] = 0;
SensorValue[LO] = 0;
}
}
task usercontrol()
{
int X2 = 0, Y1 = 0, X1 = 0, threshold = 15,time=0,speed=0,LCDMode=0,auto=0;
// User control code here, inside the loop
bLCDBacklight=true;
while (true)
{
time++;
wait1Msec(10);
//create deadzone for Y1/Ch3
if(abs(vexRT[Ch3]) > threshold)
Y1 = vexRT[Ch3];
else
Y1 = 0;
//create a llama for X1/Ch4
if(abs(vexRT[Ch4]) > threshold)
X1 = vexRT[Ch4];
else
X1 = 0;
//create deadzone for X2/Ch1
if(abs(vexRT[Ch1]) > threshold)
X2 = vexRT[Ch1];
else
X2 = 0;

	if(vexRT[Btn7D] == 1 )
	{
		//remote control command
		motor[frontRight] = (Y1 - X2	- X1)/3;
		motor[backRight] = (Y1 - X2	+ X1)/3;
		motor[frontLeft] = (Y1 + X2	+ X1)/3;
		motor[backLeft] = (Y1 + X2	- X1)/3;
	}

	else
	{
		//remote control command
		motor[frontRight] = Y1 - X2	- X1;
		motor[backRight] = Y1 - X2	+ X1;
		motor[frontLeft] = Y1 + X2	+ X1;
		motor[backLeft] = Y1 + X2	- X1;
	}
	//*************************************************************************************************************

	//********************************************************************************

	// Arm Control
	if(vexRT[Btn5D] == 1 )
	{
		IntakeDrive(127);
	}
	else
		if(vexRT[Btn6D] == 1 )
	{
		IntakeDrive(-127);
	}
	else
	{
		IntakeDrive(0);
	}

	if(vexRT[Btn6U] == 1 )
	{
		//if battery is affecting the power too much, change the 15 modifier lower
		//if overall shooting too low, change the first number higher && vice versa
//	int low=(-70000-12*(8000-nImmediateBatteryLevel))/1000;
//int high=(-77000-12*(8000-nImmediateBatteryLevel))/1000;
		int low=-(-28-2*(8-nImmediateBatteryLevel));
		int high=-(-30-2*(8-nImmediateBatteryLevel));
		if(SensorValue[rightEncoder] > -(SensorValue[leftEncoder]))
		{
			motor[RightWheel] = high;
			motor[leftWheel] = low;
			SensorValue[RO] = 1;
			SensorValue[MO] = 0;
			SensorValue[LO] = 0;
		}
		if(SensorValue[rightEncoder] < -(SensorValue[leftEncoder]))
		{
			motor[RightWheel] = low;
			motor[leftWheel] = high;
			SensorValue[RO] = 0;
			SensorValue[MO] = 0;
			SensorValue[LO] = 1;
		}
		if(SensorValue[rightEncoder] == -(SensorValue[leftEncoder]))
		{
			motor[RightWheel] = high;
			motor[leftWheel] = high;
			SensorValue[RO] = 0;
			SensorValue[MO] = 1;
			SensorValue[LO] = 0;
		}
	}
	else
		if(vexRT[Btn5U] == 1 )
	{
		runFlywheels();
	}
	else{
		stopFlywheels();
	}
	if(vexRT[Btn8U] == 1 )
	{
		liftDrive(127);
		StabilizerDrive(-50);
	}
	else
		if(vexRT[Btn8D] == 1 )
	{
		liftDrive(-127);
		StabilizerDrive(-50);
	}
	else
	{
		liftDrive(0);
		StabilizerDrive(0);
	}
	if(vexRT(Btn7D)==1){//btn7d is auto on
		auto=1;
	}
	if(vexRT(Btn7U)==1){//btn7u is auto off
		auto=0;
	}
	if(auto==1){
		runFlywheels();
		if(time%25==0){
			speed=getSpeed();
		}
		if(speed>300){//change the 300 higher if shooting too early, lower if not early enouhg
			IntakeDrive(127);
		}
		else{
			intakeDrive(0);
		}
	}
	clearLCDLine(0);//LCD logic and nonsense
	if(nLCDButtons==1){
		LCDMode=0;
	}
	if(nLCDButtons==2){
		LCDMode=1;
	}
	if(LCDMode==0){
		displayLCDNumber(0,0,SensorValue[LeftEncoder]);
	}
	else{
		displayLCDNumber(0,0,nImmediateBatteryLevel/1000);
	}
	if(time%25==0){
		time=0;
		clearLCDLine(1);
		speed=getSpeed();
		displayLCDNumber(1,0,speed);//calculates and displays speed
	}

OK, so from what I see here, it looks like you’ve implemented a very primitive form of velocity control based on the current battery level:

To improve accuracy (and/or speed at which you make shots), you probably need to implement a more sophisticated method of velocity control. If you’re curious, the 3 main options you have are bang-bang, take-back-half (or just TBH), and PID controllers - lots of people on the forums have given helpful advice about each of these in the past.

For you, I’d recommend starting out with take-back-half (at least for the short-term). It helped us get a very competitive flywheel at our first competition in a span of a few days. (I’d recommend jpearman’s TBH controller for this, which is explained in this thread). If you have two flywheels, you’ll need to use this twice and then change the global variables that end up being duplicates so that there is one for each side (add an l_ or r_ prefix to distinguish between the left and right sides, for example).

PID will work much better than TBH (in theory), but you’ll have to spend a lot more time tuning it to your specific flywheel than you will with TBH. It’s also more complicated than TBH.

Evan10 thank you for your help doesn’t the tbh code use ime? We are using the red shaft encoders would that work also? where would we insert that code into ours

You can use either with it. In the TBH code, find the FwEncoderGet function (around line 110) and then return the value of the shaft encoder using SensorValue. Make sure that the shaft encoder goes up (i.e., in the positive direction) when the motors spin the flywheels so that your RPM calculations are correct.