SmartVehicle-Basis
SmartFactory
|
Contains the FSM to controll the Drive. More...
#include <DriveCtrl.h>
Public Types | |
enum | Event { Event::TurnLeft, Event::TurnRight, Event::TurnAround, Event::FollowLineForward, Event::FollowLineBackward, Event::FullLineDetected, Event::LineAligned, Event::Error, Event::Resume, Event::Reset, Event::NoEvent } |
Enum holds all possible events. More... | |
enum | State { State::idle, State::turningLeft, State::turningRight, State::turningAround, State::followingLineForward, State::followingLineBackward, State::resetState, State::errorState } |
Enum holds all possible states. More... | |
Public Member Functions | |
DriveCtrl () | |
Construct a new Drive Ctrl object and set the currentState with idle state and initialize the PID-Controller. More... | |
void | loop () |
Calls the do-function of the active state and hence generates Events. More... | |
void | loop (Event currentEvent) |
procceses the current Event and calls the do-function of the active state More... | |
const State | getcurrentState () |
Get the current State. More... | |
Private Member Functions | |
void | process (Event e) |
changes the state of the FSM based on the event More... | |
void | entryAction_idle () |
executes the entry action of the idle More... | |
DriveCtrl::Event | doAction_idle () |
executes the main action of the idle More... | |
void | exitAction_idle () |
executes the exit action of the idle More... | |
void | entryAction_turningLeft () |
executes the entry action of the turningLeft More... | |
DriveCtrl::Event | doAction_turningLeft () |
executes the main action of the turningLeft More... | |
void | exitAction_turningLeft () |
executes the exit action of the turningLeft More... | |
void | entryAction_turningRight () |
executes the entry action of the turningRight More... | |
DriveCtrl::Event | doAction_turningRight () |
executes the main action of the turningRight More... | |
void | exitAction_turningRight () |
executes the exit action of the turningRight More... | |
void | entryAction_turningAround () |
executes the entry action of the turningAround More... | |
DriveCtrl::Event | doAction_turningAround () |
executes the main action of the turningAround More... | |
void | exitAction_turningAround () |
executes the exit action of the turningAround More... | |
void | entryAction_followingLineForward () |
executes the entry action of the followingLineForward More... | |
DriveCtrl::Event | doAction_followingLineForward () |
executes the main action of the followingLineForward More... | |
void | exitAction_followingLineForward () |
executes the exit action of the followingLineForward More... | |
void | entryAction_followingLineBackward () |
executes the entry action of the followingLineBackward More... | |
DriveCtrl::Event | doAction_followingLineBackward () |
executes the main action of the followingLineBackward More... | |
void | exitAction_followingLineBackward () |
executes the exit action of the followingLineBackward More... | |
void | entryAction_errorState () |
entry action of the errorState More... | |
DriveCtrl::Event | doAction_errorState () |
main action of the errorState More... | |
void | exitAction_errorState () |
exit action of the errorState More... | |
void | entryAction_resetState () |
entry action of the resetState More... | |
DriveCtrl::Event | doAction_resetState () |
main action of the resetState More... | |
void | exitAction_resetState () |
exit action of the resetState More... | |
String | decodeState (State state) |
Decodes the State-Enum and returns a description. More... | |
String | decodeEvent (Event event) |
Decodes the Event-Enum and returns a description. More... | |
Private Attributes | |
State | lastStateBevorError |
holds the last state of the FSM so it's possible to resume after error More... | |
State | currentState |
holds the current state of the FSM More... | |
Event | currentEvent |
holds the current event of the FSM More... | |
Event(DriveCtrl::* | doActionFPtr )(void) = nullptr |
Functionpointer to call the current states do-function. More... | |
unsigned long | currentMillis = 0 |
will store current time More... | |
unsigned long | previousMillis = 0 |
will store last time More... | |
const unsigned long | ignoreSensorTurnMillis = 500 |
sets how long the sensors are ignored for a turn More... | |
const unsigned long | ignoreSensorAroundMillis = 1500 |
sets how long the sensors are ignored for a turning around More... | |
double | pController_Input = 0 |
Controller Input. More... | |
double | pController_Output = 0 |
Controller Output. More... | |
double | pController_Setpoint = 0 |
Controller Setpoint. More... | |
int | pSampleTime = 50 |
Controler SampleTime in ms. More... | |
double | pVal_p = PID_KP |
P-Value. More... | |
double | pVal_i = PID_KI / pSampleTime |
I-Value (independet of SamplingTime) More... | |
double | pVal_d = PID_KD * pSampleTime |
D-Value (independet of SamplingTime) More... | |
PID | pController = PID(&pController_Input, &pController_Output, &pController_Setpoint, pVal_p, pVal_i, pVal_d, DIRECT) |
PID-Controller Object. More... | |
Drive | pDrive = Drive(RIGHT_MOTOR, LEFT_MOTOR) |
Drive Object. More... | |
EnvironmentDetection | pEnvdetect |
EnviromentDetection Object. More... | |
|
strong |
Enum holds all possible events.
Definition at line 39 of file DriveCtrl.h.
|
strong |
Enum holds all possible states.
Definition at line 56 of file DriveCtrl.h.
DriveCtrl::DriveCtrl | ( | ) |
Construct a new Drive Ctrl object and set the currentState with idle state and initialize the PID-Controller.
Definition at line 17 of file DriveCtrl.cpp.
void DriveCtrl::loop | ( | ) |
Calls the do-function of the active state and hence generates Events.
Definition at line 26 of file DriveCtrl.cpp.
void DriveCtrl::loop | ( | Event | currentEvent | ) |
procceses the current Event and calls the do-function of the active state
currentEvent | - Event |
Definition at line 31 of file DriveCtrl.cpp.
const DriveCtrl::State DriveCtrl::getcurrentState | ( | ) |
|
private |
changes the state of the FSM based on the event
e | - Event |
Definition at line 41 of file DriveCtrl.cpp.
|
private |
executes the entry action of the idle
Definition at line 156 of file DriveCtrl.cpp.
|
private |
executes the main action of the idle
This is an idle-state. Return NoEvent.
Definition at line 163 of file DriveCtrl.cpp.
|
private |
executes the exit action of the idle
Definition at line 169 of file DriveCtrl.cpp.
|
private |
executes the entry action of the turningLeft
Start Turning Left.
Definition at line 174 of file DriveCtrl.cpp.
|
private |
executes the main action of the turningLeft
Turn Left until the line is aligned again. Return LineAligned else return no Event.
Definition at line 184 of file DriveCtrl.cpp.
|
private |
executes the exit action of the turningLeft
Stop Driving.
Definition at line 194 of file DriveCtrl.cpp.
|
private |
executes the entry action of the turningRight
Start Turning Right.
Definition at line 200 of file DriveCtrl.cpp.
|
private |
executes the main action of the turningRight
Turn Right until the line is aligned again. Return LineAligned else return no Event.
Definition at line 210 of file DriveCtrl.cpp.
|
private |
executes the exit action of the turningRight
Stop Driving.
Definition at line 220 of file DriveCtrl.cpp.
|
private |
executes the entry action of the turningAround
Start Turning Right.
Definition at line 226 of file DriveCtrl.cpp.
|
private |
executes the main action of the turningAround
Turn Right until the line is aligned again. Return LineAligned else return no Event.
Definition at line 237 of file DriveCtrl.cpp.
|
private |
executes the exit action of the turningAround
Stop Driving.
Definition at line 250 of file DriveCtrl.cpp.
|
private |
executes the entry action of the followingLineForward
Start Driving Straight
Definition at line 256 of file DriveCtrl.cpp.
|
private |
executes the main action of the followingLineForward
Check Line-deviation and correct accordingly via PID-Controller and drive until a FullLine is Detected. Return Event FullLine else reutrn NoEvent.
Definition at line 267 of file DriveCtrl.cpp.
|
private |
executes the exit action of the followingLineForward
Stop driving.
Definition at line 294 of file DriveCtrl.cpp.
|
private |
executes the entry action of the followingLineBackward
Start Driving Straight
Definition at line 300 of file DriveCtrl.cpp.
|
private |
executes the main action of the followingLineBackward
Check Line-deviation and correct accordingly via PID-Controller and drive until a FullLine is Detected. Return Event FullLine else reutrn NoEvent.
Definition at line 314 of file DriveCtrl.cpp.
|
private |
executes the exit action of the followingLineBackward
Stop driving.
Definition at line 343 of file DriveCtrl.cpp.
|
private |
entry action of the errorState
Definition at line 351 of file DriveCtrl.cpp.
|
private |
main action of the errorState
Definition at line 360 of file DriveCtrl.cpp.
|
private |
exit action of the errorState
Definition at line 366 of file DriveCtrl.cpp.
|
private |
entry action of the resetState
Definition at line 371 of file DriveCtrl.cpp.
|
private |
main action of the resetState
Definition at line 377 of file DriveCtrl.cpp.
|
private |
exit action of the resetState
Definition at line 383 of file DriveCtrl.cpp.
|
private |
Decodes the State-Enum and returns a description.
state | - enum State |
Definition at line 389 of file DriveCtrl.cpp.
|
private |
Decodes the Event-Enum and returns a description.
event | - enum Event |
Definition at line 414 of file DriveCtrl.cpp.
|
private |
holds the last state of the FSM so it's possible to resume after error
Definition at line 95 of file DriveCtrl.h.
|
private |
holds the current state of the FSM
Definition at line 96 of file DriveCtrl.h.
|
private |
holds the current event of the FSM
Definition at line 97 of file DriveCtrl.h.
|
private |
Functionpointer to call the current states do-function.
https://stackoverflow.com/questions/1485983/calling-c-class-methods-via-a-function-pointer
Definition at line 104 of file DriveCtrl.h.
|
private |
will store current time
Definition at line 106 of file DriveCtrl.h.
|
private |
will store last time
Definition at line 107 of file DriveCtrl.h.
|
private |
sets how long the sensors are ignored for a turn
Definition at line 108 of file DriveCtrl.h.
|
private |
sets how long the sensors are ignored for a turning around
Definition at line 109 of file DriveCtrl.h.
|
private |
Controller Input.
Definition at line 111 of file DriveCtrl.h.
|
private |
Controller Output.
Definition at line 112 of file DriveCtrl.h.
|
private |
Controller Setpoint.
Definition at line 113 of file DriveCtrl.h.
|
private |
Controler SampleTime in ms.
Definition at line 114 of file DriveCtrl.h.
|
private |
P-Value.
Definition at line 115 of file DriveCtrl.h.
|
private |
I-Value (independet of SamplingTime)
Definition at line 116 of file DriveCtrl.h.
|
private |
D-Value (independet of SamplingTime)
Definition at line 117 of file DriveCtrl.h.
|
private |
PID-Controller Object.
https://www.quora.com/What-would-be-appropriate-tuning-factors-for-PID-line-follower-robot
Definition at line 131 of file DriveCtrl.h.
|
private |
Drive Object.
Definition at line 132 of file DriveCtrl.h.
|
private |
EnviromentDetection Object.
Definition at line 133 of file DriveCtrl.h.