Marco Oehler / Mbed 2 deprecated Lab2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers StateMachine.h Source File

StateMachine.h

00001 /*
00002  * StateMachine.h
00003  * Copyright (c) 2020, ZHAW
00004  * All rights reserved.
00005  */
00006 
00007 #ifndef STATE_MACHINE_H_
00008 #define STATE_MACHINE_H_
00009 
00010 #include <cstdlib>
00011 #include <mbed.h>
00012 #include "Controller.h"
00013 #include "IRSensor.h"
00014 
00015 /**
00016  * This class implements a simple state machine for a mobile robot.
00017  * It allows to move the robot forward, and to turn left or right,
00018  * depending on distance measurements, to avoid collisions with
00019  * obstacles.
00020  */
00021 class StateMachine {
00022     
00023     public:
00024         
00025         static const int    ROBOT_OFF = 0;      // discrete states of this state machine
00026         static const int    MOVE_FORWARD = 1;
00027         static const int    TURN_LEFT = 2;
00028         static const int    TURN_RIGHT = 3;
00029         static const int    SLOWING_DOWN = 4;
00030         
00031                     StateMachine(Controller& controller, DigitalOut& enableMotorDriver, DigitalOut& led0, DigitalOut& led1, DigitalOut& led2, DigitalOut& led3, DigitalOut& led4, DigitalOut& led5, DigitalIn& button, IRSensor& irSensor0, IRSensor& irSensor1, IRSensor& irSensor2, IRSensor& irSensor3, IRSensor& irSensor4, IRSensor& irSensor5);
00032         virtual     ~StateMachine();
00033         int         getState();
00034         
00035     private:
00036         
00037         static const float  PERIOD;                 // period of task in [s]
00038         static const float  DISTANCE_THRESHOLD;     // minimum allowed distance to obstacle in [m]
00039         static const float  TRANSLATIONAL_VELOCITY; // translational velocity in [m/s]
00040         static const float  ROTATIONAL_VELOCITY;    // rotational velocity in [rad/s]
00041         
00042         Controller&     controller;
00043         DigitalOut&     enableMotorDriver;
00044         DigitalOut&     led0;
00045         DigitalOut&     led1;
00046         DigitalOut&     led2;
00047         DigitalOut&     led3;
00048         DigitalOut&     led4;
00049         DigitalOut&     led5;
00050         DigitalIn&      button;
00051         IRSensor&       irSensor0;
00052         IRSensor&       irSensor1;
00053         IRSensor&       irSensor2;
00054         IRSensor&       irSensor3;
00055         IRSensor&       irSensor4;
00056         IRSensor&       irSensor5;
00057         int             state;
00058         int             buttonNow;
00059         int             buttonBefore;
00060         Ticker          ticker;
00061         
00062         void            run();
00063 };
00064 
00065 #endif /* STATE_MACHINE_H_ */
00066