I have created a function that calculates the I part of PID and then outputs the data to the console to create a graph and analyze different constants (Ki). This is a side project while we wait on build to finish what they are working on. The integral function works, but when I add it to our Sample Robot, it fails for multiple reasons: I get the error below when running the test code, and The output does not go to the console unless I go into teleop mode.
Why is the output delayed and why did this error occur? Any easier ways to output data? File I/O does not work. I have tried using cout and printf, and both have this problem. Usually cout works better
FRC: Robot radio detection times. Error on line 238 CTRE CAN Transmit Error
at /home/lvuser/FRCUserProgram() [0x1fcc4]
at /home/lvuser/FRCUserProgram() [0x27904]
at /home/lvuser/FRCUserProgram() [0x87210]
at /home/lvuser/FRCUserProgram() [0x898f0]
at /home/lvuser/FRCUserProgram() [0x9a3cc]
at /home/lvuser/FRCUserProgram() [0x9499c]
at /home/lvuser/FRCUserProgram() [0xc0804]
at /opt/GenICam_v2_3/bin/Linux_armv7-a/libstdc++.so.6(+0xa2cb0) [0xb6af1cb0]
double integral(double angle, double x)
{
double result = 0;
int n = 1;
result += gyros[0];
if(x > 0.1)
{
for(double i = 1; i <= x * 10; i += 1)
{
result += 2*gyros*;
n++;
}
}
result += angle;
result *= x/(2*n);
std::cout << result << '
';
return result;
}
void Test() override
{
for(int x = 0; x < 10000; x++)
{
double angle = gyro->GetAngle();
myRobot->Drive(0.15, -Kp*angle );
gyros.push_back(angle);
std::cout << x << ' ' << Kp*integral(angle, x) << ',';
printf("%d %e,", x, Ki*integral(angle, x));
Wait(0.01);
}
myRobot->SetLeftRightMotorOutputs(0.0, 0.0);
}