2

I am getting a file error when I try to run this on my NXT 2.0. It's my first time using NXC and the program compiles and transfers fine...

I tried replacing the batteries, the only other thing is that I thought maybe there was a firmware problem. Only thing is, I'd rather not get a custom firmware if I don't have to.

/**
 * Tripod walker
 *
 * Description:  This the Tripod program, to make it walk, turn, and avoid obstacles
 *
 * Notes: Compile for 2.0 NXT firmware (1.028)
 *
 * @author Daniele Benedettelli, MCP http://robotics.benedettelli.com, Copyright (C) 2012.
 *
 * @see The GNU Public License (GPL)
 */

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#define STEP_PAUSE 80

#define LEFT_LEG OUT_C
#define REAR_LEG OUT_B
#define RIGHT_LEG OUT_A
#define EYE IN_4

#define NEAR 25
#define NONE -1
#define LEFT 1
#define RIGHT 2
#define FRONT 3
#define BACK 4

#define CW 1
#define CCW 0

#define KP 30
#define KD 10
#define KI 0
#define DAMP 60
#define SCALE 5

#define MID 60

int ref[3];


void Set(byte rear, byte left, byte right)
{
   ref[REAR_LEG] = rear;
   ref[LEFT_LEG] = left;
   ref[RIGHT_LEG] = right;
}

void Pulse(byte motor, int times, bool long_pulse)
{
   repeat (times)
   {
      ref[motor] = MID+10;
      Wait(80);
      //Wait(70+long_pulse*30);
      ref[motor] = MID-10;
      Wait(80);
   }
}

void PulseDouble(byte motor_one, byte motor_two, int times, bool long_pulse)
{
   repeat (times)
   {
      ref[motor_one] = 80;
      ref[motor_two] = 80;
      Wait(50+long_pulse*40);
      ref[motor_one] = 40;
      ref[motor_two] = 40;
   }
}

void Walk (int dir, int times)
{
   repeat(times)
   {
      if (dir == FRONT)
      {
         Set(MID-20,MID,MID);
         Wait(300);
         Set(MID+10,MID,MID);
         Wait(200);
      }
      else if (dir == BACK)
      {
         Set(MID-10,MID+20,MID+20);
         Wait(150);
         Set(MID-10,MID-10,MID-10);
         Wait(300);
      }
      else if (dir == RIGHT)
      {
         Set(MID-10,MID-20,MID-10);
         Wait(80);
         Set(MID+10,MID-20,MID+10);
         Wait(150);
         Set(MID-10,MID-20,MID-10);
         Wait(300);
      }
      else if (dir == LEFT)
      {
         Set(MID-10,MID-10,MID-20);
         Wait(80);
         Set(MID+10,MID+10,MID-20);
         Wait(150);
         Set(MID-10,MID-10,MID-20);
         Wait(300);
      }
//      if (times>1)  Wait(STEP_PAUSE);
   }
}

void Turn(int wise, int times)
{
   repeat (times)
   {
      ref[REAR_LEG] = MID-10;
      ref[wise==CCW? RIGHT_LEG:LEFT_LEG] = MID+10;
      Wait(100);
      ref[wise==CCW? LEFT_LEG:RIGHT_LEG] = MID+10;
      ref[wise==CCW? RIGHT_LEG:LEFT_LEG] = MID-10;
      Wait(100);
      ref[wise==CCW? LEFT_LEG:RIGHT_LEG] = MID-10;
      ref[REAR_LEG] = MID+10;
      Wait(100);
//      Pulse( wise==CCW? REAR_LEG:LEFT_LEG, 1, false);
//      Pulse(RIGHT_LEG,1,false);
//      Pulse( wise==CCW? LEFT_LEG:REAR_LEG,1,false);
   }
}

void Demo()
{
   Walk(FRONT,10);
   Turn(CCW,10);
   Walk(FRONT,10);
   Turn(CW,10);
   Walk(FRONT,10);
   Walk(LEFT,10);
   Walk(RIGHT,10);
}


task motorAcontroller()
{
   int err, P, I, D, PID, Apos, Aold;
   ResetAllTachoCounts(OUT_A);
   ResetRotationCount(OUT_A);
   while(true)
   {
      Apos = MotorRotationCount(OUT_A);
      err = Apos - ref[OUT_A];
      P = KP*err;
      I = err + KI*I*(100-DAMP)/100;
      D = KD*(err-Aold);
      PID = (P + I + D)/SCALE;
      PID = abs(PID)>100? sign(PID)*100 : PID;
      OnRev(OUT_A,PID);
      Aold = err;
   }
}

