Unexpected "File Error!"

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
jfons1
Posts: 3
Joined: 03 Jul 2011, 18:11

Unexpected "File Error!"

Post by jfons1 »

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.

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);
}
If you have any idea on how to solve that please tell me.

Thanks.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Unexpected "File Error!"

Post by HaWe »

I don't know it there are more issues, but you can't return angles because you can't return more-dim arrays

Code: Select all

   
Angles[0] = degsAngle1;
Angles[1] = degsAngle2;

return Angles;
what file error do you get? (number?)
jfons1
Posts: 3
Joined: 03 Jul 2011, 18:11

Re: Unexpected "File Error!"

Post by jfons1 »

doc-helmut wrote:I don't know it there are more issues, but you can't return angles because you can't return more-dim arrays

Code: Select all

   
Angles[0] = degsAngle1;
Angles[1] = degsAngle2;

return Angles;
what file error do you get? (number?)
The error I get is not in the compiling, I jut get a "File Error!" text in the NXT display when I try to run the program.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Unexpected "File Error!"

Post by HaWe »

you need not quote my post comletely for answering. Just answer ("post reply"), not "quote".

can you upload the enhanced firmware and target it in your BCC? the you'll get fw error numbers like

Code: Select all

    //Fatal errors

    #define ERR_ARG      -1
    #define ERR_INSTR    -2
    #define ERR_FILE     -3
    #define ERR_VER      -4
    #define ERR_MEM      -5
    #define ERR_BAD_PTR  -6

    //General errors

    #define ERR_INVALID_PORT   -16
    #define ERR_INVALID_FIELD  -17
    #define ERR_INVALID_QUEUE  -18
    #define ERR_INVALID_SIZE   -19
    #define ERR_NO_PROG        -20

    //Communications specific errors

    #define ERR_COMM_CHAN_NOT_READY -32
    #define ERR_COMM_CHAN_INVALID   -33
    #define ERR_COMM_BUFFER_FULL    -34
    #define ERR_COMM_BUS_ERR        -35

    //Remote control (direct commands) errors

    #define ERR_RC_ILLEGAL_VAL -64
    #define ERR_RC_BAD_PACKET  -65
    #define ERR_RC_UNKNOWN_CMD -66
    #define ERR_RC_FAILED      -67
in most cases (to my experience) runtime errors occur when devide by zero
(e.g.: can THIS become zero:
/((L2 * sin2 * posY) + ((L1 + (L2 * cos2)) * posX)

or when accessing arrays on undifined ranges (array[-1], array[lenght+1] a.s.o.). Lets see what error msg you get.
Last edited by HaWe on 03 Jul 2011, 20:37, edited 1 time in total.
jfons1
Posts: 3
Joined: 03 Jul 2011, 18:11

Re: Unexpected "File Error!"

Post by jfons1 »

I don't know how to upload and target the enhanced firmware in BCC(I understand is Bricx CC). Could you please explain a little bit more?

PS. Sorry for the quote thing.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Unexpected "File Error!"

Post by HaWe »

what Bricxccc (BCC) version do you have?

if you're not sure, look here - and install new!
https://sourceforge.net/apps/phpbb/mind ... p?f=3&t=49
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Unexpected "File Error!"

Post by afanofosc »

The compiler should complain but doesn't that you are trying to return an array of float in a function that is declared to return a float. NXC does not currently support returning array types and it does not do a very good job of telling you that you are doing something wrong when you try to do that.

It looks like you are targeting the standard firmware. I would recommend switching to the enhanced NBC/NXC firmware. If you do that then use asin and acos rather than ASin and ACos which are deprecated.

When you declare an array you either have to give it a size (float Angles[2]) or you have to initialize it at the declaration (float Angles[] = {PI, PI/2}).

If you try to write to elements 0 and 1 of an array that has zero elements in it (since you did neither of the above) then you will get a File Error abort when you run the program.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests