Upgrade to Pro — share decks privately, control downloads, hide ads and more …

4 VIPLE FSM and Maze Programming

4 VIPLE FSM and Maze Programming

2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班

shadowkael

July 19, 2016
Tweet

More Decks by shadowkael

Other Decks in Education

Transcript

  1. 1 物联网和机器人导论 VIPLE工作流编程 Introduction to IoT and Robotics, based on

    Visual Programming Experiments Yinong Chen Arizona State University, U.S.A. 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Lectures of the Course 2 http://neptune.fulton.ad.asu.edu/VIPLE/ Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 3 Lecture Outline Garage Door Opener 3 Drive-by-Wire in Simulated Maze 4 Vending Machine 2 Finite State Machine for Software Design 1 Autonomous Maze Navigation Algorithms 5 Other Visual Programming Environments 6 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 4 Finite State Machine (FSM)  A Finite State Machine (FSM) is a mathematical model consisting of a finite number of states, transitions between states, inputs, and outputs.  An input causes a transition from one to another state  An output is associated with a state and an input  As a programming model, FSMs are best to be applied to respond to a sequence of inputs (events), such as  Coin insertion into a vending machine;  Timer expires for traffic lights  Mouse-clicks/key strikes during a program’s execution  Arrival of individual characters from a string Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 5 A Classic Application of FSM: Vending Machine • Soda costs 40 cents • Possible inputs: Nickel, Dime, Quarter • Not all “return” transitions are shown 10 0 dime 20 30 40 50 25 5 15 35 dime nickel quarter dime nickel quarter dime nickel soda dime dime nickel nickel 45 nickel nickel nickel nickel dime soda soda return return return soda soda nickel Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 6 FSM with Variable • Allowing additional variables for storing values quarter dollar Sum = Sum + 25 Sum = Sum + 100 quarter dollar soda If (Sum== 75) release soda return If (Sum>75) Sum = Sum – 75 release soda If Sum < 75, do nothing 0 > 0
  2. 2 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 7 VIPLE Implementation

    of the Vending Machine Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 8 N E S W FSMs are used for designing hardware and software For example: • Sequential circuit design; • Parity generation in storage and communication; • Parentheses matching in expressions; • Garage door controller; • Traffic lights controller. NS green EW red NS yellow EW red NS red EW green NS red EW yellow Timer 1 Timer 2 Timer 3 Timer 4 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 9 • When the system is simple, e.g., with two to four states, we may not need to explicitly use an FSM • When the system becomes more complex, it is harder without using FSM. • For example, design the controller for this traffic lights: Design controller for this traffic controller Traffic Lights by Canary Wharf Tower, East London FSMs are often used for Traffic Lights System Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Use FSM to design a garage door control system Open Close 10 No states required Required states. When button pressed: If state==open then close else open Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Use FSM to design a garage door control systems If the door is closed and the button is pressed (touch sensor), the door begins to move up. When it reaches the top, the door activates a limit switch (a touch sensor) and stops. If the door is open and the button is pressed, the door begins to move down. When it reaches the bottom, the door activates another limit switch and stops. 11 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Use FSM to design a garage door control systems A garage door opener system garage door controller motor door block diagram limit switch touch sensor button ...we want to design the controller... 12
  3. 3 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Use FSM to

    design a garage door control systems A garage door opening system states - door closed - door open - door closing - door opening events - button press - limit switch touched (closing finished or opening finished) 13 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Use FSM to design a garage door control systems door closing door opened button pressed door closed door opening button pressed limit tripped limit tripped stopped button pressed button pressed button pressed 14 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Use FSM to design a garage door control systems button pressed door closing door opened door closed door opening button pressed limit tripped limit tripped opening stopped button pressed closing stopped button pressed button pressed button pressed 15 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 16 VIPLE Implementation if the Garage Door Opener Six states Button as input Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Drive-by-Wire Simulation 17 Key Press Events Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Unity Simulator Configuration 18 Right Click The simulator has two distance sensors, in the front and on the right.
  4. 4 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Maze Navigation Algorithms

    19 DistanceMeasured < 1 Turning Left Turned Left leftFinished Spin 180 DistanceMeasured < 2 DistanceMeasured >= 2 Spin180 Finished Start Forward • Greedy Algorithm: Take the first working solution Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Maze Navigation Algorithms 20 • Local Best: Measure two distances and choose the direction with the longer distance DistanceMeasured < 1 Turned Right Turned Left rightFinished Resume 180 DistanceMeasured < rightDistance Turning Right Turning Left leftFinished DistanceMeasured >= rightDistance Resum180 Finished Start RightDistance  DistanceMeasured Forward Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Maze Navigation Algorithms 21 Forward Start Turning Right90 RightDistance > BaseDistance + 1 Turned Right rightFinished Turning Left90 Turned Left leftFinished FrontSensorDistance < 1 Right-Wall-Following: • Move forward; • Turn right if the right side is open; • Turn left if the front is not open. • It assumes that forwards and turns are accurate. Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Improving the Navigation Algorithm 22 exit exit Given implementation A possible enhancement • For example: • Detect the cu-de-sac turn 90 degree; move forward; turn 90 degree If cu-de-sac turn 180 degree Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Web Simulation 23 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Communication between VIPLE & Device: JSON Object 24 ASU VIPLE Visual IoT Programming IoT / Robot An object pair, with the second element an array of objects
  5. 5 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Interfacing with Different

    Devices  For any open architecture robot, we can program the robot:  to interpret the JSON objects from VIPLE  to wrap sensor data into JSON object  For vendor-specific robots, such as Lego EV3 and iRobot,  We cannot program the robots to interface with VIPLE  We program VIPLE to interface with each type of such robots. I have Lego robots programmed so far. 25 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Connecting to Physical Robot: Edison Robot 26 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Controlling Physical Robot: Lego EV3 Robot 27 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Physical Robot Construction 28 1- Intel Edison Board 1- Edison Breakout Board 1- Base Shield 1- Robot Base 2- Wheels + Screws 1- Caster Wheel 2- Servos 2- Servo Mounts 1- Breadboard LOT -Female Jumpers LOT- Male Jumpers 1- Sonar Sensor 1- LCD Screen + Cable 1- Touch Sensor 1- Light Sensor LOT- 6-32 Nut LOT- M/F Jumpers Sonar Mount Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Physical Robot Servo Assembly 29 1. Gather servo and mounts 2. Slide servo into mount 3. Screw in the top hole for the servo Note: Make sure servos are calibrated prior to installation Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Physical Robot Body Assembly 30 1. Gather base and Servo mounts 2. Align mounts on the base and fasten with screw and nuts 3. Gather caster wheel and hardware 4. Align and fasten Caster Wheel to base as shown
  6. 6 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Physical Robot Final

    Assembly 31 Y. Chen 2016 Google 师资培育与课程建设第二期 “嵌入式与系统软件开发”研讨班 Lecture Summary  Use FSM model for event-driven programming  Vending machine  Traffic light controller  Garage door opener  Autonomous maze navigation algorithms and programs  VIPLE simulation environment  First working solution  Local best  Wall following  Physical Robot Construction 32