Kansas State University - Slide 1

Document Sample
Kansas State University - Slide 1 Powered By Docstoc
					      Design Methodology
              for
State based Embedded Systems
 Case Study: Robot Controller


        Phaneendra Vanka
Graduate Student (Masters’ Program)

                 Department of Computing and Information Sciences
                                           Kansas State University
Contents

 Introduction
 Demo

 Design Methodology for Time-Triggered State
  Machine based systems
 Case Study: Robot Controller

 Questions




                       Department of Computing and Information Sciences
                                                 Kansas State University
Introduction




      Department of Computing and Information Sciences
                                Kansas State University
Behavior Control

 Behavior – tasks that process external/internal
  sensory information and issues an action.
 Reactive robot control architecture.

 Complex behavior – series of alternations of
  simple behaviors.
 Hierarchical Model.




                          Department of Computing and Information Sciences
                                                    Kansas State University
LEGO MINDSTORMS
Robotics Invention System Kit consists of
 motors, touch sensors, light sensors, bricks,
 gears etc.
 RCX Brick

    - Hitachi H8/3292 series microcontroller.
    - 16 MHz of clock speed.
    - 16Kb ROM.
    - 32 Kb external RAM.
                       Department of Computing and Information Sciences
                                                 Kansas State University
leJOS

 Java Platform for the RCX Brick.
 leJOS API

      - java.lang, java.util and java.io
      - classes to control motors, sensors,
        buttons, IR communication, navigation
        etc.



                         Department of Computing and Information Sciences
                                                   Kansas State University
Behavior Control API

Behavior
      boolean takeControl( )
      void action( )
      void suppress( )
Arbitrator
      public Arbitrator (Behavior[ ] behaviors)


                          Department of Computing and Information Sciences
                                                    Kansas State University
Robot Controller

 A modification of the Navigator robot as given
  in Brian Bagnall’s book “Core Lego Mindstorms
  Programming”.
 Sensors and Inputs: Touch sensor, Timer and
  two Rotation Sensors.
 Actuators: Three motors.




                        Department of Computing and Information Sciences
                                                  Kansas State University
Behavior’s of Robot Controller
   MOVE (true):
           Travel to a random point
   COMMAND (Input from IR transceiver):
           Travel to a predefined point. If there is an obstacle go around
            that obstacle
   BUMP (Input from touch sensor):
           Travels 20 units in backward direction.
   GO HOME (Timer as input):
           Travel to the starting point
   ARM ROTATE (Timer as input):
           Rotate the arm
    .                                      Department of Computing and Information Sciences
                                                                     Kansas State University
Robot Controller’s Behavior Model
        Timer                     GO HOME


  Touch Sensor                      BUMP                     S


                                  COMMAND                    S
   Command


    Default                         MOVE                    S         Motors


        Timer                     ARM ROTATE

    S      Point of Suppression


                                            Department of Computing and Information Sciences
                                                                      Kansas State University
DEMO




       Department of Computing and Information Sciences
                                 Kansas State University
Design Methodology for Time-Triggered
     State Machine based systems



                  Department of Computing and Information Sciences
                                            Kansas State University
Rational Unified Process

    Actors        Class Diagrams
                                                    Implementation
  Use-Cases         Use-Case
                   realizations



 Use-Case Model   Analysis/Design                     Actual code
     (what)            (how)




                         Department of Computing and Information Sciences
                                                   Kansas State University
Use-Case realizations
                                WAKEUP
                   WAIT




                        Department of Computing and Information Sciences
                                                  Kansas State University
Use-Case realizations with asynchronous
waits
 Allocating a thread for each scenario with
  synchronization code
 Finite State Machine based implementation




                         Department of Computing and Information Sciences
                                                   Kansas State University
Allocating a thread for each scenario
      Actors                     Class Diagrams
                                                                   Component code
     Use-Cases                     Use-Case
                                  realizations

                                 Identify regions in which
                                 synchronization is required                Complete
                                                                              code
      Global          Coarse-                Fine-grained
    invariants        grained                    code
    (patterns)        solution


 A Structured Approach to Develop Concurrent Programs in UML,
           Masaaki Mizuno, Gurdip Singh, Mitchell Nielsen

                                          Department of Computing and Information Sciences
                                                                    Kansas State University
Finite State Machine based implementation
   Actors       Class Diagrams                       Revised Class
                                                       Diagram
  Use-cases       Use-case
                 realizations                        Scenarios for
                                                        threads




                                  Original Class
                                 Diagram + State       Implementation
                                  information +
                                  Active Classes


              Time Triggered




                                 Department of Computing and Information Sciences
                                                           Kansas State University
