LMHanoi - Tower of Hanoi with Lego Software Mindstorms - - PowerPoint PPT Presentation

lmhanoi tower of hanoi with lego
SMART_READER_LITE
LIVE PREVIEW

LMHanoi - Tower of Hanoi with Lego Software Mindstorms - - PowerPoint PPT Presentation

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot LMHanoi - Tower of Hanoi with Lego Software Mindstorms Inter-thread communication Application logic Robot controller Music Experiment Markus Flatz, Peter Palfrader,


slide-1
SLIDE 1

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

LMHanoi - Tower of Hanoi with Lego Mindstorms

Markus Flatz, Peter Palfrader, Andreas Rottmann 25.01.2011

slide-2
SLIDE 2

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Overview

1 Basics 2 The robot 3 Software

Inter-thread communication Application logic Robot controller Music

4 Experiment

slide-3
SLIDE 3

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

The puzzle

  • Move a set of disks from one rod to another
slide-4
SLIDE 4

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

The puzzle

  • Move a set of disks from one rod to another
  • With moving only ever one disk
slide-5
SLIDE 5

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

The puzzle

  • Move a set of disks from one rod to another
  • With moving only ever one disk
  • No larger disk may rest on a smaller one
slide-6
SLIDE 6

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Lego Mindstorms

  • Extends Lego with new building blocks:
  • Sensors
  • Motors
  • Programmable computer
  • NXT 2.0: 32-bit ARM7 microprocessor, 64 kB RAM and

256 kB Flash memory

  • 4 input, 3 output ports
  • Bluetooth, USB
  • Sound
slide-7
SLIDE 7

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

ABuNQEUC1 NXC Not eXactly C

  • Free compiler to build Lego Mindstorms executables from

something similar to C

  • Somewhat documented
  • Several limitations, e.g., no recursion, no passing of

mutexes as parameters

  • Workarounds require abusing the preprocessor

1almost, but not quite, entirely unlike C

slide-8
SLIDE 8

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

The robot: Klaus

  • Forklift
  • Can move along three axes
  • Movement limited by

sensors for two of them

  • Using touch and color

sensors

slide-9
SLIDE 9

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

slide-10
SLIDE 10

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Software

  • App. Logic

Controller Music

MBox Global Variable

Robot

Three threads

  • Application logic (Tower of Hanoi algorithm)
  • Robot controller
  • Music playback
slide-11
SLIDE 11

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Inter-thread communication

NXC Primitives

  • Mutex

Mailbox

6 5 4 3 2 1

front fill

  • Circular buffer
  • Mutex (protects fill count and front pointer)
  • Two counting semaphores (full, empty)[1]
slide-12
SLIDE 12

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Application logic

  • Determine movement sequence
slide-13
SLIDE 13

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Recursive algorithm

void hanoi ( i n t n , rod source , rod help , rod dest ) { i f ( n > 0) { hanoi ( n − 1 , source , dest , help ) ; move disk ( source , dest ) ; hanoi ( n − 1 , help , source , dest ) ; } }

slide-14
SLIDE 14

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Recursive algorithm

void hanoi ( i n t n , rod source , rod help , rod dest ) { i f ( n > 0) { hanoi ( n − 1 , source , dest , help ) ; move disk ( source , dest ) ; hanoi ( n − 1 , help , source , dest ) ; } }

  • 2n − 1 moves
slide-15
SLIDE 15

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Recursive algorithm

void hanoi ( i n t n , rod source , rod help , rod dest ) { i f ( n > 0) { hanoi ( n − 1 , source , dest , help ) ; move disk ( source , dest ) ; hanoi ( n − 1 , help , source , dest ) ; } }

  • 2n − 1 moves
  • Optimal movement sequence
slide-16
SLIDE 16

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Iterative algorithm [2],[3]

  • Rods source, help and destination on a circle
  • Even number of disks: ordered clockwise
  • Odd number of disks: ordered counterclockwise
slide-17
SLIDE 17

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Iterative algorithm [2],[3]

  • Rods source, help and destination on a circle
  • Even number of disks: ordered clockwise
  • Odd number of disks: ordered counterclockwise

while ( not a l l d i s k s

  • n

d e s t i n a t i o n rod ) { move the s m a l l e s t d i s k

  • ne

rod c l o c k w i s e ; i f ( a d i s k

  • ther

than the s m a l l e s t can be moved ) { move t h i s d i s k ; } }

