Difference between revisions of "Logo for NXT"

From RoboWiki
Jump to: navigation, search
Line 18: Line 18:
 
== Motor & Sensor procedures ==
 
== Motor & Sensor procedures ==
  
  (motor m cmd [arg])
+
  (motor m cmd arg)
 
   
 
   
   where cmd is one of:   
+
   where m is the number of motor(s) as in NBC:
     on         
+
    0 - motor A
     off
+
    1 - motor B
     brake       
+
    2 - motor C
     regulate    [speed]
+
    3 - motors AB
     sync       [ratio]
+
    4 - motors AC
     on_rot      [number_of_rotations]
+
    5 - motors BC
     on_ms      [number_of_ms]
+
    6 - motors ABC
     power       [power]
+
   
     rst
+
  and cmd is one of (with the corresponding argument, similar to NBC):   
 +
     onfwd      power
 +
    onrev      power 
 +
     off         (ignored)
 +
     float      (ignored)
 +
     fwdr        [power regmode]
 +
     revr       [power regmode]
 +
     fwds        [power turnpct]
 +
     revs        [power turnpct]
 +
     onrot       [power angle]
 +
     rst         kind  (1-4)   
 
   
 
   
 
  (readmotor m cmd)
 
  (readmotor m cmd)
Line 42: Line 52:
 
  (setsensor N type)
 
  (setsensor N type)
 
   
 
   
     where type is one of:
+
     where type is number according to NBC:
       raw
+
       0 - raw
       switch
+
       1 - switch
       tmp_C
+
       2 - tmp_C
       tmp_F
+
       194 - tmp_F
       refl
+
       3 - refl
       angle
+
       4 - angle
       light_a
+
       5 - light active
       light_i
+
       6 - light inactive
       db
+
       7 - sound db
       dba
+
       8 - sound dba
       lowspeed
+
       9 - custom
       ls9V
+
      10 - lowspeed
 +
      11 - lowspeed with 9V
 +
       12 - high speed
  
 
== Supported primitives ==
 
== Supported primitives ==
Line 75: Line 87:
 
The expressions must be in prefix notation. Variables are used the same way as in Logo - as "name when referring to variable name, and as :name when referring to its value. There are global variables as well as local variables, lexical scoping as usual in Logo.
 
The expressions must be in prefix notation. Variables are used the same way as in Logo - as "name when referring to variable name, and as :name when referring to its value. There are global variables as well as local variables, lexical scoping as usual in Logo.
  
The <tt>(remote expression)</tt> operations allow to start evaluating an expression on NXT when started from PC, and vice-versa. This can be used for communication. Of course, one could then easily say, for example:
+
The <tt>(remote "expression)</tt> operations allow to start evaluating an expression on NXT when started from PC, and vice-versa. This can be used for communication. Of course, one could then easily say, for example:
  
  remote [print "hello]
+
  remote "|[print "hello]|
  
 
or
 
or
  
  remote [my_program 123]
+
  remote "|[my_program 123]|
  
 
or read value of remote variable:
 
or read value of remote variable:
  
  remote :varA
+
  remote "|:var|
  
 
However, one has to keep in mind that BlueTooth communication is slow due to switching of the direction of the transceiver and receiver. Therefore, it is preferable to implement higher-level functions and procedures that can run on NXT brick autonomously. Logo programs have about 30kb of memory available - for storing both the logo programs and data, however, programs can load/erase data and code from NXT files that are stored in the large flash.
 
However, one has to keep in mind that BlueTooth communication is slow due to switching of the direction of the transceiver and receiver. Therefore, it is preferable to implement higher-level functions and procedures that can run on NXT brick autonomously. Logo programs have about 30kb of memory available - for storing both the logo programs and data, however, programs can load/erase data and code from NXT files that are stored in the large flash.

Revision as of 10:17, 21 August 2007

Welcome to Logo for NXT

This page contains information about the project of programming NXT in Logo language.

The project is under intensive development, and there are no releases yet. However, the projet is open-source and the latest development version is available in the CVS.

Nxtlogo.gif

Features

  1. Interactive Imagine project with direct GUI controls that allow interfacing with NXT robot over Bluetooth
  2. Loadable imagine library (nxt.imt) that contains set of procedures for direct control of NXT robot over Bluetooth from your Imagine projects
  3. Interpreter of Logo running on the NXT that can run logo programs (with restricted syntax), which can communicate with Imagine projects and control the robots motors and sensors.

Motor & Sensor procedures

(motor m cmd arg)

  where m is the number of motor(s) as in NBC:
   0 - motor A
   1 - motor B
   2 - motor C 
   3 - motors AB
   4 - motors AC
   5 - motors BC
   6 - motors ABC
   
  and cmd is one of (with the corresponding argument, similar to NBC):  
    onfwd       power
    onrev       power   
    off         (ignored)
    float       (ignored) 
    fwdr        [power regmode]
    revr        [power regmode]
    fwds        [power turnpct]
    revs        [power turnpct]
    onrot       [power angle]
    rst         kind  (1-4)     

(readmotor m cmd)

  where cmd is one of:
    rotations
    tacho
    blocktacho

(sensor N)

(setsensor N type)

   where type is number according to NBC:
     0 - raw
     1 - switch
     2 - tmp_C
     194 - tmp_F
     3 - refl
     4 - angle
     5 - light active
     6 - light inactive
     7 - sound db
     8 - sound dba
     9 - custom
     10 - lowspeed
     11 - lowspeed with 9V
     12 - high speed

Supported primitives

NXT Logo supports the following primitive procedures and operations:

  1. Arithmetic: add, sub, mul, div, mod, neg
  2. Logic: and, or, xor, not
  3. Bitwise: bitand, bitor, bitxor, bitnot
  4. Lists and words: first, bf, last, bl, item, se, list, word
  5. Maps & co.: map, apply, foreach, run, remote
  6. Loops and conditions: repeat, while, foreach, if, ifelse
  7. Predicates: empty? number? list? word? equal? gt? lt? ge? le? member?
  8. Variables and procedures: make, let, to, op, stop, erase, launch
  9. NXT file handling: load, printto, fopen, fwrite, fread, fclose, fremove
  10. Sounds: tone, sound
  11. Motors, sensors: motor, readmotor, sensor, setsensor, battery
  12. Other: wait, random, print, draw, ascii, char, boot, gc, fm

The expressions must be in prefix notation. Variables are used the same way as in Logo - as "name when referring to variable name, and as :name when referring to its value. There are global variables as well as local variables, lexical scoping as usual in Logo.

The (remote "expression) operations allow to start evaluating an expression on NXT when started from PC, and vice-versa. This can be used for communication. Of course, one could then easily say, for example:

remote "|[print "hello]|

or

remote "|[my_program 123]|

or read value of remote variable:

remote "|:var|

However, one has to keep in mind that BlueTooth communication is slow due to switching of the direction of the transceiver and receiver. Therefore, it is preferable to implement higher-level functions and procedures that can run on NXT brick autonomously. Logo programs have about 30kb of memory available - for storing both the logo programs and data, however, programs can load/erase data and code from NXT files that are stored in the large flash.

Examples

Some sample code for Logo for NXT is in the Examples folder.

Syntax

Detailed syntax is shown in the file syntax.txt.

Reference Guide

More detailed description of all commands and the system are located here: Logo for NXT Reference Guide.

Internals

Short specification of the Logo for NXT internals is in the file specification.txt.