Hello Vex Community!
In my program, I have an array that is created, and its components are defined by any change in events by the motors (at which its defined to the value of motorGet()) The array is created, and defined correctly, as I can see in the for loop within my code with the printer values (to the LCD) of the motorvalues. However, when exporting the text file created, an array out of bounds error is received in PROS. Is it because fprintf is not made to output to a *FILE stream (it does not mention it in the API.H, so that’s probably the problem).
Thus, what method would be most optimal for a human to read? (I plan to later implement code to read from the file, and reconstruct the same array).
*Note, in the code, I may have included an extra bracket. Not actually included in the program. woops
**If anyone needs the actual file, I am happy to provide. The spacing seems to be really jacked up in the
, though that's *partially* my fault.
[CODE]
void operatorcontrol (){
//do stuff, array initialization.
int c = 20;
int x; int y;
long int starttime = millis();
int i = 20; // amount of ticks for recording autonomous
int k = 5;// k is the amount of motors
int Times*;
Times[1] = starttime;
long int rMotor*[k];
int a = 1;
rMotor[1][1] = motorGet(1); //StrafeWheel
rMotor[1][2] = motorGet(2); //Left Side of Drive
rMotor[1][3] = motorGet(3); // Right Side of Drive
rMotor[1][4] = motorGet(6); // Left Arm
rMotor[1][5] = motorGet(7); // Right Arm
while(1){
//opcontrol functions, and array definitions(event based)
if(a == i){
x = 0; y =0;
motorStopAll();
lcdClear(uart1);
lcdSetBacklight(uart1, true);
FILE *rMot;// = "rMot";
//FILE *Timings;// = "Timings";
lcdPrint(uart1, 1, "FIN %d", a);
//fopen("Mot_ArmR", "w");
//fopen("rMot", "w");
//fopen("Timings", "w");
rMot = fopen("rMot", "w");
//Timings = fopen("Timings", "w");
int ca;
for(ca = 1; ca < 20; ca++){
delay(2000);
lcdClear(uart1);
lcdPrint(uart1, 2, "%d , %ld", ca, rMotor[1][ca]);
//lcdPrint(uart1, 2, "%d , %ld", ca, rMotor[1][ca]);
fprintf(rMot, "%ld , \n", rMotor[1][ca]);
if(ca == i){
lcdPrint(uart1, 2, "%d , %ld", ca, rMotor[1][ca]);
fclose(rMot);
delay(100);
break;
}
}break;
//fwrite(rMotor, sizeof(long int), i*k, rMot);
//fclose(Timings);
}
else{
lcdPrint(uart1, 1, "aVal rM %d", a);
lcdPrint(uart1, 2, "Init[1][1] %ld", rMotor[1][3]);
}
if(abs(motorGet(1) - rMotor[a][1] > c) || abs(motorGet(3) - rMotor[a][2]) > c ||
abs(motorGet(5) - rMotor[a][3]) > c || abs(motorGet(6) - rMotor[a][4]) > c ||
(abs(motorGet(7) - rMotor[a][5]) > c))
{
if(a != 20){
rMotor[a+1][1] = motorGet(1); //StrafeWheel
rMotor[a+1][2] = motorGet(2); //Left Side of Drive
rMotor[a+1][3] = motorGet(3); // Right Side of Drive
rMotor[a+1][4] = motorGet(6); // Left Arm
rMotor[a+1][5] = motorGet(7); // Right Arm
lcdSetBacklight(uart1, true);
Times[a+1] = millis() - starttime;
delay(100);
a++;
}
}
else{
lcdSetBacklight(uart1, false);
}
}
}
[/CODE]
**