slide-18
SLIDE 18

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Iterative algorithm [2],[3]

  • Rods source, help and destination on a circle
  • Even number of disks: ordered clockwise
  • Odd number of disks: ordered counterclockwise

while ( not a l l d i s k s

  • n

d e s t i n a t i o n rod ) { move the s m a l l e s t d i s k

  • ne

rod c l o c k w i s e ; i f ( a d i s k

  • ther

than the s m a l l e s t can be moved ) { move t h i s d i s k ; } }

  • Same movement sequence
slide-19
SLIDE 19

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Implementation

  • No support for recursion
  • Choose iterative algorithm
slide-20
SLIDE 20

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Na¨ ıve implementation

help dest. source . . . dest. disk 1 2 3 . . . n

  • Store the current location of each disk
slide-21
SLIDE 21

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Na¨ ıve implementation

help dest. source . . . dest. disk 1 2 3 . . . n

  • Store the current location of each disk
  • Space complexity: O(n)
slide-22
SLIDE 22

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Na¨ ıve implementation

help dest. source . . . dest. disk 1 2 3 . . . n

  • Store the current location of each disk
  • Space complexity: O(n)
  • Time complexity per move: O(n)
slide-23
SLIDE 23

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Refined implementation

source 3 help 4 1 destination 5 2 height: 1 2 2 source help dest.

  • Store the disks on each rod
slide-24
SLIDE 24

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Refined implementation

source 3 help 4 1 destination 5 2 height: 1 2 2 source help dest.

  • Store the disks on each rod
  • Store the height of each rod’s stack
slide-25
SLIDE 25

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Refined implementation

source 3 help 4 1 destination 5 2 height: 1 2 2 source help dest.

  • Store the disks on each rod
  • Store the height of each rod’s stack
  • Approximately three times as much memory
slide-26
SLIDE 26

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Refined implementation

source 3 help 4 1 destination 5 2 height: 1 2 2 source help dest.

  • Store the disks on each rod
  • Store the height of each rod’s stack
  • Approximately three times as much memory
  • Space complexity: O(n)
slide-27
SLIDE 27

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Refined implementation

source 3 help 4 1 destination 5 2 height: 1 2 2 source help dest.

  • Store the disks on each rod
  • Store the height of each rod’s stack
  • Approximately three times as much memory
  • Space complexity: O(n)
  • Time complexity per move: O(1)
slide-28
SLIDE 28

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Robot controller (1)

General structure

  • Get movements from mailbox and execute them
  • Maintains current position
  • Wagon position stops on color sensor readings
  • Fork vertical movement stops on touch sensor
  • Fork moves horizontally by fixed amount
slide-29
SLIDE 29

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Robot controller (2)

Specialties

  • Overshoot

T arget Position Sensor Path

slide-30
SLIDE 30

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Robot controller (2)

Specialties

  • Overshoot

T arget Position Sensor Path

  • Use raw mode of color sensor to detect blue
slide-31
SLIDE 31

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Music

  • Additional concurrency
slide-32
SLIDE 32

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Music

  • Additional concurrency
  • Situational
slide-33
SLIDE 33

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Experiment

duration(n) = (2n − 1) · d + c

slide-34
SLIDE 34

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Experiment

duration(n) = (2n − 1) · d + c

100 200 300 400 500 1 2 3 4 5 duration [s] number of disks ’lmhanoi.dat’ expreg(x)

slide-35
SLIDE 35

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Experiment

duration(n) = (2n − 1) · d + c

100 200 300 400 500 1 2 3 4 5 duration [s] number of disks ’lmhanoi.dat’ expreg(x)

expreg(x) = (e0.693·x − 1) · 23.2 + 12.7

slide-36
SLIDE 36

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

References

John A. Trono and William E. Taylor. Further comments on “a correct and unrestrictive implementation of general semaphores”. SIGOPS Oper. Syst. Rev., 34:5–10, July 2000. Wikipedia. Tower of Hanoi – Wikipedia, The Free Encyclopedia, 2011. https://secure.wikimedia.org/wikipedia/en/w/ index.php?title=Tower_of_Hanoi&oldid=407310252. Wikipedia. T¨ urme von Hanoi – Wikipedia, Die freie Enzyklop¨ adie, 2011. https: //secure.wikimedia.org/wikipedia/de/w/index. php?title=T%C3%BCrme_von_Hanoi&oldid=83701385.

slide-37
SLIDE 37

LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software

Inter-thread communication Application logic Robot controller Music

Experiment

Thank you for your attention.