1chung robofest 2007 introduction to robolab workshop feb. 3, 2007 maurice tedder

46
1 chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder www.Robofest.net

Upload: justin-hogan

Post on 26-Mar-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

1chung

Robofest 2007 Introduction to RoboLab

Workshop

Feb. 3, 2007

Maurice Tedderwww.Robofest.net

Page 2: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

2chung

Student Assistant

• Emily Trudell and Joe Long• Sat. 9AM-12PM

Page 3: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

3chung

Agenda• Intro to RCX• Intro to RoboLab • 9 Class Missions (somewhat related

to the Robofest Game 2007)• Programming Tips

Page 4: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

4chung

LEGO MindStorms 101

Page 5: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

5chung

LEGO MindStorms® Overview – Robot Command Explorer (RCX/Brick)

Hitachi H8 16MHz 8-bit microcontroller with 32K ext. Ram

16K ROM contains power up driver

16K of firmware can be downloaded to extend the on-chip driver

User programs are downloaded to the RCX as byte code in 6K region of memory

Firmware executes and interprets the byte code of programs when instructed

Page 6: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

6chung

LEGO MindStorms® Overview – Robot Command Explorer (RCX/Brick)Infra-red (IR) Receiver Is a sensor that accepts the

program being transmitted from the IR tower. Also transmits data.

Sensor Input Ports Input ports 1, 2, & 3 are used to attach sensors to the RCX (0V/0 – 5V/1024 A/D)

View Button Used to obtain feedback from the input and output ports

On-Off Button Manually turn the RCX on and off

Motor (output) Ports Use output ports A-C to connect any combination of motors

LCD Display Display different values and information regarding the RCX and programs

AC/DC Power Input The RCX can be powered by plugging into a 9 Volt adapter (not for recharging batteries)

Program Button Used to switch between programs 1-5

Run Button Press the Run button to activate and run your current program

Speaker (not shown) Internal speaker indicates RCX status and acts as a programmable sound output

Page 7: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

7chung

What Is RoboLab?

• A ‘Graphical’ programming language For the RCX based on LabVIEW

• In 1997, LabView was used for Sojourner project

• By designing a flow chart with given icons the programmer can program the RCX

Page 8: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

8chung

Writing a new program

Click on the Programmer button.You should then see the Inventor login screen. Double click Inventor 4 to get full RoboLab environment.

Introduction to RoboLab – Programming Environment

Page 9: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

9chung

ROBOLAB Environment

• Set up your screen in Inventor 4 so that it looks like the screen to the right.

Page 10: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

10chung

ROBOLAB Environment

• There are two major pallets that contain most of the icons and commands you need to build a program.

• If you cannot see these pallets, you can find them under the Window -> Show drop down list.

Tools

Functions

Page 11: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

11chung

RoboLab Workspace

Functions Palette – Contains

Icons for all possible

RCX program

commands. Icons vary with Level

Tools Palette – Contains Icons for building a

program diagram in the RoboLab

workspace

Context Help –

When this window is

open it displays

Help information about the Function

Icon under the mouse

cursor

Example Program –

All programs begin with a Green light

and end with a Red light

Icon

Search – Click the Search tab to find a Function

Icon in the Functions palette

Menus

Sub Menu Icons – Icons with the right side black dot have sub

menuIcons

Page 12: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

12chung

Tools Palette

Operate Value tool: Change values in the Workspace window

Wire Tool: connect icons in your program from start to

finish

Set/Clear Breakpoint: allows you to suspend the execution of your program

Set Color Tool: allows you to set the colors of objects in the Panel and Diagram windows

Scroll Window Tool: move around in the Title or Workspace windows

Arrow Tool: move, delete, or place icons in workspace window

Automatic Tool Selection: Automatically senses correct

tool to use

Get Color Tool: allows you to copy a color from an image and use it as part of the color palette

Probe Data: allows you to check the program for values

Object Popup Tool: modify settings for

items in the Workspace window

Edit Text Tool: edit or insert text boxes

Page 13: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

13chung

RoboLab Programming Elements• Forks – equivalent to if/then selection

structures• Task – run multiple task simultaneously (8

max.)• Wait states – program execution will be

halted until the wait state condition is satisfied

• Loops – to create repetition structures in a program

• Subroutines – a segment of code that can be called repeatedly from another code segment (8 max./program slot)

• Events – jumps to the specific section of code when the specified event occurs

Page 14: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

14chung

RoboLab Capabilities I

Read Analog input values Output PWM on the output ports Subroutines Multitasking Event monitoring Multimedia Image/sound processing and

capture Access all RCX Brick input/output

interfaces (buttons, LCD screen, etc.) Music and sound functions

Page 15: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

15chung

RoboLab Capabilities II

Data logging (2000 pts. @ 100Hz) and processing functions using G-Code (can compute basic statistics to derivatives and integrals)

Basic Logic and Math functions Variables (47 total, 22 user variables) IR Communication functions Direct program control functions Internet functions User defined libraries LASM functions (LEGO assembly language) Control lab interface functions

Page 16: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

16chung

Pros to Using RoboLab

