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