To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.spyboticsOpen lugnet.robotics.spybotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Spybotics / 421
420  |  422
Subject: 
Re: Spybot built-in program
Newsgroups: 
lugnet.robotics.spybotics
Date: 
Mon, 14 Nov 2005 16:28:23 GMT
Viewed: 
13266 times
  
In lugnet.robotics.spybotics, John Hansen wrote:
It is possible if you are really clever to write an
NQC program which cooperates with the built-in ROM tasks and subroutines.

I spent some time recently working on NQC headers which would enable using more
(if not all) of the Spybot ROM subroutines and tasks with a NQC program.  I
haven't done extensive testing of the headers in real programs.  I hope there
are still a few Spybot users out there who might be willing to test them a bit
more than I have.  There are 4 header files:

SpyGlobals.nqh
SpyInteraction.nqh
SpyBeads.nqh
SpyEvents.nqh

SpyGlobals.nqh includes SpyInteraction.nqh and SpyBeads.nqh.  The header files
make use of the NQC preprocessor quite a bit to make sure that global variables
are correctly reserved and defined.  The SpyEvents header file also hooks up a
special spybot event initialization routine.  You can get these headers at
http://bricxcc.sourceforge.net/spynqh.zip.  If you test them please let me know
if you run into any problems.

I also have a port of the Mindscript code for the Task 0 program in ROM to NQC
in the file builtin.nqc.  Here it is:

#include "SpyGlobals.nqh"
#include "SpyEvents.nqh"

#define right 0 // output 1
#define left 1 // output 2

#define cAdvance 1
#define cRetreat 2

//int nMode;
#pragma reserve 9
#define nMode (@9)

task main()
{
  // initialize our global variable
  nMode = cAdvance;

  SetPriority(2);

  ResetMotors();
  ResetEngine();

  nStatus |= EVENT_RUNBEADS;

  SetAnimation(ANIMATION_SCAN);

  repeat(2)
  {
    PlayTone(2232, 10); Wait(20);
    PlayTone(1736, 10); Wait(20);
    PlayTone(1202, 10); Wait(35);

    PlayTone(1202, 10); Wait(20);
    PlayTone(1736, 10); Wait(20);
    PlayTone(2232, 10); Wait(35);
  }

  SetLED(LED_MODE_ON, 0);

  ResetMessages();

  start MyPostWatcher;
//  StartTask(cBuiltInPostWatcher);
  start MyBumpWatcher;
//  StartTask(cBuiltInBumpWatcher);

  while(true)
  {
    SelectTarget();

    if (Target(SPY_RANGE) > RANGE_ANYWHERE)
    {
      if (nMode == cAdvance)
      {
        if (Target(SPY_RANGE) == RANGE_THERE)
          PlaySound(SOUND_MAGNET);
        Advance_Bead(RANGE_HERE, 100);
      }
      else
      {
        if (Target(SPY_RANGE) == RANGE_HERE)
          PlaySound(SOUND_REPULSE);
        Retreat_Bead(RANGE_HERE, 100);
      }
    }
    else
    {
      BasicMovement_Bead(MOVE_BASIC_SPIN_LEFT, 50);
      Fx_Bead(FX_TWITTER, 25);
      RandomMovement_Bead(MOVE_RANDOM_FORWARD, 100);
      FancyMovement_Bead(MOVE_FANCY_BUG_FORWARD, 1, 100);
      Wait(25);
    }
  }
}

task BumpWatcher()
{
}

task PowerUpTask()
{
  int nLevel = EEPROM(EEPROM_USERLEVEL);
  SetLED(LED_MODE_YELLOW, 0);
  Wait(50);
  if (nLevel < 16)
  {
    nStatus = EVENT_RUNBEADS;
    CountDown_Bead(nLevel, COUNT_DIR_UP, 50);
  }
  ResetMotors();
  Wait(100);
}

task MyPostWatcher()
{
  while (true)
  {
    monitor(EVENT_MASK(PostEvent))
    {
      Wait(32767);
    }
    catch
    {
      SetPriority(0);
      if ((RxMessageChannel() & MSG_IR) > 0)
      {
        SetRxMessageLock(MSG_IR);

        if (RxMessage(MSG_IR, MSG_COMMAND) == COMMAND_CONTROLLER)
        {
          nControllerButton = RxMessage(MSG_IR, MSG_HI_BYTE);
          nControllerButton *= 256;
          nControllerButton |= RxMessage(MSG_IR, MSG_LO_BYTE);
        }

        switch(nControllerButton)
        {
          case CONTROLLER_BUTTON1:
            PlayTone(3401, 3);
            nMode = cAdvance;
            break;
          case CONTROLLER_BUTTON2:

Fire_Bead(CMD_FIRE_LASER,FIRE_TYPE_THERE_NARROW,-1,0,0,SOUND_FIRE_LASER,50);
            break;
          case CONTROLLER_BUTTON3:
            PlayTone(2801, 3);
            nMode = cRetreat;
            break;
        }
        SetRxMessageLock(MSG_NONE);
      }
    }
  }
}

task MyBumpWatcher()
{
  while (true)
  {
    monitor(EVENT_MASK(BumpEvent))
    {
      Wait(32767);
    }
    catch
    {
      SetPriority(1);
      PlaySound_Bead(SOUND_OUCH, 0);
      BasicMovement_Bead(MOVE_BASIC_BACKWARD, 50);
      BasicMovement_Bead(MOVE_BASIC_SPIN_RIGHT, 50);
    }
  }
}



Message is in Reply To:
  Re: Spybot studies: seek a world object
 
(...) I have found a copy of the MindScript code for the default program (sort of) and I have ported it to NQC. Here's the default program in MindScript: program SpybotDefaultProgram { main { start 0 } } And here is its NQC equivalent: #pragma (...) (19 years ago, 13-Oct-05, to lugnet.robotics.spybotics)

14 Messages in This Thread:





Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR