Unexpected "File Error!"
Posted: 03 Jul 2011, 18:16
Hi everyone,
I'm working on a simple arm with two rotational degrees of freedom(it only acts in 2d). The idea is to place a pen at the tip and draw simple things with it. I'm having some trouble because the program compiles well but when I execute it in the brick I immediately get "File Error!" and the program ends. Here you have the code(in NXC) it isnot the final one(I want to add mor functionalities) but I don't know why it doesn't work.
If you have any idea on how to solve that please tell me.
Thanks.
I'm working on a simple arm with two rotational degrees of freedom(it only acts in 2d). The idea is to place a pen at the tip and draw simple things with it. I'm having some trouble because the program compiles well but when I execute it in the brick I immediately get "File Error!" and the program ends. Here you have the code(in NXC) it isnot the final one(I want to add mor functionalities) but I don't know why it doesn't work.
Code: Select all
float calculateAngle (float posX, float posY){
//Define the lenghts of the arm links
float L1 = 18;
float L2 = 18;
//Calculate the cosine of the first angle
float cos2 = ((posX * posX) + (posY * posY) - (L1 * L1) - (L2 * L2)) / (2 * L1 * L2);
//Check if the piont is reachable
if (cos2 >= -1.0 && cos2 <= 1){
//Calculate both angles in rads
float radsAngle2 = Acos(cos2);
float sin2 = Sin(radsAngle2);
float radsAngle1 = (-(L2 * sin2 * posX) + ((L1 + (L2 * cos2)) * posY))/((L2 * sin2 * posY) + ((L1 + (L2 * cos2)) * posX));
//Convert angles into degrees
float degsAngle1 = radsAngle1 * (180/PI);
float degsAngle2 = radsAngle2 * (180/PI);
//Return both values
float Angles[];
Angles[0] = degsAngle1;
Angles[1] = degsAngle2;
return Angles;
} else {
TextOut(0,LCD_LINE3, "Point not reachable");
}
}
void drawPoint(float X, float Y){
//Define arrays
float targetJointAng[];
float currentMotorAng [];
float currentJointAng[];
float movementJointAng[];
float movementMotorAng[];
targetJointAng = calculateAngle(X,Y);
//Get the rotation counts of the motors
currentMotorAng[0] = MotorRotationCount(OUT_A);
currentMotorAng[1] = MotorRotationCount(OUT_B);
//Multiply the rotation counts by the gear ratio
currentJointAng[0] = currentMotorAng[0] * 18.667;
currentJointAng[1] = currentMotorAng[1] * 18.667;
//Subtract target and current joint angle
movementJointAng[0] = targetJointAng[0] - currentJointAng[0];
movementMotorAng[0] = movementJointAng[0]/ 18.667;
movementJointAng[1] = targetJointAng[1] - currentJointAng[1];
movementMotorAng[1] = movementJointAng[1]/ 18.667;
//Rotate both motors
RotateMotor(OUT_A ,40,movementMotorAng[0]);
RotateMotor(OUT_B ,40,movementMotorAng[1]);
}
task main (){
float Ax = 6;
float Ay = 10;
ResetRotationCount(OUT_ABC);
drawPoint(Ax,Ay);
Wait(30000);
}
Thanks.