Event Triggered Systems



     Boundary Class           Other Classes




                      Department of Computing and Information Sciences
                                                Kansas State University
Time Triggered Systems



 Boundary Class   Active Class                Other Classes




                         Department of Computing and Information Sciences
                                                   Kansas State University
From the above discussion we have the
following combinations
   Time Triggered    State Machine based
                      implementation
   Event Triggered   Thread for each scenario




                        Department of Computing and Information Sciences
                                                  Kansas State University
Case Study : Robot Controller




                    Department of Computing and Information Sciences
                                              Kansas State University
Use Cases for Robot Controller
   MOVE (true):
        Pick up a random point (x,y) to reach.
        Calculate the angle and distance to (x,y).
        Rotate for the angle and travel the distance in straight line.
   COMMAND (Input from IR transceiver):
        Calculate the angle and distance to (MAXX, MAXY).
        Rotate for the angle and travel the distance in straight line.
   BUMP (Input from touch sensor):
        Travel 20 units in backward direction.
   GO HOME (Timer as input):
        Calculate the angle and distance for initial point (0,0).
        Rotate for the angle and travel the distance in straight line.
   ARM ROTATE (Timer as input):
        Rotate the arm in forward direction for 2 seconds
        Rotate the arm in backward direction for 2 seconds
STEER (Inputs from Rotation Sensors):
        Uses rotation sensor to find angle rotated and distance traveled.
        Keeps the travel in straight line.

                                                      Department of Computing and Information Sciences
                                                                                Kansas State University
Use Case Model for Robot Controller
                              1..1



                default                               Tippy Senior
             1..1                                            Move Behavior
                                                1..1
                                                                                  1..1                      1..1
                                                1..1      1..1                   1..1
  Command
                              1..1                                                                        1..1
                                                                                                        1..1       1..1

                                                             Command Behavior
                                               1..1                                   1..1
                    bump                                                             1..1                         Left Motor
                                                                                                                1..1

                                                                 Bump Behavior
                                                  1..1                               1..1
                       1..1
                                                  1..1
                                                   1..1                             1..1



      GoHome timer
                                                              GoHome Behavior
                                                                                          1..1              1..1
                                                                                                            1..1
                                                 1..1
                                                  1..1
                                                 1..1                                    1..1
                                                                                                         1..1    1..1
                    1..1
                      1..1
                     1..1                                            Steer
                                                                                     1..1
                                     1..1          1..1
                                                  1..1                              1..1
                       1..1
                                                                                                               Right Motor
                                                                                                            1..1
                                     1..1
                                     1..1
                                     1..1

  Left Rotational Sensor
                                                                  Arm Rotate
                                                      1..1                         1..1
                                                                                                 1..1
                     Right Rotational Sensor
                      1..1


                                                                                                        Arm Motor

        Arm timer


                                                                 Department of Computing and Information Sciences
                                                                                           Kansas State University
                                                                                                 Motor

                                                                                  3


Class Diagram
                                                       RotationNavigator


                                                      +getX() : int
                           RotationSensor             +getY() : int
                                                      +getAngle() : double                    Touch Sensor
                                                      +rotate()                   1
                                                      +gotoPoint()
                                                      +travel()               1
                           2                          +forward()
                                                      +backward()
                                                      +updateCoordinate()
                                                      +updateAngle()
                                                      +halt()
                                                      +stop()
                                               1      +setCommand()                               Timer
                                                      +checkRotate()
                                                      +checkForward()
                                                      +checkBackward()
      IRTransceiver                                                                   1
                                                                                                       1
                                                                  Navigator

                                                       1
                                                       1
                                                       1
        1
             1                                         1                                  1
                      1        1                                         1                         1
                                                              1
            Move          Command            Bump                    GoHome                   ArmRotate

                                                                                      1




                                           «interface»
                                            Behavior
                                      +takecontrol() : bool
                                      +action()
                                      +suppress()

                                            Department of Computing and Information Sciences
                                                                      Kansas State University
Use Case Realization Example
 Robot Controller : MOVE Behavior
          Wait Until MOVE is triggered
          Pick a new point (x, y)
          Calculate angle and distance
          Start the motors
          Wait Until required angle is rotated
          Stop motors
          Update geometry
          Start the motors
          Wait Until required distance is traveled
          Stop motors
          Update geometry



                                    Department of Computing and Information Sciences
                                                              Kansas State University
