Top Banner
LEGO Mindstorms NXT LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Miha Štajdohar Anjum Gupta Anjum Gupta Group: Roanne Manzano Group: Roanne Manzano Eric Tsai Eric Tsai Jacob Robison Jacob Robison SOURCES: SOURCES:
51

LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Dec 18, 2015

Download

Documents

Violet Ferguson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

LEGO Mindstorms NXTLEGO Mindstorms NXT

Carnegie Mellon Gabriel J. FerrerDactaLegoTimothy FriezMiha Štajdohar Anjum GuptaAnjum GuptaGroup: Roanne ManzanoGroup: Roanne ManzanoEric TsaiEric TsaiJacob RobisonJacob Robison

SOURCES:SOURCES:

Page 2: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Introductory Introductory programming programming

robotics projectsrobotics projects• Developed for a zero-prerequisite course• Most students are not ECE or CS majors• 4 hours per week

– 2 meeting times– 2 hours each

• Students build robot outside class

Page 3: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Beginning activities

• Bridge• Tower• LEGO Man• Organizing Pieces• Naming Pieces• Programming Robot People• Robots by instructions

Page 4: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Teaching Ideas

• Teach mini-lessons as necessary• Gears- Power vs. Speed • Transmission of energy/motion• Using fasteners• Worm Gears• Building with bricks vs. building machines

These spin:

These don’t:

Page 5: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 1: Motors and Project 1: Motors and Sensors (1)Sensors (1)

• Introduce motors– Drive with both motors forward for a fixed time– Drive with one motor to turn– Drive with opposing motors to spin

• Introduce subroutines– Low-level motor commands get tiresome

• Simple tasks– Program a path (using time delays) to drive through

the doorway

Page 6: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

First Project (2)

• Introduce the touch sensor– ifif statements statements

• Must touch the sensor at exactly the right time

– whilewhile loops loops• Sensor is constantly monitored

• Interesting problem– Students try to put code in the loop body

• e.g. set the motor power on each iteration

– Causes confusion rather than harm

Page 7: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

First Project (3)

• Combine infinite loops with conditionals

• Enables programming of alternating behaviors– Front touch sensor hit => go backward– Back touch sensor hit => go forward

• Braitenberg vehicles and state-machine based robots

Page 8: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 2: Mobile robot and Project 2: Mobile robot and rotation sensors (1)rotation sensors (1)

• Physics of rotational motion

• Introduction of the rotation sensors– Built into the motors

• Balance wheel power– If left counts < right counts

• Increase left wheel power

• Race through obstacle course

Page 9: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Second Project (2)if (/* Write a condition to put here */) { nxtDisplayTextLine(2, "Drifting left"); } else if (/* Write a condition to put here */) { nxtDisplayTextLine(2, "Drifting right"); } else { nxtDisplayTextLine(2, "Not drifting"); }

Complete this code with various conditions and various motions

Page 10: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 3Project 3

Line Line FollowingFollowing

Page 11: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Line Following1. Use light sensors to follow a line in the least

time2. Design and programming challenge3. Uses looping or repeating programs4. Robots appear to be ‘thinking’

Page 12: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

The „line following” project

1. Objectives :2. Build a mobile robot and program it to follow a

line3. Make the robot go „as fast as possible”

4. Challenges :5. Different lines (large, thin, continuous, with gaps,

sharp turns, line crossings, etc…)6. Control algorithms for 1, 2 and 3 sensors7. Real time, changing environment8. Learning, adaptation9. Fault tolerance, error recovery

Page 13: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Different control algorithms for different lines (large and thin line)

RC

X

RC

X

RC

X

RC

X

RC

X

RC

X

Page 14: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Different control algorithms for 1 and 3 sensors…

RC

X

RC

X

RC

X

RC

X

RC

X RC

X

RC

X

Page 15: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

The used techniques and knowledge (1)

Real time constraints appear when the robot goes „as fast as possible” :

• Sensor reading and information processing speed

• Motor-robot inertia, wheel slipping…

Fault tolerant, error recovery techniques are used when :