• Easy to see control structure• Visual interface is simple• Exactly like LabVIEW• Data gathering and visualization

(investigator)

Page 17: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

17chung

Cons to Using RoboLab

• Spaghetti code• Hard to wire icons…• No edge triggering supported

Page 18: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

18chung

For More Information

• LEGO’s Pagewww.lego.com/dacta/robolab

• National Instruments Pagewww.ni.com/robolab

• Tufts Universitywww.ceeo.tufts.edu/graphics/robolab

• www.lego.com/education/mindstorms/images/eng/downloads/compare.doc

Page 19: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

19chung

What is a computer program?

A list of instructions created by a computer programmer (you) that tell a computer what to do next

Your job as a computer programmer is to: Decide how to get from point A

to point B using a bag of tricks (instructions)

For the LEGO Robot, instructions = Picture Icons connected together to form a program

•A (what I want the program to do)

•B(program doing what I want it to do)

LEGO RoboLab Function Icon

Palette

Page 20: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

20chung

An Introduction to Structured Programming(or How to get from point A to point B) Structured programming philosophy states that all

programs can written using only three single entry/single exit control structures

1. Sequence structure: is built into RoboLab and means that statements are executed sequentially one after another as along the chain of connected icons

2. Selection structure: chooses between alternative courses of action (makes yes or no decisions)

3. Repetition structure: tells which actions are to be repeated while some condition is true

Programs are built in structured programming by stacking and/or nesting as many control structure building blocks as needed to solve the problem

Page 21: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

21chung

RoboLab Control Structures

SequenceLoop/Repetition : Decision: Fork

Subroutines:Multitasking:

Page 22: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

22chung

Ex 1: Go forward 2 seconds and come back by reversing motors

Page 23: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

23chung

Making Turns

• Turn left:

• Spin left: (point turn)

• Face left:Left wheel

Left wheel

Right wheel

Right wheel

Left wheel Right wheel

stop

stop

Page 24: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

24chung

Ex 2: Go forward 1.5 seconds and come back by spinning left

• Spinning 180 degrees?• Is it accurate?

Page 25: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

25chung

Tips• How to insert icons?• How delete icons?• How to save programs?• How to use the Icon search feature?• Cover the tower and RCX when

downloading, if more than one robot in a room!

• Use Meaningful file names• Add Comments using “A: edit text”

Page 26: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

26chung

Sensors•Light•Touch• Rotation • Temperature• Timer – Internal sensor• RCX buttons

Page 27: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

27chung

Light Sensor

• Percent mode 5% - lowest dark 100% - very bright

• Reflected light mode: shines a red light

• Use View Button

Page 28: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

28chung

Light Sensor Readings

Source: HighTechKids.org

Page 29: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

29chung

Attach a Light Sensor

• Facing down• Gap: around 1 cm (What will be the

problem if less than 1 cm to solve the Miner Rescue problem?)

• Port No. 1

Page 30: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

30chung

Ex 3. Go straight until the edge of the table is detected. Then stop the robot

Page 31: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

31chung

Stop when it sees the black line on the Miner Rescue field• Measure and record the following

values White shelf Black line Foil Outside Edge Start of the ramp from the miner field

and the home base: why? The big gap!

• Suggested to lower the power level move down slowly

Page 32: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

32chung

The gap between the Light sensor and the floor!!!• Both Reflected and Ambient light

values are affected by the distance between the sensor and the floor!

• The light sensor value is in inverse proportion to the gap

Lightsensor

Lightsensor

Page 33: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

33chung

Stop when it sees the black line on the Miner Rescue field

Page 34: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

34chung

Ex 4. Stop when it sees the 2nd black line on the Miner Rescue field

What went wrong?

Page 35: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

35chung

How about stopping at the 4th line?• Loop (Repeat)

Block

Page 36: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

36chung

Touch Sensor

• If released (not pressed): 0• If pressed: 1• Is it very sensitive?

Page 37: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

37chung

Attach a Touch Sensor

• Port No. 2

Page 38: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

38chung

Ex. 5 Loop until a touch sensor is pressed

Display seconds until touch sensor is pressed.

Page 39: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

39chung

Line following - Zigzag methods

Page 40: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

40chung

Ex 6. Follow the black line until a touch sensor is pressed

Page 41: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

41chung

Ex 7. Follow the line until it detects the foil

• Need max power to climb

Page 42: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

42chung

Ex 8. Follow the line until it climbs back to the home base

Page 43: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

43chung

Ex 9. Follow the line until it climbs back to the home base – Use Subroutines

Page 44: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

44chung

Not covered advanced topics

• Variables

• Multiple tasks & Synchronization of multiple tasks

• …

Page 45: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

45chung

Tips for Robofest 2007 Game

•Line following may be needed for RCX

• Light sensor needed for detecting balls in the tunnel or edge

Page 46: 1chung Robofest 2007 Introduction to RoboLab Workshop Feb. 3, 2007 Maurice Tedder

46chung

Tips for RoboSumo

• Light Sensor to detect the ring edge

• Touch sensor to detect the opponent

• Theories in physics