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 / 385
384  |  386
Subject: 
Re: Arrays and proximity
Newsgroups: 
lugnet.robotics.spybotics
Date: 
Thu, 27 Jan 2005 22:04:04 GMT
Viewed: 
7376 times
  
In lugnet.robotics.spybotics, Kim Øyhus wrote:
   I just got my Spybotics set cheaply, and I now want to start my machine intellligence experiment. However, I need arrays to process inputs and store experiences. How large can they be in the spybot? How can I use the flash? And how can I use the proximity sensors?

The Spybot has a limited number of global (32) variables. NQC lets you access these via an array syntax. MindScript and NQC also let you use pointers to variables which effectively is an array. The maximum size of an array is less than 32. The Spybot also has an area in its flash memory which can be directly read and written via program code. If you don’t want to preserve the Spybot Game information in the flash memory then you can read and write to 256 byte-sized flash memory addresses. If you do want to preserve that information then you can only use 128 bytes of this region (addresses 0x80 through 0xff). LASM, MindScript, and NQC can all access this region of memory. NQC doesn’t give you access to this memory space via its standard array syntax but it does let you access it as an array via a slightly different syntax. The proximity sensors can be accessed using the appropriate MindScript or NQC API syntax.

   Yesterday I studied LASM, and to my horror: No arrays, no indexing, nothing! Ghastly! It is NOT turing machine compatible. It is in fact not a computer, just a state machine. Perhaps self modifying code would do the trick. Any advice on that?

I don’t follow you here. The Spybot is indeed a computer. You can access memory as if it were an array using LASM (as well as MindScript and NQC).

   I got quite impressed with NQC, which do have arrays, and I wonder how those were implemented. Self modifying code again? Bytecodes not in LASM?

The LASM opcodes and sources do let you use indirect sources for accessing memory locations. Arrays and pointers in NQC are implemented using the Indirect source.

   But it seems to lack control of proximity sensor. Could I put that in myself with some #pragma or similar?

The Spybot API which is included in recent versions of NQC does give access to the Spybot world relationship table information. You don’t want to use versions of NQC older than 3.0a2 with the Spybot because of a problem in the subroutine code generation (if you use any subroutines).

   Then I discovered BrickOS. Perfect! ...except that it just runs on the RCX, not the spybots. Can that be fixed? Could I fix that, with a little help?

As Steve already explained, you can’t replace the firmware in the Spybot brick.

Here is a very simple sample MindScript program demonstrating the use of pointers, flash memory (eeprom), and proximity information:

program demo {
  #include<Spybot.h>
  var x

  main {
    local nIndex
    local i
    local p
    p = @x
    i = 0
    x = 0x80
    while i < 10
    {
      eeprom[x] = i
      p^ = x + 1
    }
    find world[nIndex,iRange] > cNowhere {
      eeprom[0xa0] = world[nIndex, iRange]
      if world[nIndex,iShortID] < cPCID
      {
        eeprom[x] = eeprom[x] + 1
      }
    }
  }
}

Here’s the LASM equivalent:

;Program demo
;----------------------------------------
;Main task
 task 8
Main:

 senm 0,1,0

 senm 1,4,0
 setv 33,2,31
 setv 34,2,0
 setv 31,2,128
While0001:
 chk 2,10,0,0,34,EndWhile0001
 set 54,31,0,34
 setv 32,0,31
 sumv 32,2,1
 set 36,33,0,32
 jmp While0001
EndWhile0001:
 setv 35,2,-1
Find0002:
 find 35,45,0,2,0
 chkl 2,-1,3,0,35,EndFind0003
 set 20,160,45,35
;If004:
 chk 2,7,0,49,35,EndIf0004
 set 0,32,54,31
 sumv 32,2,1
 set 54,31,0,32
EndIf0004:
 jmp Find0002
EndFind0003:
EndMain:
 endt
;----------------------------------------
;Main (task 8) code size: 103 bytes
;----------------------------------------
;Total code size: 103 bytes


Here’s an NQC program demonstrating some of these same concepts:

#pragma noinit

#define Eeprom(n) @@(0x1436)[(n)]

#define World(i, n) @@(0x322a+(i))[(n)]
#define WorldShortID(n) @@(0x322a+SPY_SHORTID)[(n)]
#define WorldLinkID(n) @@(0x322a+SPY_LINKID)[(n)]
#define WorldRange(n) @@(0x322a+SPY_RANGE)[(n)]
#define WorldDirection(n) @@(0x322a+SPY_DIRECTION)[(n)]
#define WorldAspect(n) @@(0x322a+SPY_ASPECT)[(n)]
#define WorldNote(n) @@(0x322a+SPY_NOTE)[(n)]

task main()
{
  int x = 0;
  int t = -1;
  int* p = &x;
  ClearWorld();
  FindWorld(t, SPY_RANGE, REL_GT, RANGE_NOWHERE);
  while (t != -1)
  {
    SetWorldNote(t, 40);
    WorldNote(t) = 40;
    SetTargetID(t);
    x = WorldShortID(t);
    x = WorldRange(t);
    x = WorldNote(t);
/*
    GetWorld(SPY_SHORTID, t, x);
    GetWorld(SPY_LINKID, t, x);
    GetWorld(SPY_RANGE, t, x);
    GetWorld(SPY_DIRECTION, t, x);
    GetWorld(SPY_ASPECT, t, x);
    GetWorld(SPY_INFO, t, x);
    GetWorld(SPY_NOTE, t, x);
*/
    FindWorld(t, SPY_RANGE, REL_GT, RANGE_NOWHERE);
  }

  SetTargetNote(x);
  x = Target(SPY_SHORTID);
  x = Target(SPY_LINKID);
  x = Target(SPY_RANGE);
  x = Target(SPY_DIRECTION);
  x = Target(SPY_ASPECT);
  x = Target(SPY_INFO);
  x = Target(SPY_NOTE);

  int i;
  x = 0x80;
  for(i=0; i<10; i++)
  {
    Eeprom(x) = i;
//    x++;
    *p += 1;
  }
  Eeprom(0x81) = 11;
  i = Eeprom(x);

}

The #defines at the top of this NQC sample will very likely be in the next official NQC API.

John Hansen



Message is in Reply To:
  Arrays and proximity
 
I just got my Spybotics set cheaply, and I now want to start my machine intellligence experiment. However, I need arrays to process inputs and store experiences. How large can they be in the spybot? How can I use the flash? And how can I use the (...) (19 years ago, 27-Jan-05, to lugnet.robotics.spybotics)

4 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