ROME_P5

Dependencies:   mbed

Committer:
Inaueadr
Date:
Fri Apr 27 08:47:34 2018 +0000
Revision:
0:29be10cb0afc
Hallo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Inaueadr 0:29be10cb0afc 1 /*
Inaueadr 0:29be10cb0afc 2 * StateMachine.h
Inaueadr 0:29be10cb0afc 3 * Copyright (c) 2018, ZHAW
Inaueadr 0:29be10cb0afc 4 * All rights reserved.
Inaueadr 0:29be10cb0afc 5 */
Inaueadr 0:29be10cb0afc 6
Inaueadr 0:29be10cb0afc 7 #ifndef STATE_MACHINE_H_
Inaueadr 0:29be10cb0afc 8 #define STATE_MACHINE_H_
Inaueadr 0:29be10cb0afc 9
Inaueadr 0:29be10cb0afc 10 #include <cstdlib>
Inaueadr 0:29be10cb0afc 11 #include <deque>
Inaueadr 0:29be10cb0afc 12 #include <mbed.h>
Inaueadr 0:29be10cb0afc 13 #include "Controller.h"
Inaueadr 0:29be10cb0afc 14 #include "IRSensor.h"
Inaueadr 0:29be10cb0afc 15 #include "Task.h"
Inaueadr 0:29be10cb0afc 16 #include "TaskWait.h"
Inaueadr 0:29be10cb0afc 17 #include "TaskMove.h"
Inaueadr 0:29be10cb0afc 18 #include "TaskMoveTo.h"
Inaueadr 0:29be10cb0afc 19
Inaueadr 0:29be10cb0afc 20 /**
Inaueadr 0:29be10cb0afc 21 * This class implements a simple state machine for a mobile robot.
Inaueadr 0:29be10cb0afc 22 * It allows to move the robot forward, and to turn left or right,
Inaueadr 0:29be10cb0afc 23 * depending on distance measurements, to avoid collisions with
Inaueadr 0:29be10cb0afc 24 * obstacles.
Inaueadr 0:29be10cb0afc 25 */
Inaueadr 0:29be10cb0afc 26 class StateMachine {
Inaueadr 0:29be10cb0afc 27
Inaueadr 0:29be10cb0afc 28 public:
Inaueadr 0:29be10cb0afc 29
Inaueadr 0:29be10cb0afc 30 static const int ROBOT_OFF = 0; // discrete states of this state machine
Inaueadr 0:29be10cb0afc 31 static const int PROCESSING_TASKS = 1;
Inaueadr 0:29be10cb0afc 32 static const int TURN_LEFT = 2;
Inaueadr 0:29be10cb0afc 33 static const int TURN_RIGHT = 3;
Inaueadr 0:29be10cb0afc 34 static const int SLOWING_DOWN = 4;
Inaueadr 0:29be10cb0afc 35
Inaueadr 0:29be10cb0afc 36 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);
Inaueadr 0:29be10cb0afc 37 virtual ~StateMachine();
Inaueadr 0:29be10cb0afc 38 int getState();
Inaueadr 0:29be10cb0afc 39
Inaueadr 0:29be10cb0afc 40 private:
Inaueadr 0:29be10cb0afc 41
Inaueadr 0:29be10cb0afc 42 static const float PERIOD; // period of task in [s]
Inaueadr 0:29be10cb0afc 43 static const float DISTANCE_THRESHOLD; // minimum allowed distance to obstacle in [m]
Inaueadr 0:29be10cb0afc 44 static const float TRANSLATIONAL_VELOCITY; // translational velocity in [m/s]
Inaueadr 0:29be10cb0afc 45 static const float ROTATIONAL_VELOCITY; // rotational velocity in [rad/s]
Inaueadr 0:29be10cb0afc 46
Inaueadr 0:29be10cb0afc 47 Controller& controller;
Inaueadr 0:29be10cb0afc 48 DigitalOut& enableMotorDriver;
Inaueadr 0:29be10cb0afc 49 DigitalOut& led0;
Inaueadr 0:29be10cb0afc 50 DigitalOut& led1;
Inaueadr 0:29be10cb0afc 51 DigitalOut& led2;
Inaueadr 0:29be10cb0afc 52 DigitalOut& led3;
Inaueadr 0:29be10cb0afc 53 DigitalOut& led4;
Inaueadr 0:29be10cb0afc 54 DigitalOut& led5;
Inaueadr 0:29be10cb0afc 55 DigitalIn& button;
Inaueadr 0:29be10cb0afc 56 IRSensor& irSensor0;
Inaueadr 0:29be10cb0afc 57 IRSensor& irSensor1;
Inaueadr 0:29be10cb0afc 58 IRSensor& irSensor2;
Inaueadr 0:29be10cb0afc 59 IRSensor& irSensor3;
Inaueadr 0:29be10cb0afc 60 IRSensor& irSensor4;
Inaueadr 0:29be10cb0afc 61 IRSensor& irSensor5;
Inaueadr 0:29be10cb0afc 62 int state;
Inaueadr 0:29be10cb0afc 63 int buttonNow;
Inaueadr 0:29be10cb0afc 64 int buttonBefore;
Inaueadr 0:29be10cb0afc 65 deque<Task*> taskList;
Inaueadr 0:29be10cb0afc 66 Ticker ticker;
Inaueadr 0:29be10cb0afc 67
Inaueadr 0:29be10cb0afc 68 void run();
Inaueadr 0:29be10cb0afc 69 };
Inaueadr 0:29be10cb0afc 70
Inaueadr 0:29be10cb0afc 71 #endif /* STATE_MACHINE_H_ */
Inaueadr 0:29be10cb0afc 72