Tronbike Meter (TBM) 4.0.0 Test Ride

Wednesday, October 19, 2011

Technical Extinction - My Ode to Lego Mindstorms I, torbot.nqc

The kids finally have reached an age where Lego Mindstorms might impress and teach. I took out my well preserved set, found the included 1998 CDROM useless, went to the archive of all things, the Internet.

Or so I thought. I barely found documentation on "NQC" - not quite C, the replacement/enhancement for Mindstorms - dated 2000. A full 90% of the links
were "dead", links to code, ideas, work, everything. The "LugNet" main site had some ancient forum Q&A, but nothing on the simple code to make my Lego "torbot" run. Even Lego corp itself had no links on the Original Mindstorm, something I assumed to be an iconic product that could never go away.

Anyway, I will hereby post code to run "The Torbot" and hope it may survive for others to use, copy, and learn from. I included a sniffing routing to use the IR eyeball/give the bot some motivation.

// torbot.nqc - run that lego mindstorm 1 torbot please
//
// T.Stiers 20111019
//
// copyright tronbikes.com 2011
//
sub forward() {
   OnRev(OUT_C);
   OnFwd(OUT_A);
}

sub backward() {
   OnFwd(OUT_C);
   OnRev(OUT_A);
}

sub right() {
   OnFwd(OUT_A);
}

sub left() {
   OnRev(OUT_C);
}

sub backright() {
   OnFwd(OUT_C);
}

sub backleft() {
   OnRev(OUT_A);
}



sub whoa() {
   Off(OUT_A+OUT_C);
}
task sniff() {
   PlaySound(1); Wait(100);
   while( true ) {
        if ( SENSOR_2 < 700 ) {
                forward(); Wait(25); 
                whoa(); Wait(25);
        }
        if ( SENSOR_2 < 700) {
                right(); Wait(25);
                whoa(); Wait(25);
        }
        if ( SENSOR_2 < 700 ) {
                forward(); Wait(25);
                whoa(); Wait(25);
        }
        if ( SENSOR_2 < 700) {
                left(); Wait(25);
                whoa(); Wait(25);
        }
   }
}



task main()
{
  SelectDisplay(DISPLAY_SENSOR_2);
  SetSensor(SENSOR_1,SENSOR_TOUCH);
  SetSensor(SENSOR_3,SENSOR_TOUCH);
  start sniff;
  while (true)
  {

    if ( SENSOR_1 == 1 || SENSOR_3 == 1 ) {
        stop sniff;
        PlaySound(4);Wait(5);
        // backward(); Wait(25); whoa();
        if ( SENSOR_1 == 1 ) {
                backleft(); Wait(150); whoa();
        }
        if ( SENSOR_3 == 1 ) {
                backright(); Wait(150); whoa();
        }
        if ( SENSOR_1 == 1 && SENSOR_3 == 1 ) {
                backward(); Wait(50); whoa();
        }

        if (SENSOR_1 == 0 || SENSOR_3 == 0 ) {
                start sniff;
        }
    }

  }
}

0 comments: