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 <mbed.h> 00012 #include "Controller.h" 00013 #include "IRSensor.h" 00014 00015 #include <deque> 00016 #include "Task.h" 00017 #include "TaskWait.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 MOVE_FORWARD = 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,DigitalOut& led); 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& led; 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 Ticker ticker; 00067 00068 deque<Task*> taskList; 00069 00070 void run(); 00071 }; 00072 00073 #endif /* STATE_MACHINE_H_ */ 00074
Generated on Thu Jul 14 2022 09:49:36 by
