Robolab Tutorial
Steve Dakin Hacienda Robotics sdakin@sdakin.com
Introduction
Target audience
Coaches and parents of kids in the FIRST LEGO League program
Objectives
Overview of Robolab programming environment and concepts Some tips and tricks acquired over the years Help you so that you can better help your kids
Contents
Setting up Robolab
Administrator area, Robolab settings, RCX settings
Beginner Topics
Writing programs, Basic control blocks (motors, waits, modifiers), Conditionals (forks, resets)
Intermediate Topics
Flow control (jumps, loops), Variables (containers), LEGO MINDSTORMS Remote Control
Advanced Topics
Subroutines, Sub VIs, Data logging (Investigator)
Robolab Main Menu
Administrator Screen
Robolab Settings
RCX Settings
Select Program
New Program
Programming Strategy
Define what you want the program or robot to do Identify high-level tasks Write pseudo-code (in pseudo-English) Use pseudo-code as comments to define program skeleton Divide and conquer Program in pairs: pilot and co-pilot
Functions Palette
Function Sub-palettes and the Tools Palette
Writing Robolab Programs
Four ways to add blocks to a program:
Functions palette Context menu Insert command Replace command
Use auto-wiring tool Connection point introspection Block arrangement commands Include Comments
Modifiers
Two types of modifiers
Reference Value-of
Reference modifiers specify the where Value-of modifiers specify the what Not very intuitive, but with practice and use of the online help choosing the right modifier gets easier. Can connect multiple blocks to same modifier
Modifiers Program
Reset the rotation sensor on port 1 Turn on motors on ports A and C Wait until touch sensor on port 2 is pressed Stop motors on ports A and C Display the value of port 2 on the RCX
Conditionals and Resets
Robolab term: forks Used to branch the flow of execution in your program Usually associated with sensors Every fork must have a corresponding merge Nested forks can be tricky In some situations you may need to reset sensors before using them
Conditional and Reset Program
This program demonstrates one way of using a single RCX program slot to run two different programs. Start with a robot containing a downward facing light sensor. Next, find a brick that is sufficiently different in color than the mat area in base. The blue container will contain 1 if you use the brick, 0 otherwise. In your main program you can use a fork that branches depending on the value in the blue container.
Flow Control
Robolab terms: jumps and loops Used to repeat a portion of your program Can be controlled with sensors, containers or other factors
Variables
Robolab term: containers Containers hold values that can change during the execution of a program 23 value containers, including 3 defaults:
0 = red container 1 = blue container 2 = yellow container
25 Task containers Good tool for teaching abstraction
Advanced Containers
Formula container
Sets a container value based on a formula Supports basic arithmetic expressions and shorthand mnemonics for other values (containers, input ports, mail messages, etc.)
Containers container
Analogous to a pointer in traditional programming languages A modifier that specifies which container to use based on the value of another container
Advanced Container Program
As noted in the comment this program can be used to show container values on the RCXs display. Container 22 holds the number of the container to display (0, 1 or 2). Container 21 holds a computed value that shows the container number followed by its value. The program uses the formula container to multiply the value in container 22 by 1000 to move it to the left three places on the display. Next it adds the value of the container whose container number is specified in container 22 (this is accomplished using the containers container). The last block before the red jump displays the computed container value on the RCXs display.
LEGO Remote Control
Amazingly useful prototyping tool Send motor (output) commands to RCX Start and stop programs easily Send mail messages to RCX Best $20 you can spend on equipment
Subroutines
Analogous to subroutines in other programming languages Allow you to reuse code
Reduces program size Makes programs more robust
Define first then call as many times as youd like Another good tool for teaching abstraction
Subroutine Program
This program demonstrates how you can define two subroutines and call them from within your program based on the value in a container. By changing the value in the container you control which subroutine is called. This is a useful way to observe what your program is doing while it runs.
Sub VIs
VIs (Virtual Instruments) = programs Sub VIs are like program modules (libraries) Act like macros (code is repeated each time it is used) Improve readability
Can create your own icons for Sub VIs Only the Sub VI block appears in your main program
How to Create Sub VIs
Select the blocks you want in the Sub VI (to make input parameters to the Sub VI exclude modifiers) Select the Edit Create menu command Tidy up the Sub VI and include it in your programs
FLL Program (Two Missions)
Data Logging
Robolab and the RCX are a form of embedded device programming
Download and run Difficult to monitor and debug interactively
Data logging captures values while a program runs on the RCX Analyze captured data in the Investigator area
Data Logging in Robolab
Change Inventor level to Program Level 4 (adds an Investigator palette and specialized modifiers to the modifiers palette) Include blocks to initialize, start and stop data logging Run the program on the RCX Upload data to Robolab and analyze it in the Investigator area
Data Logging Program
Data logging modifiers Sample program
Initializes the red data set to capture data from the light sensor connected to port one Starts data logging and captures 1 data point every second until 10 data points are collected Stops data logging
Uploaded Data
Other Advanced Topics
Tasks
Enable your program to do multiple things at the same time
Events
Monitor and respond to specific conditions
Direct mode
Another way to prototype
LASM
A hackers delight
Questions and Comments
Please let me know what you think
Email: sdakin@sdakin.com Web: www.haciendarobotics.com/resources Tip: use Adobe Reader 7s commenting support
More info
www.legoeducation.com/sharedimages/resources/Mindstorms_Quickstart.pdf www.ceeo.tufts.edu/robolabatceeo/ www.ceeo.tufts.edu/robolabatceeo/References/documentation/default.asp