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) 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 #include "TaskMoveToWaypoint.h" 00020 00021 /** 00022 * This class implements a simple state machine for a mobile robot. 00023 * It allows to move the robot forward, and to turn left or right, 00024 * depending on distance measurements, to avoid collisions with 00025 * obstacles. 00026 */ 00027 class StateMachine { 00028 00029 public: 00030 00031 static const int ROBOT_OFF = 0; // discrete states of this state machine 00032 static const int PROCESSING_TASKS = 1; 00033 static const int TURN_LEFT = 2; 00034 static const int TURN_RIGHT = 3; 00035 static const int SLOWING_DOWN = 4; 00036 00037 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); 00038 virtual ~StateMachine(); 00039 int getState(); 00040 00041 private: 00042 00043 static const float PERIOD; // period of task in [s] 00044 static const float DISTANCE_THRESHOLD; // minimum allowed distance to obstacle in [m] 00045 static const float TRANSLATIONAL_VELOCITY; // translational velocity in [m/s] 00046 static const float ROTATIONAL_VELOCITY; // rotational velocity in [rad/s] 00047 00048 Controller& controller; 00049 DigitalOut& enableMotorDriver; 00050 DigitalOut& led0; 00051 DigitalOut& led1; 00052 DigitalOut& led2; 00053 DigitalOut& led3; 00054 DigitalOut& led4; 00055 DigitalOut& led5; 00056 DigitalIn& button; 00057 IRSensor& irSensor0; 00058 IRSensor& irSensor1; 00059 IRSensor& irSensor2; 00060 IRSensor& irSensor3; 00061 IRSensor& irSensor4; 00062 IRSensor& irSensor5; 00063 int state; 00064 int buttonNow; 00065 int buttonBefore; 00066 deque<Task*> taskList; 00067 Ticker ticker; 00068 00069 void run(); 00070 }; 00071 00072 #endif /* STATE_MACHINE_H_ */ 00073
Generated on Sun Jul 23 2023 17:17:31 by
1.7.2