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, Andreas Rottmann 25.01.2011
LMHanoi - Tower of Overview Hanoi with Lego Mindstorms Basics 1 Basics The robot Software Inter-thread 2 The robot communication Application logic Robot controller Music 3 Software Experiment Inter-thread communication Application logic Robot controller Music 4 Experiment
LMHanoi - Tower of The puzzle Hanoi with Lego Mindstorms Basics • Move a set of disks from one rod to another The robot Software Inter-thread communication Application logic Robot controller Music Experiment
LMHanoi - Tower of The puzzle Hanoi with Lego Mindstorms Basics • Move a set of disks from one rod to another The robot Software Inter-thread communication Application logic Robot controller Music Experiment • With moving only ever one disk
LMHanoi - Tower of The puzzle Hanoi with Lego Mindstorms Basics • Move a set of disks from one rod to another The robot Software Inter-thread communication Application logic Robot controller Music Experiment • With moving only ever one disk • No larger disk may rest on a smaller one
LMHanoi - Tower of Lego Mindstorms Hanoi with Lego Mindstorms Basics The robot • Extends Lego with new building blocks: Software • Sensors Inter-thread communication • Motors Application logic Robot controller • Programmable computer Music Experiment • NXT 2.0: 32-bit ARM7 microprocessor, 64 kB RAM and 256 kB Flash memory • 4 input, 3 output ports • Bluetooth, USB • Sound
LMHanoi - Tower of ABuNQEUC 1 NXC Hanoi with Lego Mindstorms Not eXactly C Basics The robot Software Inter-thread communication • Free compiler to build Lego Mindstorms executables from Application logic Robot controller something similar to C Music Experiment • Somewhat documented • Several limitations, e.g., no recursion, no passing of mutexes as parameters • Workarounds require abusing the preprocessor 1 almost, but not quite, entirely unlike C
LMHanoi - Tower of The robot: Klaus Hanoi with Lego Mindstorms Basics The robot Software • Forklift Inter-thread communication • Can move along three axes Application logic Robot controller Music Experiment • Movement limited by sensors for two of them • Using touch and color sensors
LMHanoi - Tower of Hanoi with Lego Mindstorms Basics The robot Software Inter-thread communication Application logic Robot controller Music Experiment
LMHanoi - Tower of Software Hanoi with Lego Mindstorms Basics The robot MBox App. Logic Controller Software Inter-thread Global communication Variable Application logic Robot controller Music Experiment Music Robot Three threads • Application logic (Tower of Hanoi algorithm) • Robot controller • Music playback
LMHanoi - Tower of Inter-thread communication Hanoi with Lego Mindstorms NXC Primitives Basics • Mutex The robot Software Inter-thread communication Mailbox Application logic Robot controller Music 0 1 2 3 4 5 6 Experiment fill front • Circular buffer • Mutex (protects fill count and front pointer) • Two counting semaphores (full, empty)[1]
LMHanoi - Tower of Application logic Hanoi with Lego Mindstorms Basics The robot Software Inter-thread communication Application logic Robot controller Music • Determine movement sequence Experiment
LMHanoi - Tower of Recursive algorithm Hanoi with Lego Mindstorms Basics The robot Software void hanoi ( i n t n , rod source , rod help , rod dest ) { Inter-thread ( n > 0) { i f communication hanoi ( n − 1 , source , dest , help ) ; Application logic Robot controller move disk ( source , dest ) ; Music hanoi ( n − 1 , help , source , dest ) ; Experiment } }
LMHanoi - Tower of Recursive algorithm Hanoi with Lego Mindstorms Basics The robot Software void hanoi ( i n t n , rod source , rod help , rod dest ) { Inter-thread ( n > 0) { i f communication hanoi ( n − 1 , source , dest , help ) ; Application logic Robot controller move disk ( source , dest ) ; Music hanoi ( n − 1 , help , source , dest ) ; Experiment } } • 2 n − 1 moves
LMHanoi - Tower of Recursive algorithm Hanoi with Lego Mindstorms Basics The robot Software void hanoi ( i n t n , rod source , rod help , rod dest ) { Inter-thread ( n > 0) { i f communication hanoi ( n − 1 , source , dest , help ) ; Application logic Robot controller move disk ( source , dest ) ; Music hanoi ( n − 1 , help , source , dest ) ; Experiment } } • 2 n − 1 moves • Optimal movement sequence
LMHanoi - Tower of Iterative algorithm [2],[3] Hanoi with Lego Mindstorms Basics • Rods source, help and destination on a circle The robot Software • Even number of disks: ordered clockwise Inter-thread communication • Odd number of disks: ordered counterclockwise Application logic Robot controller Music Experiment
LMHanoi - Tower of Iterative algorithm [2],[3] Hanoi with Lego Mindstorms Basics • Rods source, help and destination on a circle The robot Software • Even number of disks: ordered clockwise Inter-thread communication • Odd number of disks: ordered counterclockwise Application logic Robot controller Music Experiment ( not a l l d i s k s on d e s t i n a t i o n rod ) { while move the s m a l l e s t d i s k one rod c l o c k w i s e ; ( a d i s k other than the s m a l l e s t can be moved ) { i f move t h i s d i s k ; } }
LMHanoi - Tower of Iterative algorithm [2],[3] Hanoi with Lego Mindstorms Basics • Rods source, help and destination on a circle The robot Software • Even number of disks: ordered clockwise Inter-thread communication • Odd number of disks: ordered counterclockwise Application logic Robot controller Music Experiment ( not a l l d i s k s on d e s t i n a t i o n rod ) { while move the s m a l l e s t d i s k one rod c l o c k w i s e ; ( a d i s k other than the s m a l l e s t can be moved ) { i f move t h i s d i s k ; } } • Same movement sequence
LMHanoi - Tower of Implementation Hanoi with Lego Mindstorms Basics The robot Software Inter-thread communication Application logic Robot controller • No support for recursion Music Experiment • Choose iterative algorithm
LMHanoi - Tower of Na¨ ıve implementation Hanoi with Lego Mindstorms Basics The robot Software help dest. source . . . dest. Inter-thread communication disk 1 2 3 . . . n Application logic Robot controller Music Experiment • Store the current location of each disk
LMHanoi - Tower of Na¨ ıve implementation Hanoi with Lego Mindstorms Basics The robot Software help dest. source . . . dest. Inter-thread communication disk 1 2 3 . . . n Application logic Robot controller Music Experiment • Store the current location of each disk • Space complexity: O ( n )
LMHanoi - Tower of Na¨ ıve implementation Hanoi with Lego Mindstorms Basics The robot Software help dest. source . . . dest. Inter-thread communication disk 1 2 3 . . . n Application logic Robot controller Music Experiment • Store the current location of each disk • Space complexity: O ( n ) • Time complexity per move: O ( n )
LMHanoi - Tower of Refined implementation Hanoi with Lego Mindstorms Basics source 3 The robot help 4 1 Software destination 5 2 Inter-thread communication Application logic Robot controller height: 1 2 2 Music source help dest. Experiment • Store the disks on each rod
LMHanoi - Tower of Refined implementation Hanoi with Lego Mindstorms Basics source 3 The robot help 4 1 Software destination 5 2 Inter-thread communication Application logic Robot controller height: 1 2 2 Music source help dest. Experiment • Store the disks on each rod • Store the height of each rod’s stack
LMHanoi - Tower of Refined implementation Hanoi with Lego Mindstorms Basics source 3 The robot help 4 1 Software destination 5 2 Inter-thread communication Application logic Robot controller height: 1 2 2 Music source help dest. Experiment • Store the disks on each rod • Store the height of each rod’s stack • Approximately three times as much memory
LMHanoi - Tower of Refined implementation Hanoi with Lego Mindstorms Basics source 3 The robot help 4 1 Software destination 5 2 Inter-thread communication Application logic Robot controller height: 1 2 2 Music source help dest. Experiment • Store the disks on each rod • Store the height of each rod’s stack • Approximately three times as much memory • Space complexity: O ( n )
LMHanoi - Tower of Refined implementation Hanoi with Lego Mindstorms Basics source 3 The robot help 4 1 Software destination 5 2 Inter-thread communication Application logic Robot controller height: 1 2 2 Music source help dest. Experiment • 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)
Recommend
More recommend