Clogo is a LOGO REPL (interpreter) written in Clojure. It can control a Lego NXT2 turtle robot or be used in standalone mode.
Logo is an education programming language, designed in 1967 … remembered mainly for its use of “turtle graphics” … Logo is a multi-paradigm adaptation and dialect of Lisp — Wikipedia Logo (programming language)
WTF? (What’s This For?)
- For kids to learn programming, through the good old Logo turtle
- To mess up with Clojure, with many side effects (such as drawing on the screen and even commanding a robot)
- To play with Lego Mindstorms and build a “turtle robot” which holds a pencil to draw on paper
Quick Start (without the Lego Mindstorms robot)
You can try Clogo very easily. Even if you don’t have Lego Mindstorms, you can learn the LOGO language and command the turtle to draw on the screen. All you need is either leiningen or maven to build the app.
git clone https://github.com/japonophile/clogo.git
- With leiningen:
lein compile lein uberjar java -jar target/clogo-0.1.0-SNAPSHOT-standalone.jar
- With maven:
mvn install java -jar target/clogo-0.1.0-SNAPSHOT-jar-with-dependencies.jar
See the cLOGO Crash Course to find out what you can do with Clogo
Instructions for building Clogo to control a Lego NXT2 turtle robot
If you plan to try with a Lego NXT2 robot, you will need
- Maven
- Lejos NXJ (Java for LEGO Mindstorms)
- Bluecove (bluetooth library to connect to the turtle robot)
Note: I am on Mac OSX and haven’t tested on other platforms.
Here are the steps to follow:
- Download Lejos libraries: get
leJOS_NXJ_0.9.1beta-3.tar.gz
from http://sourceforge.net/projects/lejos/files/lejos-NXJ/ - Install them in your local Maven repo:
mvn install:install-file -Dfile=leJOS_NXJ_0.9.1beta-3/lib/pc/pccomm.jar -DgroupId=lejos.pc -DartifactId=pccomm -Dversion=0.9.1-beta3 -Dpackaging=jar
mvn install:install-file -Dfile=leJOS_NXJ_0.9.1beta-3/lib/nxt/classes.jar -DgroupId=lejos.nxt -DartifactId=classes -Dversion=0.9.1-beta3 -Dpackaging=jar
- Install and build bluecove (2.1.1-SNAPSHOT)
git clone https://github.com/jarias/bluecove.git mvn install
- Use Maven to build the LOGO interpreter and the LogoTurtle software to be downloaded onto the NXT2 robot. You need to specify the path of leJOS, because the compiler will be required to compile the turtle code.
mvn install -Pnxt -Dnxj.home=/Users/yourhome/leJOS_NXJ_0.9.1beta-3
- Build your turtle robot. It will use 2 motors to move and turn, and one motor to control the pencil. Once the robot is built, you should configure bluetooth and pair your NXT2 processor with your computer.
- Download the LogoTurtle.nxd / LogoTurtle.nxj onto your NXT2 processor (using the USB link shipped with your Lego Mindstorms); then start your robot. It will show the letters “connecting…” on its LCD screen.
- Start the application on your computer.
java -jar target/clogo-0.1.0-SNAPSHOT-jar-with-dependencies.jar
Within a few seconds, the application should try to connect with the turtle using bluetooth. Each command to the LOGO REPL will be sent to the robot for execution.
Enjoy!
cLOGO Crash Course
First of all, note that this LOGO interpreter only understand French LOGO commands (although it should be straighforward to support other languages -contributions are welcome!)
Here are some commands you can use:
Basic drawing commands
AVANCE X
(respRECULE X
) : move forward (resp backward) for X stepsGAUCHE Y
(respDROITE X
) : make a left (resp right) turn of X degreesLEVECRAYON
(respBAISSECRAYON
) : put the pen down (resp up)MONTRETORTUE
(respCACHETORTUE
) : show (resp hide) the turtle
Programming constructs
REPETE N [ ... ]
: repeat N times the instructions in square bracketsPOUR PROCNAME ... FIN
: defines a procedure calledPROCNAME
which can be reused by writing its name. You can also pass parameters to the procedure likePOUR PROCNAME :PARAM1 ... FIN
where:PARAM1
is an input parameter of the procedure which can then be used by writingPARAM1
(without the “:” prefix).DONNE VARNAME VALUE
: defines a variableVARNAME
with a certainVALUE
which can be an expression.
Expressions
- Clogo supports both prefix and infix operatorsr:
- Prefix operators:
SOMME X Y
,DIFFERENCE X Y
,PRODUIT X Y
andQUOTIENT X Y
. - Infix operators:
X + Y
,X - Y
,X * Y
andX / Y
.
- Prefix operators:
- You can also use parentheses in your expressions
Writing to the screen
ECRIS X
: write the value of X to the screen- Clogo has 2 predefined variables:
POS
: the position of the turtle (x and y)CAP
: the orientation of the turtle (in degrees)
Examples:
- Draw a square
POUR CARRE :COTE
AVANCE COTE
DROITE 90
FIN - Draw a circle (actually a 36-sides polygon)
POUR CERCLE
REPETE 36 [ AVANCE 1 DROITE 10 ]
FIN
Contributing
Clogo was an experiment / personal project to get my children play with Lego Mindstorms and learn programming through the LOGO language. It has only been tested on Mac (OSX Lion-Mavericks) and the turtle robot was an original creation (which also required some non-NXT bricks).
Feel free to try and contribute if you like Clogo.
Spreading the word by posting on Twitter or blogging about Clogo is also a great way to show your appreciation.
License
Copyright © 2014 Antoine Choppin
Distributed under the Eclipse Public License, the same as Clojure.