Hi! I’ve been trying to use a Vex iq robot to test a PID loop, but every time I try to run the program, it shows “… exceeded time limit of 3 seconds” on the screen. I’ve read all of the topics regarding this error, but none of the solutions seem to work for me. This is the code:
#include "iq_cpp.h"
// Allows for easier use of the VEX Library
using namespace vex;
float Rerror;
float Lerror;
float error;
float prevRerror;
float prevLerror;
float totalRerror;
float totalLerror;
float Rderivative;
float Lderivative;
float Loltage;
float Roltage;
float kP = 0.7;
float kI = 0.8;
float kD = 0.9;
void drivefwdPID(int dist)
{
Rdrive.setPosition(0,degrees);
Ldrive.setPosition(0,degrees);
while(true)
{
Rerror = dist - Rdrive.position(degrees);
Lerror = dist - Ldrive.position(degrees);
error = (Rerror+Lerror)/2;
Rderivative = Rerror - prevRerror;
Lderivative = Lerror - prevLerror;
totalRerror += Rerror;
totalLerror += Lerror;
Roltage = Rerror*kP + Rderivative*kD + totalRerror*kI;
Loltage = Lerror*kP + Lderivative*kD + totalLerror*kI;
Rdrive.spin(forward,Roltage,volt);
Ldrive.spin(forward,Loltage,volt);
if(error == 0)
{
break;
}
}
vex::task::sleep(100);
}
int main() {
// Begin project code
drivefwdPID(3000);
}