SmartVehicle-Basis
SmartFactory
HoistCtrl Class Reference

Contains the FSM for the Hoist. More...

#include <HoistCtrl.h>

Collaboration diagram for HoistCtrl:

Public Types

enum  Event {
  Event::Raise, Event::Lower, Event::PosReached, Event::Error,
  Event::Resume, Event::Reset, Event::NoEvent
}
 Enum holds all possible events. More...
 
enum  State {
  State::low, State::raising, State::high, State::lowering,
  State::resetState, State::errorState
}
 Enum holds all possible states for the Hoist. More...
 

Public Member Functions

 HoistCtrl ()
 Construct a new Hoist Ctrl object and initailize the currentState with low state. 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_low ()
 executes the entry action of the low state. More...
 
HoistCtrl::Event doAction_low ()
 executes the main action of the low state. More...
 
void exitAction_low ()
 executes the exit action of the low state. More...
 
void entryAction_raising ()
 executes the entry action of the raising state. More...
 
HoistCtrl::Event doAction_raising ()
 executes the main action of the raising state. More...
 
void exitAction_raising ()
 executes the exit action of the raising state. More...
 
void entryAction_high ()
 executes the entry action of the high state. More...
 
HoistCtrl::Event doAction_high ()
 executes the main action of the high state. More...
 
void exitAction_high ()
 executes the exit action of the high state. More...
 
void entryAction_lowering ()
 executes the entry action of the lowering state. More...
 
HoistCtrl::Event doAction_lowering ()
 executes the main action of the lowering state. More...
 
void exitAction_lowering ()
 executes the exit action of the lowering state. More...
 
void entryAction_errorState ()
 entry action of the errorState state. More...
 
HoistCtrl::Event doAction_errorState ()
 main action of the errorState state. More...
 
void exitAction_errorState ()
 exit action of the errorState state. More...
 
void entryAction_resetState ()
 entry action of the resetState More...
 
HoistCtrl::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(HoistCtrl::* doActionFPtr )(void) = nullptr
 Functionpointer to call the current states do-function. More...
 
Hoist pHoist = Hoist(HOIST_SERVO_PIN, HOIST_SERVO_DELAY, HOIST_POISITION_MAX, HOIST_POSITION_MIN)
 Hoist Object. More...
 

Detailed Description

Contains the FSM for the Hoist.

HoistCtrl.png

Definition at line 27 of file HoistCtrl.h.

Member Enumeration Documentation

◆ Event

enum HoistCtrl::Event
strong

Enum holds all possible events.

Enumerator
Raise 

Ext: Start Raise.

Lower 

Ext: Start Lower.

PosReached 

Signal: Position reached.

Error 

Error occured.

Resume 

Ext.: Resume after Error occured.

Reset 

Ext.: Reset after Error occured.

NoEvent 

No event generated.

Definition at line 34 of file HoistCtrl.h.

◆ State

enum HoistCtrl::State
strong

Enum holds all possible states for the Hoist.

Enumerator
low 

low State

raising 

raising State

high 

high State

lowering 

lowering State

resetState 

reset state

errorState 

error State

Definition at line 47 of file HoistCtrl.h.

Constructor & Destructor Documentation

◆ HoistCtrl()

HoistCtrl::HoistCtrl ( )

Construct a new Hoist Ctrl object and initailize the currentState with low state.

Definition at line 16 of file HoistCtrl.cpp.

Member Function Documentation

◆ loop() [1/2]

void HoistCtrl::loop ( )

Calls the do-function of the active state and hence generates Events.

Definition at line 19 of file HoistCtrl.cpp.

◆ loop() [2/2]

void HoistCtrl::loop ( Event  currentEvent)

Procceses the current Event and calls the do-function of the active state.

Parameters
currentEvent- Event

Definition at line 24 of file HoistCtrl.cpp.

◆ getcurrentState()

const HoistCtrl::State HoistCtrl::getcurrentState ( )

Get the current State.

Returns
State - current State

Definition at line 30 of file HoistCtrl.cpp.

◆ process()

void HoistCtrl::process ( Event  e)
private

changes the state of the FSM based on the event

This Functions switchs the state based on the occuring events

Parameters
e- Event

Definition at line 34 of file HoistCtrl.cpp.

◆ entryAction_low()

void HoistCtrl::entryAction_low ( )
private

executes the entry action of the low state.

Definition at line 110 of file HoistCtrl.cpp.

◆ doAction_low()

HoistCtrl::Event HoistCtrl::doAction_low ( )
private

executes the main action of the low state.

This is an idle-state. Return NoEvent.

Returns
HoistCtrl::Event - generated Event

Definition at line 117 of file HoistCtrl.cpp.

◆ exitAction_low()