task motorBcontroller()
{
   int err, P, I, D, PID, Bpos, Bold;
   ResetAllTachoCounts(OUT_B);
   ResetRotationCount(OUT_B);
   while(true)
   {
      Bpos = MotorRotationCount(OUT_B);
      err = Bpos - ref[OUT_B];
      P = KP*err;
      I = err + KI*I*(100-DAMP)/100;
      D = KD*(err-Bold);
      PID = (P + I + D)/SCALE;
      PID = abs(PID)>100? sign(PID)*100 : PID;
      OnRev(OUT_B,PID);
      Bold = err;
   }
}

task motorCcontroller()
{
   int err, P, I, D, PID, Cpos, Cold;
   ResetAllTachoCounts(OUT_C);
   ResetRotationCount(OUT_C);
   while(true)
   {
      Cpos = MotorRotationCount(OUT_C);
      err = Cpos - ref[OUT_C];
      P = KP*err;
      I = err + KI*I*(100-DAMP)/100;
      D = KD*(err-Cold);
      PID = (P + I + D)/SCALE;
      PID = abs(PID)>100? sign(PID)*100 : PID;
      OnRev(OUT_C,PID);
      Cold = err;
   }
}

void triped_init()
{
   //SetSensorLowspeed(LEFT_EYE);
   //SetSensorLowspeed(RIGHT_EYE);
   SetSensorLowspeed(EYE);
   OnRev(OUT_ABC,20);
   Wait(80);
   Float(OUT_ABC);
   Wait(500);
   start motorAcontroller;
   start motorBcontroller;
   start motorCcontroller;
   //Set(MID+40,MID+40,MID+40);
   //Wait(1000);
   Set(MID,MID,MID);
   Wait(1000);
   /*
   repeat(3)
   {
      Set(MID,MID+20,MID+20);
      Wait(200);
      Set(MID+20,MID+20,MID);
      Wait(200);
      Set(MID+20,MID,MID+20);
      Wait(600);
   }
   Set(MID,MID,MID);
   */
}

void Jump( int times )
{
   repeat (times)
   {
      Set(90,90,90);
      Wait(1000);
      for (int i=90; i >=30; i--)
      {
         Set(i,i,i);
         Wait(1);
      }
      Wait(1000);
   }
}

task main()
{
   int count;
   triped_init();
   while (true)
   {
      if (ButtonPressed(BTNCENTER,true))
      {
         Set(MID+50,MID+50,MID+50);
         while(ButtonPressed(BTNCENTER,true));
         until(ButtonPressed(BTNCENTER,true));
      }
      if (SensorUS(EYE)>NEAR)
      {
         Walk(FRONT,1);
      }
      else
      {
         Walk(BACK,3);
         count = 0;
         while(SensorUS(EYE)<=NEAR && count<20)
         {
            Turn(CCW,3);
            count++;
         }
         if (SensorUS(EYE)<=NEAR)
         {
            count = 0;
            while(SensorUS(EYE)<NEAR && count<20)
            {
               Turn(CW,3);
               count++;
            }
            Walk(LEFT,4);
         }
         else
         {
            Walk(RIGHT,4);
         }
         //Turn(CCW,5);
      }
   }
}

the error

the error

  • You might want to share the exact error you get, and what you are doing when you get this error. – user3971 Nov 8 '15 at 22:37
  • @jdv "File error" on the NXT, literally... here, take a look - imgur.com/kzjuc0N – Timtech Nov 9 '15 at 0:25
  • This might be the size of the memory in use at runtime. Does a super simple "turn a motor, beep, turn the motor" test program work? Is this the only program on the brick? – user3971 Nov 9 '15 at 1:43
  • @jdv It could be a memory error, because I've got a bunch of other stuff on there. I'll check a simple program later. – Timtech Nov 9 '15 at 11:44
  • Scratch the possible memory problem. I deleted huge amount of stuff, and the error is still exactly the same. – Timtech Nov 9 '15 at 11:47
2

I got this to work. Set the optimisation level to 1 on the NBC/NXC tab of the compilation options. Then recompile and download.

enter image description here

1

I had the exact same problem when I built the tripod. This program is written in BrickCC, instead of the standard NXT-G. The way to solve this is to download and install the compiler for brickCC, which can be found by browsing the tripod section on robotsquare here.

Sources: robotsquare.com

  • 1
    Umm, I used BricxCC 3.3.8.9 to compile and transfer the program. – Timtech Nov 9 '15 at 11:43
  • Oh. Ok. Um. I haven't got anything else. – Kilian Seifert Leitch Nov 10 '15 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.