ROME2 / Mbed 2 deprecated ROME2_p3

Dependencies:   mbed

Committer:
koenithi
Date:
Wed Mar 25 13:26:46 2020 +0000
Revision:
0:d8d297847268
Child:
1:c5408c1c1b81
Rome2_p3

Who changed what in which revision?

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