void HoistCtrl::exitAction_low ( )
private

executes the exit action of the low state.

Definition at line 123 of file HoistCtrl.cpp.

◆ entryAction_raising()

void HoistCtrl::entryAction_raising ( )
private

executes the entry action of the raising state.

Attach Servo.

Definition at line 128 of file HoistCtrl.cpp.

◆ doAction_raising()

HoistCtrl::Event HoistCtrl::doAction_raising ( )
private

executes the main action of the raising state.

Raise the Hoist till the Endposition is reached and generate an PosReached Event. Else return NoEvent.

Returns
HoistCtrl::Event - generated Event

Definition at line 136 of file HoistCtrl.cpp.

◆ exitAction_raising()

void HoistCtrl::exitAction_raising ( )
private

executes the exit action of the raising state.

Detach Servo.

Definition at line 145 of file HoistCtrl.cpp.

◆ entryAction_high()

void HoistCtrl::entryAction_high ( )
private

executes the entry action of the high state.

Definition at line 151 of file HoistCtrl.cpp.

◆ doAction_high()

HoistCtrl::Event HoistCtrl::doAction_high ( )
private

executes the main action of the high state.

This is an idle-state. Return NoEvent.

Returns
HoistCtrl::Event - generated Event

Definition at line 158 of file HoistCtrl.cpp.

◆ exitAction_high()

void HoistCtrl::exitAction_high ( )
private

executes the exit action of the high state.

Definition at line 164 of file HoistCtrl.cpp.

◆ entryAction_lowering()

void HoistCtrl::entryAction_lowering ( )
private

executes the entry action of the lowering state.

Attach Servo.

Definition at line 169 of file HoistCtrl.cpp.

◆ doAction_lowering()

HoistCtrl::Event HoistCtrl::doAction_lowering ( )
private

executes the main action of the lowering state.

Lower the hoist till the lowposition is reached and then generate the event PosReached. else return NoEvent.

Returns
HoistCtrl::Event - generated Event

Definition at line 177 of file HoistCtrl.cpp.

◆ exitAction_lowering()

void HoistCtrl::exitAction_lowering ( )
private

executes the exit action of the lowering state.

Detache the Servo.

Definition at line 186 of file HoistCtrl.cpp.

◆ entryAction_errorState()

void HoistCtrl::entryAction_errorState ( )
private

entry action of the errorState state.

Definition at line 192 of file HoistCtrl.cpp.

◆ doAction_errorState()

HoistCtrl::Event HoistCtrl::doAction_errorState ( )
private

main action of the errorState state.

Returns
HoistCtrl::Event - generated Event

Definition at line 200 of file HoistCtrl.cpp.

◆ exitAction_errorState()

void HoistCtrl::exitAction_errorState ( )
private

exit action of the errorState state.

Definition at line 206 of file HoistCtrl.cpp.

◆ entryAction_resetState()

void HoistCtrl::entryAction_resetState ( )
private

entry action of the resetState

attach servo

Definition at line 211 of file HoistCtrl.cpp.

◆ doAction_resetState()

HoistCtrl::Event HoistCtrl::doAction_resetState ( )
private

main action of the resetState

lower the hoist and then detach the servo

Returns
DriveCtrl::Event - generated Event

Definition at line 218 of file HoistCtrl.cpp.

◆ exitAction_resetState()

void HoistCtrl::exitAction_resetState ( )
private

exit action of the resetState

Definition at line 227 of file HoistCtrl.cpp.

◆ decodeState()

String HoistCtrl::decodeState ( State  state)
private

Decodes the State-Enum and returns a description.

Parameters
state- enum State
Returns
String - State as String

Definition at line 233 of file HoistCtrl.cpp.

◆ decodeEvent()

String HoistCtrl::decodeEvent ( Event  event)
private

Decodes the Event-Enum and returns a description.

Parameters
event- enum Event
Returns
String - Event as String

Definition at line 258 of file HoistCtrl.cpp.

Member Data Documentation

◆ lastStateBevorError

State HoistCtrl::lastStateBevorError
private

holds the last state of the FSM so it's possible to resume after error

Definition at line 84 of file HoistCtrl.h.

◆ currentState

State HoistCtrl::currentState
private

holds the current state of the FSM

Definition at line 85 of file HoistCtrl.h.

◆ currentEvent

Event HoistCtrl::currentEvent
private

holds the current event of the FSM

Definition at line 86 of file HoistCtrl.h.

◆ doActionFPtr

Event(HoistCtrl::* HoistCtrl::doActionFPtr) (void) = nullptr
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 93 of file HoistCtrl.h.

◆ pHoist

Hoist Object.

Definition at line 95 of file HoistCtrl.h.


The documentation for this class was generated from the following files: