Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
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 #include <deque> 00015 #include "Task.h" 00016 #include "TaskWait.h" 00017 #include "TaskMoveTo.h" 00018 00019 /** 00020 * This class implements a simple state machine for a mobile robot. 00021 * It allows to move the robot forward, and to turn left or right, 00022 * depending on distance measurements, to avoid collisions with 00023 * obstacles. 00024 */ 00025 class StateMachine { 00026 00027 public: 00028 00029 static const int ROBOT_OFF = 0; // discrete states of this state machine 00030 static const int MOVE_FORWARD = 1; 00031 static const int TURN_LEFT = 2; 00032 static const int TURN_RIGHT = 3; 00033 static const int SLOWING_DOWN = 4; 00034 00035 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); 00036 virtual ~StateMachine(); 00037 int getState(); 00038 00039 private: 00040 00041 static const float PERIOD; // period of task in [s] 00042 static const float DISTANCE_THRESHOLD; // minimum allowed distance to obstacle in [m] 00043 static const float TRANSLATIONAL_VELOCITY; // translational velocity in [m/s] 00044 static const float ROTATIONAL_VELOCITY; // rotational velocity in [rad/s] 00045 00046 Controller& controller; 00047 DigitalOut& enableMotorDriver; 00048 DigitalOut& led0; 00049 DigitalOut& led1; 00050 DigitalOut& led2; 00051 DigitalOut& led3; 00052 DigitalOut& led4; 00053 DigitalOut& led5; 00054 DigitalIn& button; 00055 IRSensor& irSensor0; 00056 IRSensor& irSensor1; 00057 IRSensor& irSensor2; 00058 IRSensor& irSensor3; 00059 IRSensor& irSensor4; 00060 IRSensor& irSensor5; 00061 int state; 00062 int buttonNow; 00063 int buttonBefore; 00064 Ticker ticker; 00065 00066 deque<Task*> taskList; 00067 00068 void run(); 00069 }; 00070 00071 #endif /* STATE_MACHINE_H_ */ 00072
Generated on Wed Jul 20 2022 03:42:12 by