Use Case Realization Example
 Robot Controller : MOVE Behavior                          Asynchronous waits
          Wait Until MOVE is triggered
          Pick a new point (x, y)
          Calculate angle and distance
          Start the motors
          Wait Until required angle is rotated
          Stop motors
          Update geometry
          Start the motors
          Wait Until required distance is traveled
          Stop motors
          Update geometry



                                    Department of Computing and Information Sciences
                                                              Kansas State University
Finite State Machine Method
                               actions




                            Behavior Action

   Each behavior is a set of actions.
   After completing one action it goes to the next action
    of the behavior.
   Describe the entire system using finite state machine.
   Allocate threads to traverse through the state machine.
       Needs only mutual exclusion of shared variables.

                                         Department of Computing and Information Sciences
                                                                   Kansas State University
Use Case Realization Example                                               States


 Tippy Senior : MOVE Behavior
          Wait Until MOVE is triggered
          Pick a new point (x, y)
          Calculate angle and distance
          Start the motors
          Wait Until required angle is rotated
          Stop motors
          Update geometry
          Start the motors
          Wait Until required distance is traveled
          Stop motors
          Update geometry



                                   Department of Computing and Information Sciences
                                                             Kansas State University
Revised Class Diagram                                                                                                                Motor

                  StateTable                                                                                              3
                                                                                              RotationNavigator

       +getNextState() : byte                    1
       +getActionToBeTaken() : Action                                                        +getX() : int
                                                                RotationSensor               +getY() : int
       +setNextState()
       +setActionToBeTaken()                                                                 +getAngle() : double                 Touch Sensor
                                                                                             +rotate()                1
                                                                                             +gotoPoint()
                                                                                             +travel()                1
                                                                2                            +forward()
                                                       1                1                    +backward()
                                                                                             +updateCoordinate()
       CurrentState                                  Rotation Sensor Thread                  +updateAngle()
   1                                                                                         +halt()
                          1                                                                  +stop()
                                            1
                                            1                                      1
                                                     +getCurrentState() : byte               +setCommand()                            Timer
                                                                                       1
              1                                      +setCurrentState()                      +checkRotate()
                                                     +nextState()                            +checkForward()
                                                                                             +checkBackward()
         ArmState                                                                                                         1
                                     IRTransceiver
                                                                        1                                                                  1
                                                                                                          Navigator                        1

                                                                                              1
                                                                                              1
                                                                                              1
          1                                 1
                                             1                                                1
                                                           1        1                                            1            1        1
                                                                                                      1
                                          Move                 Command             Bump                      GoHome               ArmRotate

                                                                                                                          1




                                                                                  «interface»
                                                                                   Behavior
                                                                             +takecontrol() : bool
                                                                             +action()
                                                                             +suppress()
                               1

                                                                                                  *
                                   Arbitrator

                      1
                                                      1

                                                                        Department of Computing and Information Sciences
                                                                                                  Kansas State University
Use Case Realization Example                                               Arbitrator


 Tippy Senior : MOVE Behavior
          Wait Until MOVE is triggered
          Pick a new point (x, y)
          Calculate angle and distance
          Start the motors
                                                                        Rotation Sensor
          Wait until required angle is rotated
                                                                        Thread
          Stop motors
          Update geometry
          Start the motors
          Wait Until required distance is traveled
          Stop motors
          Update geometry



                                   Department of Computing and Information Sciences
                                                             Kansas State University
Arbitrator thread
                            Action (GO HOME)




         takeControl
          GO HOME          Action (BUMP)

         takeControl
            BUMP

         takeControl                               DONE
         COMMAND

         takeControl
            MOVE

                             Action (COMMAND)




                                Action (MOVE)




                       Department of Computing and Information Sciences
                                                 Kansas State University
Rotation Sensor Thread
                           Action (GO HOME)




        takeControl
         GO HOME          Action (BUMP)

        takeControl
           BUMP

        takeControl                               DONE
        COMMAND

        takeControl
           MOVE

                            Action (COMMAND)




                               Action (MOVE)




                      Department of Computing and Information Sciences
                                                Kansas State University
Acknowledgement
 Dr. Masaaki Mizuno
 Dr. Gurdip Singh

 Dr. Mitchell Nielsen




                         Department of Computing and Information Sciences
                                                   Kansas State University
Questions ???




      Department of Computing and Information Sciences
                                Kansas State University