• Unreliable sensor values• Inaccurate surface• Loosing the line…

Page 16: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

The used techniques and knowledge (2)

Initial calibration and adaptation are used in the „changing environment” :

• Changes in the light intensity of the line (room lamps, robot shade, …)

• Battery’s charge…

„Learning” techniques can be used to determine : • How fast the robot can go (acceleration on long

straight lines)• How sharply the robot should turn• How to avoid endless repetitions

Page 17: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Educational benefits of the „line following” project

Students confronted, used and learned :

• Real time constraints

• Robust, fault tolerant control algorithms

• Error „recovery” techniques

• Robot’s learning and adaptation to the changing environment

Page 18: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

The ChallengesThe Challenges

Page 19: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 4: Drawing Project 4: Drawing robotrobot

• Pen-drawer– First project with an effector– Builds upon lessons from previous projects

• Limitations of rotation sensors– Slippage problematic– Most helpful with a limit switch

• Shapes (Square, Circle)• Word (“LEGO

Page 20: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Pen-Drawer Robot

Page 21: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Pen-Drawer Robot

Page 22: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 5: Finding Project 5: Finding objects (1)objects (1)

• Finding objects

• Light sensor– Find a line

• Sonar sensor– Find an object– Find free space

Page 23: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Fourth Project (2)

• Begin with following a line edge– Robot follows a circular track– Always turns right when track lost– Traversal is one-way

• Alternative strategy– Robot scans both directions when track lost– Each pair of scans increases in size

Page 24: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Fourth Project (3)

• Once scanning works, replace light sensor reading with sonar reading

• Scan when distance is short– Finds freespace

• Scan when distance is long– Follow a moving object

Page 25: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Light Sensor/Sonar Robot

Page 26: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Other Projects with mobile robotsOther Projects with mobile robots1. “Theseus”

– Store path (from line following) in an array– Backtrack when array fills

2. Robotic forklift– Finds, retrieves, delivers an object

3. Perimeter security robot– Implemented using RCX– 2 light sensors, 2 touch sensors

4. Wall-following robot– Build a rotating mount for the sonar

5. Quantum Braitenberg Robots of Arushi Raghuvanshi

6. Maze Robots of Stefan Gebauer and Fuzzy robots of Chris Brawn

Page 27: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Robot Forklift

Page 28: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Gearing the motors

Page 29: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 6: Fuzzy LogicProject 6: Fuzzy Logic

• Implement a fuzzy expert system for the robot to perform a task

• Students given code for using fuzzy logic to balance wheel encoder counts

• Students write fuzzy experts that:– Avoid an obstacle while wandering– Maintain a fixed distance from an object

Page 30: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Fuzzy Rules for Balancing Rotation Counts

• Inference rules:– biasRight => leftSlowbiasRight => leftSlow– biasLeft => rightSlowbiasLeft => rightSlow– biasNone => leftFastbiasNone => leftFast– biasNone => rightFastbiasNone => rightFast

• Inference is trivial for this case– Fuzzy membership/defuzzification is more

interesting

Page 31: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Fuzzy Membership Functions

• Disparity = leftCount - rightCount• biasLeft is

– 1.0 up to -100– Decreases linearly down to 0.0 at 0

• biasRight is the reverse• biasNone is

– 0.0 up to -50– 1.0 at 0– falls to 0.0 at 50

Page 32: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Defuzzification

• Use representative values:– Slow = 0– Fast = 100

• Left wheel:Left wheel:– (leftSlow * repSlow + leftFast * repFast) / (leftSlow +

leftFast)

• Right wheelRight wheel is symmetric

• Defuzzified values are motor power levels

Page 33: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 7. Q-LearningProject 7. Q-Learning• Discrete sets of states and actions– States form an N-dimensional

array• Unfolded into one dimension in

practice

– Individual actions selected on each time step

• Q-valuesQ-values– 2D array (indexed by state and

action)– Expected rewards for performing

actions

Action1= strike

action2 action3 action4

State happy 0.3

State unhappy

State angry

State hungry

State bored

Q-valuesQ-values

Page 34: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Q-Learning Main Loop

1. Select action2. Change motor speeds3. Inspect sensor values

1. Calculate updated state2. Calculate reward

4. Update Q values5. Set “old state” to be the updated state

Page 35: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Calculating the State (Motors)

• For each motor:– 100% power– 93.75% power– 87.5% power

• Six motor states

Page 36: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Calculating the State (Sensors)

• No disparity: STRAIGHT

• Left/Right disparity– 1-5: LEFT_1, RIGHT_1– 6-12: LEFT_2, RIGHT_2– 13+: LEFT_3, RIGHT_3

• Seven total sensor states

• 63 states overall

Page 37: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Action Set for Balancing Rotation Counts

• MAINTAIN– Both motors unchanged

• UP_LEFT, UP_RIGHT– Accelerate motor by one motor state

• DOWN_LEFT, DOWN_RIGHT– Decelerate motor by one motor state

• Five total actions

Page 38: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Action Selection

• Determine whether action is random– Determined with probability epsilon– If random:

• Select uniformly from action set

– If not random:• Visit each array entry for the current state• Select action with maximum Q-value from current

state

Page 39: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Calculating Reward

• No disparity => highest value

• Reward decreases with increasing disparity

Page 40: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Updating Q-values

Q[oldState][action] =

Q[oldState][action] +

learningRate *

(reward + discount * maxQ(currentState) - Q[oldState][action])

Page 41: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Student Exercises

• Assess performance of wheel-balancer

• Experiment with different constants– Learning rate– Discount– Epsilon

• Alternative reward function– Based on change in disparity

Page 42: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Learning to Avoid Obstacles

• Robot equipped with sonar and touch sensor

• Hitting the touch sensor is penalized

• Most successful formulation:– Reward increases with speed– Big penalty for touch sensor

Page 43: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Other classroom possibilities

• Operating systems– Inspect, document, and modify firmware

• Programming languages– Develop interpreters/compilers– NBC an excellent target language

• Supplementary labs for CS1/CS2

Page 44: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Project 8. Project 8. Sumo and similar Sumo and similar

fighting fighting competitionscompetitions

Page 45: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

The Tug O’ War

• Robots pull on opposite ends of a 2 foot string

• There are limits on mass,motors, and certain wheels

• Teaches integrity, torque, gearing, friction

• Good challenge for beginners

• Very little programming

Page 46: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Drag Race

• Least amount of time to cross a set distance• Straight, light fast designs• Teaches gearing, efficiency• Nice contrast to Tug O’ War• Little programming

Page 47: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Sprint Rally

• Cross the table and return, attempting to stay within the designated path.

• Challenging programming• Possibly uses sensors• Teaches precision,

programming logic, prediction

Page 48: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Sumo-AutonomousSumo-Autonomous

• Robots push each other out of the ring• A ‘real’ competition• Require light sensors• Encourages efficient, robust designs• Power isn’t everything• Designs must predict unknown opponents

Page 49: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Sumo-Remote• Uses another RCX or tethered sensors to

control• Do not use Mindstorms remote• Like BattleBots• Still requires programming• Driver skill is a factor

Page 50: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Other Challenge Other Challenge PossibilitiesPossibilities

• Weight lifting, obstacle course, tightrope walking, soccer, maze navigation, Dancing, golf, bipedal locomotion, tractor pull, and many more

• Cooperative Robots• Component Design• Time-limited robot design• See the website, find more on the internet, or create

your own• Create Specific rules• Predict loopholes

Page 51: LEGO Mindstorms NXT Carnegie Mellon Gabriel J. Ferrer Dacta Lego Timothy Friez Anjum Gupta Miha Štajdohar Anjum Gupta Group: Roanne Manzano Eric Tsai Jacob.

Final Notes

• Slides available on-line:– http://ozark.hendrix.edu/~ferrer/presentations/

• Make sure to check back with www.robotc.net for updates and support.

• Join the robotc.net forums at www.robotc.net/forums

• www.chiefdelphi.com – useful community website for getting all other FIRST related questions answered

• Any questions: Post to forums, or e-mail me at [email protected]