Robotran: Robot programming adventures for novices in LEGO-land: Robotran: Robot programming adventures for novices in LEGO-land R. Mark Meyer
Debra T. Burhans
Canisius College
Buffalo, NY
Overview: Overview Our use of LEGO Mindstorms in the curriculum, especially early courses
Robolang – a simple, non-threatening programming language
Simulation – let them take it home with them
How to sneak AI concepts into intro courses
What’s NXT?
But first... Our chief protagonist: But first... Our chief protagonist The Pen bot
a roverbot with
an attached pen
so it can draw,
like turtle
graphics.
Educational Objectives: Educational Objectives Motivate students to stay in CS using the fun and challenge of robotics
Recruit new students to CS
Teach non-majors simple programming
Provide a framework for CS majors to learn Java better (using Lejos)
Use social implications of robotics to motivate ethics discussion
Introduce students to AI concepts
Most of all....: Most of all.... Our goal is happy students!
Curricular Use: Curricular Use CSC 110 – A “CS 0” course
CSC 109 – Another “CS 0” course that is solely robotics
EGR 111 – Introduction to engineering (pre-engineers)
CSC 111 – Our Java-based “CS 1”
CSC 360 – Intelligent Systems: AI, robotics, knowledge bases
CSC 391/491 – Seminar, 1 credit hour special projects
Role of AI: Role of AI Only CSC 360 is a true AI course and uses AI techniques: Wumpus world, intelligent agents, searching
CSC 109 – focus on basic AI and computing in the context of robotics, programming as a way of creating behaviors
CSC 110 – mostly drawing letters, simple algorithms
EGR 111 – study sensor electronics, basic programming concepts (BrickCC), engineering through robot building
We also sneak AI concepts into CSC 111
Seminar allows students to work on larger AI projects
Robotran V.1: Robotran V.1 Translator program
Robolang – a simple Python-ish language
Translator to true Lejos
Used as web applet or standalone Java app
Can compile and download
Robolang Details: Robolang Details Streamlined syntax for assignments and control structures, especially button handler methods
Uses Java expression syntax and transparently inserts into the final Lejos code
Simplified robot commands:
go forward 10 seconds
Motor.A.start();
Motor.B.start();
try { Thread.sleep(10000); } catch (Exception e) {}
Simplified function (method) syntax
Simple Light Follower program: Simple Light Follower program program follow1
constant BLACK = 42
loop
var lightvalue = S3
display lightvalue
if lightvalue < BLACK then
stop
else
go forward
end
end
Light Hunter: Light Hunter program follow4
global constant BLACK = 42
global var turnedLeft = 1
loop
var lightvalue = S3
display lightvalue
if lightvalue BLACK then
return 1
else
turn right sharp 25 degrees
return 0
end
end
define huntRight() returns number
turn right sharp 25 degrees
var lightvalue = S3
if lightvalue > BLACK then
return 1
else
turn left sharp 25 degrees
return 0
end
end
define findLight
var result
if turnedLeft = 1 then
result = huntLeft()
if result = 1 then
return
end
result = huntRight()
if result = 1 then
turnedLeft = 0
return
end
end
if turnedLeft = 0 then
if huntRight() = 1 then
return
end
if huntLeft() = 1 then
turnedLeft = 1
return
end
end
end
Syntactic Sugar: Syntactic Sugar Use only one equals sign to compare things
Allow several syntaxes for assignment statements; avoid the old “equals” confusion
let X = 5
set X to 5
Allow parentheses around conditions to be omitted
Use clear control structure delimiters: “end” statements
Turn around the order of elements in a function definition, à la Pascal
define huntRight() returns number
The Place of Language: The Place of Language Continuum of difficulty in Robot languages:
Robolab and NXT graphical environment
Lisp, Robolang, Python type languages
NQC
Lejos
What is your goal?
Teach beginner non-majors to control a robot? Use easy language
Inspire engineers? Use NQC
Reinforce Java for CS majors? Use Lejos
However, a difficult language may turn off students!
Alternative: use a ramp-up strategy like “Dr. Java” project Use Scheme first, then Java
Lessons Learned from Language Design: Lessons Learned from Language Design Separating button events from sensor polling is tricky for novices
Language structures should aid this distinction when RUN button is pressed do stuff end
This shouldn’t be in-line with main program
Need definite “program” structure with its own “end”
More study is needed to pinpoint troublesome concepts
Assignments: Assignments Robot avoids obstacles by randomly turning after bumps
Robot draws letters
Robot follows a light source and hunts for it when lost
Robot receives input from bumps and button presses, including binary or unary numbers
Robot is taught a path which it can then replay (uses arrays)
Robot follows a line on the floor
Robot stays within a sumo ring and tries to push another robot outside without leaving the ring itself
Robot navigates a maze (needs to remember path & obstacles)
Navigating the Maze: Navigating the Maze Robots were
programmed in
NQC, Lejos, and
Robolang
Better algorithms, anyone?: Better algorithms, anyone? The trickiness of the algorithms was a great leveler.
There was no strong edge for those who used more complex languages.
Robot Competitions are Fun!: Robot Competitions are Fun! The Physics Team at the Robot Competition
(Jeff, Mark, Jim)
Taken 18 Nov 2006
AI concepts at work: AI concepts at work Many of these tasks can motivate AI discussion and algorithm development, esp. searching, strategy and data structures
One definition of intelligence: “having a wide repertory of solutions from which to choose when encountering a problem”
We can’t do much with the RCX alone due to limited memory and processing time
Even the NXT only has 256K RAM, but it can more easily use a wirelessly connected computer as its brain
These robots are learning environments, not built to actually explore Mars!
Similarly our students are just getting started.
Need for a Simulator: Need for a Simulator Almost everyone agrees we need one
Shouldn’t usurp the tactile, kinetic experience
Allow students to complete assignments at home or outside of lab
Could be used to explore more complicated behaviors
Major challenge to build a realistic and useful one!
Doomed to Succeed?: Doomed to Succeed? “... and the demo was launched again. This time the students lost their wireless connection and the process had to begin again. In the end, the visiting Boeing bigwigs gathered around a laptop display and watched an elaborate demonstration of the treasure hunt concept – in simulation. The Boeing folks were quite intrigued and, seemingly, satisfied. ‘Simulations,’ so the saying goes at the RI (Robotics Institute at CMU), ‘are doomed to succeed.’”
“Almost Human: Making Robots Think” by Lee Gutkind
WW Norton, 2006.
Our simulator: Our simulator Simulate the penbot, only one at a time, geared towards real assignments
Don’t get overly caught up with 3d graphics
Provide functionality with both Robolang and Lejos
Make it flexible for future implementation on NXT
Use the lejos compiled code that makes calls to the firmware ROM
Create our own ROM object with same API and let the compiled code, running in tinyVM, call it
Then our ROM object sends updates to a graphics simulation object
Some of the Simulation code...: Some of the Simulation code... package simulator.rcx;
//import simulator.*;
/* This class represents the RCX robot during a simulation. It keeps track of
* states and properties that are associated with a RCX robot.
* Note that most fields are static because components on the RCX are finite
* meaning that there are a static number of robot components. (ex: number of
* buttons will always be 4)
*@author David Puehn
*/
public class RCX {
/* The state the robot is in
* 0: off
* 1: on
* 2: on and running a program
*/
public static int state = 0;
/* The current voltage of the RCX's batteries */
public static double batteryVoltage = 319; //TODO: create me
thod to convert voltage to readable value
/* The virtual RCX's buttons */
public static Button ButtonRUN = new Button(0x01);
public static Button ButtonVIEW = new Button(0x02);
public static Button ButtonPRGM = new Button(0x04);
/* The virtual RCX's motors */
public static Motor MotorA = new Motor('A');
public static Motor MotorB = new Motor('B');
public static Motor MotorC = new Motor('C');
/* The virtual RCX's sensors */
public static Sensor Sensor1 = new Sensor((short)1);
public static Sensor Sensor2 = new Sensor((short)2);
public static Sensor Sensor3 = new Sensor((short)3);
/* The RCX's ROM */
public static ROM Rom = new ROM();
/* The RCX's Memory */
public static Memory Memory = new Memory();
/* The RCX's Poller */
public static Poller Poller = new Poller();
/* The RCX's Sound */
public static Sound Sound = new Sound();
/* The RCX's User Controls */
public static RcxController Controller = new RcxController();
/* The RCX's LCD */
public static Display LCD = new Display();
/* Holds all of the simulator components so that we can iterate through them */
public static RcxComponent[] components = {
ButtonRUN,
ButtonVIEW,
ButtonPRGM,
MotorA,
MotorB,
MotorC,
Sensor1,
Sensor2,
Sensor3,
Rom,
Memory,
Poller,
Sound,
LCD
};
Emulating the native ROM routines: Emulating the native ROM routines package simulator.rcx;
/* An emulation of the RCX's native ROM routines */
public class ROM implements RcxComponent {
//simulates behavior when call to RCX's rom
public static void call(short aAddr) {
//refresh the lcd
if (aAddr == 0x27c8) {
RCX.LCD.refresh();
}
//clear the lcd
else if (aAddr == 0x27ac) {
RCX.LCD.clear();
}
}
//simulates behavior when call to RCX's rom
public static void call(short aAddr, short a1) {
//setSegment of lcd
//a1: the lcd segment
if (aAddr == 0x1b62) {
RCX.LCD.setSegment(a1);
}
//clearSegment of lcd
//a1: the lcd segment
else if (aAddr == 0x1e4a) {
RCX.LCD.clearSegment(a1);
}
//reset two byte timer
//a1: who the hell knows?
else if (aAddr == 0x339a) {
//TODO: figure out what the hell this is
}
}
//simulates behavior when call to RCX's rom
public static void call(short aAddr, short a1, short a2) {
//readButtons call
//a2: pointer address; place to store the button that is pressed
if (aAddr == 0x1fb6 && a1 == Opcodes.BUTTONS_READ) {
short buttonState = Button.readButtons();
RCX.Memory.writeShort(a2, buttonState);
}
//systemSound call
//a2: 0 = short beep 1 = double beep 2 = descending arpeggio 3 = ascending arpeggio
// 4 = long low beep 5 = quick ascending arpeggio
else if (aAddr == 0x299a) {
if (a1 == Opcodes.SOUND_QUEUED) {
RCX.Sound.systemSound(true, (int)a2);
}
else if (a1 == Opcodes.SOUND_UNQUEUED) {
RCX.Sound.systemSound(false, (int)a2);
}
}
//getVoltageInternal call
//a2: pointer address; place where to store the voltage
else if (aAddr == 0x29f2 && a1 == Opcodes.POWER_BATTERY) {
RCX.Memory.writeShort(a2, (short)RCX.batteryVoltage);
}
}
The New Robotran and Simulator: The New Robotran and Simulator
Near future improvements: Near future improvements Simulator
Permit collision detection with the walls
Permit building obstacles that the robot can bump into
Permit building a black line path on the ground for light following
Permit a light source to simulate a flashlight that the robot’s light sensor can detect
Better Robolang parser and error messages
Our experience: Our experience Students in early courses that use only Robolang like it
They can implement very complex algorithms quickly
They participated in a local robot competition and did well
Those who went on to CSC 111 seemed to appreciate the link and made the transition to Lejos/Java well
Surveys and anecdotal evidence indicate high level of satisfaction
After first robot lab: “I actually got a robot to do something!”
No statistical difference in final grades between non-robot and robot years in CSC 111
Student Reactions to AI: Student Reactions to AI Some students who are not very interested in computer science find AI fascinating
The interest in AI helps motivate them in robot programming tasks
Students are able to make connections between the very simple systems they are using and extremely complex robots such as the Honda Asimo
Students appreciate the difficulty of unsolved AI problems such as vision
The cultural perception of programmers is negative and boring a la “Office Space”, but roboticists are viewed as interesting and “sexy”
Our focus: the students: Our focus: the students
Future Plans: Future Plans Test the use of programming language structures’ effect on task completion time
Test the ease of adjustment to a harder language
Continue to track recruitment and retention (problem with small sample size at smaller colleges)
Port to the NXT
Teach an honors science elective that is heavily liberal arts and is focused on AI and robotics
Develop a cross-disciplinary minor in AI/robotics that will draw a larger audience into computer science courses
Of course, debug, Debug, DEBUG!
Have fun!