Alternative Programming Languages Myles McNally LMICSE Workshop November 19 - 21, 2004 University of Mississippi.

Slides:



Advertisements
Similar presentations
Mindstorms State Machines A structured method for handling tasks and events using RoboLab and NQC Brian Smith
Advertisements

1chung 5 th Annual Robofest 2004 Informational Meeting Mar. 20, 2004 Chan Jin Chung Ali Khazaal Jason Lo Computer Science Lawrence Technological University.
Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Alma Robotics Challenge March 30, 2007 Alma College.
PROJECT HEAD CASE Final Presentation Dan Klowden Jon Burns cse477 – Spring 2000.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Lego RCX Assembler and a Case Study Luis Paris Dept. of Computer Science University of Mississippi.
LEGO Robotics Lecture 1: Getting acquainted with your robotic environment.
Building robots Spring Mindstorms Programming Java + leJOS, NQC, and others.
The Turtle Laboratory Sequence Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
CC467 Biologically inspired robotics Introduction to Lego Mindstorms Owen Holland Computer Science University of Essex.
Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC.
Introduction to Lego Mindstorms LMICSE Workshop June , 2005 Alma College.
The Turtle Laboratory Sequence LMICSE Workshop August , 2006 Villanova University.
NQC: Not Quite C (last updated 9/14/05 2:24pm) Each NQC program has a task main () The program is contained within curly braces { ….. } task main() { SetSensor(SENSOR_1,
RobotC Programming for LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar SOURCES:
Not Quite C: A CS 0 Option LMICSE Workshop June , 2005 Alma College.
2. Textual user interface NQC (Not quite C)  C-like programs translated into CRX-bytecode  Composed of: 1.Global variables 2.Task blocks 3.Inline functions.
The Turtle Laboratory Sequence LMICSE Workshop June , 2005 Alma College.
LEGO Mindstorms RIS 2.0 Programming: NQC Code B.A. Juliano and R.S. Renner September 2004 California State University, Chico Intelligent Systems Laboratory.
Antonio Cisternino & Diego Colombo VisualStorms Tools Another Brick in the Robot... Università degli Studi di Pisa.
Tasks An NQC program consists of at most 10 tasks. Each task has a name. One task must have the name main, and this task will be executed. The other tasks.
The Lego RCX is a programmable digital device equipped with sensor inputs and motor outputs. As part of the Lego Mindstorms package, it is intended for.
Repeating Blocks of Code (updated 9/20/05 7:35pm) Reference NQC Tutorial pp 9-12.
Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before.
Lego Mindstorms NXT 2.0 Presented By: Fatma Al-Qattan Haya Al-Hajri Fatma Baqer Hanan Al-Qabandi.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Department of Computing and Information Sciences Kansas State University Design Methodology for State based Embedded Systems Case Study: Robot Controller.
[Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class 2.
Introduction to Threads CS240 Programming in C. Introduction to Threads A thread is a path execution By default, a C/C++ program has one thread called.
Presentation by Jeff Bargmann
Robotics Overview of NXT-G Actuators in Mindstorms. Touch sensor Labwork: Right turn. Touch/bump. [Explore move versus Motor Move mini & motor mini. Motor*.]
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Team Project: A Surveillant Robot System Little Red Team Chankyu Park (Michel) Seonah Lee (Sarah) Qingyuan Shi (Lisa) Chengzhou Li JunMei Li Kai Lin SW.
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
The George Washington University Department of ECE ECE 1010 Intro: Electrical & Computer Engineering –Introducing KIPR Link/Interface and Set-up –Continuation.
NXC (and NBC) NXC (Not eXactly C) is a language similar to NQC, which was the most popular way to program the RCX Built on NBC, the Next Byte Code ‘assembler’
Mindscript Presented by Dean Thomas Matthew Horoszowski.
Department of Computing and Information Sciences Kansas State University Design Methodology for State based Embedded Systems Case Study: Maze Navigator.
NQC Brief Introduction – Part 3 David Schilling. NQC – Where is my data? Programs have 32 global variables Tasks have 16 local variables These are always.
SLego: A Squeak Implementation of Lego Mindstorms Alexandre Bergel Institut fuer Mathematik und Informatik University Bern
Squeak and Botkit-Port Jeff Forbes Joel Miller. Introduction ● Squeak is a pure OO language ● Based off of SmallTalk-80 – Designed at Xerox PARC by Alan.
THE TOUCH SENSOR The Touch Sensor, shown in the picture, gives the robot the sense of touch. It gives too different signals when the orange part is ether.
Lego MindStorm An Introduction to Blocks. Blocks Blocks are used to give instructions to your robot. There are many types of blocks You can use the blocks.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Castor Bot. Now, we will begin creating a robot Log onto your computer On your screen, click on the website labeled “castor bot” Your building instructions.
NQC / BricxCC Brief Introduction David Schilling.
How to control LEGO® Mindstorms devices Thomas Mueller thomas _ tmspecial.com.
Minds and Computers 2.1 The RCX l Hitachi H8/3297 series processor l 3 inputs/sensors (1, 2, 3) l 3 outputs/motors (A, B, C) l 32k RAM/ 16k ROM ä 12 kB.
Mindstorms 1.1 Today’s topics l AI l History of Robotics l Uses of robots l The RCX l ROBOLAB l Upcoming ä Basic control ä Kinematics ä Robot architectures.
NQC Brief Introduction – Part 2 David Schilling. NQC – Where to put code? Programs Tasks Functions Subroutines.
Using the BlueJ IDE with Mindstorms LMICSE Workshop June , 2005 Alma College.
Lesson 1: Motors and Sound Programming Solutions.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
T.R.I.D.E Simon Overell (seo01) Supervisor: Keith Clark.
Presentation Outline I. Background Information II. Design Project
SPiiPlus Training Class
Instructor: Chien-Ho Ko
Introduction to Gobbit Programming
Introducing KIPR Link/Interface and Set-up
Robot Programming Computer Literacy S2.
RobotC Programming for LEGO Mindstorms NXT
Team Project: A Surveillant Robot System
Preprocessor Directives
Programming Robots using Java
LEGO Mindstorms Robot and Java
NQC Program Structure 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions.
Presentation transcript:

Alternative Programming Languages Myles McNally LMICSE Workshop November , 2004 University of Mississippi

Available Languages for the RCX Mindstorms ships with its own iconic programming language, but this is a very limited language. So other have developed for Mindstorms almost all the usual programming languages, including: C C++ Java Lisp Ada Forth Smalltalk

Primary RCX Programming Environments LejOS Java, replacement firmware NQC (Not Quite C) A simplified C-based language which uses the standard firmware BrickOS (formally known as LegOS) C and C++, replacement firmware RCXLisp Common Lisp, replacement firmware

LejOS Since LejOS is the workshop’s language/environment of instruction, we will not address it during this session But you can find the LejOS home page at

NQC Well suited for those new to programming Often used in non-majors courses Allows the demonstration of most non-object oriented aspects of introductory programming Easy introduction to concurrent programming issues

NQC Basics C-like syntax Limited by use of standard firmware 10 threads 32 global variables, 16 local variables per thread Integers only Byte codes are interpreted No call stack, no memory management Functions pass by value and pass by reference parameters all function return void Simple event model Limited arrays

RCX Basic Motor Control Recall that there are three power outputs, and in NQC the motors attached to them are called OUT_A OUT_B OUT_C Basic motor control commands OnFwd( … ) : run the … motor(s) forward OnRev( … ) : run the … motor(s) in reverse Off( … ) : stop the … motor(s) Another useful command Wait( …) : pause the program execution for … microseconds

RCX Example 1: Motor Control task main () { OnFwd(OUT_A + OUT_C);// Move Forward Wait(500); OnRev(OUT_C);// Turn Around Wait(200); OnFwd(OUT_C);// Come Back Wait(500); Off(OUT_A + OUT_C);// Stop } Move forward for 5 seconds, turn around, and come back

RCX Example 2: Inline Functions Drive around in a square shape task main () { while (true) { moveForward(500); turnLeft(100); } void moveForward(int time) { OnFwd(OUT_A + OUT_C); Wait(time); Off(OUT_A + OUT_C); } void turnLeft(int time) { OnFwd(OUT_C); OnRev(OUT_A); Wait(time); Off(OUT_A + OUT_C); }

Using Sensors Recall that there are three sensor connections, and in NQC the sensors attached to them are called SENSOR_1 SENSOR_2 SENSOR_3 To use a sensor we must first define it type using SetSensor SetSensor(SENSOR_1, SENSOR_TOUCH); SetSensor(SENSOR_2, SENSOR_LIGHT); By default, touch sensors return 0 or 1 (1 if currently pressed) By default, light sensors return a value in the range , with 0 meaning no measured light

NQC Example 3: Sensor Polling task main () { SetSensor(SENSOR_2, SENSOR_TOUCH); OnFwd(OUT_A + OUT_C);// Move Forward while (SENSOR_2 != 1)// Until a Bump ; Off(OUT_A + OUT_C);// Then Stop } Move forward until a bump

NQC Example 4: Multi-Tasking task main () { SetSensor(SENSOR_2, SENSOR_TOUCH); start patrol; while(SENSOR_2 != 1) ; stop patrol; Off(OUT_A + OUT_C); } task patrol () { OnFwd(OUT_A); while(true) { OnFwd(OUT_C); Wait(400); OnRev(OUT_C); Wait(200); } Drive back and forth until a bump

NQC Links NQC was developed by Dave Baum and is now maintained by John Hansen For the Macintosh the IDE of choice is MacNQC For Windows the IDE of choice is Bricx Command Center (bricxCC) BricxCC can also be used with BrickOS, LejOS, and pForth

BrickOS A open source project Offers the ability to program the RCX in C and in C++ Improvements over environments which use the standard firmware include: Native code execution (no interpretation!) More memory available Floating point available Memory management, call stack Fine grained hardware control, including raw mode IR In addition: C and C++ as in gcc Priority-based preemptive multitasking Real process synchronization with POSIX semaphores

BrickOS Example 1 #include int main(int argc, char *argv[]) { motor_a_speed(MAX_SPEED); motor_c_speed(MAX_SPEED); motor_a_dir(fwd); motor_c_dir(fwd); msleep(5000); motor_c_dir(rev); msleep(2000); motor_c_dir(fwd); msleep(5000); motor_a_dir(off); motor_c_dir(off); return 0; } Move forward for 5 seconds, turn around, and come back

BrickOS Example 2 #include int main(int argc, char *argv[]) { motor_a_speed(MAX_SPEED); motor_c_speed(MAX_SPEED); motor_a_dir(fwd); motor_c_dir(fwd); while(SENSOR_2 > 0xf000) ; motor_a_dir(off); motor_c_dir(off); return 0; } Move forward until a bump

BrickOS Links The BrickOS home page

RCXLisp RCXLisp is designed to allow a programmer to Remotely control the RCX from a Common Lisp program running on a desktop computer Write RCXLisp programs to run on the RCX Create and compile RCXLisp programs for downloading to RCXs “on the fly” Simultaneously control more than one RCX from a single MindStorms infrared tower Set up a network of RCX units that can communicate with each other in a targeted manner (as opposed to the “broadcast manner” supported by LEGO’s kit).

The Two Parts of RCXLisp The term `RCXLisp’ actually refers to two related languages: Remote RCXLisp: a collection of macros, variables, and functions for remotely controlling RCX units from a desktop machine. RCXLisp Proper: a subset of Common Lisp that can be used to write programs for controlling RCXs (with LEGO’s firmware, or with Mnet extended firmware that supports wireless networking and most of the opcodes from LEGO’s firmware 1.0) from onboard the units.

Writing RCXLisp Code The following examples demonstrate RCXLisp basics: On-board and remote control Targeted communication These and other examples can be found in the RCXLisp documentation

RCXLisp Example 1: Random Walk (defconstant *MOVE-TIME* 100) (defconstant *TURN-TIME* 85) (defthread (main :primary t) ( ) (set-effector-state '(:A :C) :speed 7) (set-effector-state '(:A :C) :power :on) (loop (set-effector-state '(:A :C) :direction :forward) (sleep *MOVE-TIME*) (if (= (random 1) 0) (set-effector-state :C :direction :backward) (set-effector-state :A :direction :backward)) (sleep *TURN-TIME*))) Have the robot go for a random walk (Code running on the RCX)

RCXLisp Example 2: System Sounds (DEFUN play-all-sounds ( ) (with-open-com-port (p 1) (with-open-rcx-stream (s p :rcx-unit 12) (DOTIMES (num 6) (play-system-sound num s) (DOTIMES (x 10000) (* x 1)))))) Have the RCX with network number 12 play all 6 of its system sounds (Running on the Desktop)

RCXLisp Example 3: Multiple RCXs (DEFUN test () (with-open-com-port (p 1) (with-open-rcx-stream (rcx1 p :rcx-unit 1) (with-open-rcx-stream (rcx2 p :rcx-unit 2) (full-speed-ahead2 rcx1 5 :backward) (full-speed-ahead2 rcx2 1 :forward))))) Part 1 - Tell RCX 1 to move backward at speed 5, then tell RCX 2 to move forward at speed 1 (Running on the Desktop)

RCXLisp Example 3: Multiple RCXs (DEFUN full-speed-ahead2 (r s dir) ; r moves at speed s (LET ((result 0)) ; in direction dir (using-rcx r (set-effector-state '(:A :B :C) :power :off) (set-effector-state '(:A :C) :direction dir) (set-sensor-state 2 :type :touch :mode :boolean) (set-effector-state '(:A :C) :power :on) (LOOP (SETF result (sensor 2)) (WHEN (AND (NUMBERP result) (= result 1)) (RETURN))) (set-effector-state ‘(:A :C) :power :float))))) Part 2 - Tell an RCX to move at a speed in a direction until a bump sensor is pressed (Running on the Desktop)

RCXLisp Links RCXLisp was developed by Frank Klassner The RCXLisp software can be found at The underlying Lisp environment is Xanalys LispWorks. A demo version (5 hour per session time limit) can be found at

Links for Some Other Programming Languages ADA pForth