Recently I programmed a PID controller in RobotC for a two turbo motor single flywheel launcher. While the PID itself has increased its spin-up rate, it has had a few kinks. The main two problems with the PID is that it is not taking the kp ki and kd into affect and is instead using a value other than the ones I have set, along with that it is also not using the target Rpm that I set for it instead it is using a value that I cannot see. Here is my code if anyone has a few suggestions on how I could fix these problems they would be greatly appreciated.
// in pre auton
void launcher(int speed){ // Function for apply the determined speed
motor[launch1] = speed;
motor[launch2] = speed;
}
float velocity;
task VelocityMeasure //My velocity measure task runs constantly
{
float prevelocity1;
float msvelocity;
SensorValue[ncoder] = 0;
wait1Msec(100);
prevelocity1 = SensorValue[ncoder];
wait1Msec(100);
msvelocity = (SensorValue[ncoder] - prevelocity1)/200;
velocity = msvelocity*60000;
}
float target; //target Rpm
task PIDlauncherControl() // The PID task
{
float Kp = 1;
float Ki = 1;
float Kd = 1;
int error;
int proportion;
int integralRaw;
float integral;
int lastError;
int derivative;
float integralPowerLimit = 100; //The integral limit
int finalpower;
while(true){
error = target-velocity;
proportion = Kp*error;
if(error != 0){
integralRaw = integralRaw + error;
}
else
integralRaw = 0;
if(integralRaw>integralPowerLimit)
integralRaw = integralPowerLimit;
if(integralRaw< -integralPowerLimit)
integralRaw = - integralPowerLimit;
integral = Ki * integralRaw;
derivative = Kd*(error - lastError);
lastError = error;
finalpower =+ proportion + integral+derivative;
launcher(finalpower);
wait1Msec(200);
}
}
// the rest is in user control
startTask(VelocityMeasure);
if(vexRT[Btn8D] == 1){
stopTask(PIDlauncherControl);
motor[launch1] = 0;
motor[launch2] = 0;
}
if(vexRT[Btn8R] == 1){
target = 100;
startTask(PIDlauncherControl);
}