SmartVehicle-Sortic
SmartFactory
VehicleCtrl Class Reference

The Vehicle Controll class contains the FSM for the complete Vehicle. More...

#include <VehicleCtrl.h>

Collaboration diagram for VehicleCtrl:

Classes

struct  Vehicle
 Holds all relevant infos for the Vehicle. More...
 

Public Types

enum  Event {
  Event::PosReached, Event::HSsucessful, Event::AnswerReceived, Event::NoAnswerReceived,
  Event::Error, Event::Resume, Event::Reset, Event::NoEvent
}
 Enum holds all possible events. More...
 

Public Member Functions

 VehicleCtrl ()
 Construct a new Vehicle Ctrl object. 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...
 

Public Attributes

struct VehicleCtrl::Vehicle vehicle
 

Private Types

enum  State {
  State::waitForBox, State::handshake, State::loadVehicle, State::unloadVehicle,
  State::resetState, State::errorState
}
 Enum holds all possible state's. More...
 

Private Member Functions

void process (Event e)
 changes the state of the FSM based on the event More...
 
void entryAction_waitForBox ()
 entry action of the waitForBox More...
 
VehicleCtrl::Event doAction_waitForBox ()
 main action of the waitForBox More...
 
void exitAction_waitForBox ()
 exit action of the waitForBox More...
 
void entryAction_handshake ()
 entry action of the handshake More...
 
VehicleCtrl::Event doAction_handshake ()
 main action of the handshake More...
 
void exitAction_handshake ()
 exit action of the handshake More...
 
void entryAction_loadVehicle ()
 entry action of the loadVehicle More...
 
VehicleCtrl::Event doAction_loadVehicle ()
 main action of the loadVehicle More...
 
void exitAction_loadVehicle ()
 exit action of the loadVehicle More...
 
void entryAction_unloadVehicle ()
 entry action of the unloadVehicle More...
 
VehicleCtrl::Event doAction_unloadVehicle ()
 main action of the unloadVehicle More...
 
void exitAction_unloadVehicle ()
 exit action of the unloadVehicle More...
 
void entryAction_errorState ()
 entry action of the errorState More...
 
VehicleCtrl::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...
 
VehicleCtrl::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...
 
void publishState (State state)
 Update State and Publish actual state. More...
 
void publishPosition ()
 Update position and Publish actual position. More...
 
void publishTargetPosition ()
 Update position and Publish actual position. More...
 
void publishTargetPositionBlockLine ()
 
bool checkForError ()
 Check if a new message with a error is received. More...
 
void clearGui ()
 clear node Red gui 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...
 
int substate = 0
 actual Substate of FSM More...
 
int pSorticPark [SORTIC_MAX_LINE] = {0}
 Sortic with 10 diffrent lines. More...
 
int pTransferPark [SORTIC_MAX_LINE] = {1}
 Sortic with 10 diffrent lines. More...
 
unsigned int pRandomDelayFactor = 0
 some sort of ALOHA stuff More...
 
Event(VehicleCtrl::* doActionFPtr )(void) = nullptr
 Functionpointer to call the current states do-function. More...
 
NavigationCtrl pNavCtrl
 Navigation Controll object. More...
 
Communication pComm = Communication(DEFAULT_HOSTNAME)
 Communication object. More...
 
HoistCtrl pHoistCtrl
 Hoist Controll object. More...
 
unsigned long currentMillis = 0
 will store current time More...
 
unsigned long previousMillis = 0
 will store last time published More...
 
unsigned long previousMillisPublishToken = 0
 will store last time token published More...
 
unsigned long previousMillisPublish = 0
 will store last publish time More...
 
unsigned long previousMillisPublishPos = 0
 will store last publish position time More...
 

Detailed Description

The Vehicle Controll class contains the FSM for the complete Vehicle.

VehicleCtrl.png

Definition at line 34 of file VehicleCtrl.h.

Member Enumeration Documentation

◆ Event

enum VehicleCtrl::Event
strong

Enum holds all possible events.

Enumerator
PosReached 

Vehicle is in position.

HSsucessful 

Handshake was sucessful.

AnswerReceived 

Answer received.

NoAnswerReceived 

No Answer received.

Error 

Error occured.

Resume 

Resume after Error occured.

Reset 

Reset after Error occured.

NoEvent 

No event generated.

Definition at line 58 of file VehicleCtrl.h.

◆ State

enum VehicleCtrl::State
strongprivate

Enum holds all possible state's.

https://stackoverflow.com/questions/18335861/why-is-enum-class-preferred-over-plain-enum

Enumerator
waitForBox 

wait for box to transport

handshake 

handshake

loadVehicle 

load box

unloadVehicle 

unload box

resetState 

reset state

errorState 

error state

Definition at line 108 of file VehicleCtrl.h.

Constructor & Destructor Documentation

◆ VehicleCtrl()

VehicleCtrl::VehicleCtrl ( )

Construct a new Vehicle Ctrl object.

  • Clears GUI
  • Publishs current State and position
  • sets start position in NavigationCtrl
  • subscribe to "Vehicle/vehicle.id/error"
  • subscribe to "Vehicle/error"
  • subscribe to "error"
  • subscribe to "Box/+/handshake"

Definition at line 15 of file VehicleCtrl.cpp.

Member Function Documentation

◆ loop() [1/2]

void VehicleCtrl::loop ( )

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

Definition at line 31 of file VehicleCtrl.cpp.

◆ loop() [2/2]

void VehicleCtrl::loop ( Event  currentEvent)

procceses the current Event and calls the do-function of the active state

Parameters
currentEvent- Event

Definition at line 36 of file VehicleCtrl.cpp.

◆ process()

void VehicleCtrl::process ( Event  e)
private

changes the state of the FSM based on the event

Parameters
e- Event

Definition at line 43 of file VehicleCtrl.cpp.

◆ entryAction_waitForBox()

void VehicleCtrl::entryAction_waitForBox ( )
private

entry action of the waitForBox

  • publish current state and position
  • clear old message from circular buffer
  • publish "Vehicle/vehicle.id/handshake" {ack:"",req:""} to clear GUI-Entry
  • subscribe to "Box/+/handshake"
  • publish to target sector to clear GUI-Entry

Definition at line 128 of file VehicleCtrl.cpp.

◆ doAction_waitForBox()

VehicleCtrl::Event VehicleCtrl::doAction_waitForBox ( )
private

main action of the waitForBox

  • check incomming message for error
  • check if a Box requests the vehicle
  • publish all xx seconds "Vehicle/vehicle.id/availabel" {"sector": "actualSector", "line":number}
Returns
VehicleCtrl::Event - generated Event

Definition at line 149 of file VehicleCtrl.cpp.

◆ exitAction_waitForBox()

void VehicleCtrl::exitAction_waitForBox ( )
private

exit action of the waitForBox

  • unsubscribe "Box/+/handshake"
  • publish "Vehicle/vehicle.id/available", {"id":"vehicle.id","sector":""","line":""} to clear GUI-Entry

Definition at line 175 of file VehicleCtrl.cpp.

◆ entryAction_handshake()

void VehicleCtrl::entryAction_handshake ( )
private

entry action of the handshake

  • publish current state and position
  • subscribe to "Box/vehicle.req/handshake"

Definition at line 182 of file VehicleCtrl.cpp.

◆ doAction_handshake()

VehicleCtrl::Event VehicleCtrl::doAction_handshake ( )
private

main action of the handshake

VehicleCtrlHandshake.png

0 check for ack

  • check if Box ack vehicle
    • update targetSector and targetLine
    • switch to next state
  • if timeout
    • return Event:NoAnswerReceived

10 publish ack for Box 5 times

  • "Vehicle/vehicle.id/handshake" {"id":"vehicle.id","ack":"vehicle.ack "}
    • return Event:HSsucessful
Returns
VehicleCtrl::Event - generated Event

Definition at line 195 of file VehicleCtrl.cpp.

◆ exitAction_handshake()

void VehicleCtrl::exitAction_handshake ( )
private

exit action of the handshake

  • unsubscribe from "Box/vehicle.req/handshake"

Definition at line 250 of file VehicleCtrl.cpp.

◆ entryAction_loadVehicle()

void VehicleCtrl::entryAction_loadVehicle ( )
private

entry action of the loadVehicle

Definition at line 256 of file VehicleCtrl.cpp.

◆ doAction_loadVehicle()

VehicleCtrl::Event VehicleCtrl::doAction_loadVehicle ( )
private

main action of the loadVehicle

VehicleCtrlLoad.png
  • check incomming message for error
  • publish position and targetposition all TIME_BETWEEN_PUBLISH seconds

0 check position

  • if in positon switch to state 40 "raise hoist"
  • if in sector SorticWaitForGateway
    • subscribe to "Sortic/Gateway"
  • if in sector TransferWaitForGateway
    • subscribe to "Transfer/Gateway"

10 wait for gateway

  • listen if no token is published for current gateway for xx seconds + some random time

11 listen if only one in gateway

  • publish token for gateway and check if the only one for xx seconds
  • if not available go back to 10 "wait for gateway"
  • else go to 20 "check which gateway to block"

20 check which gateway to block

  • if in sector SorticGateway go to 21 "block Gateway Sortic"
  • if in sector TransitGateway go to 22 "block gateway Transfer"

21 block Gateway Sortic

  • publish token to Gateway as long as in sector Gateway
  • go to substate 30 "chek if in position"

22 block gateway Transfer

  • publish token to Gateway as long as in sector Gateway
  • go to substate 30 "chek if in position"

30 chek if in position

  • if current sector = target sector go to 40 " raise hoist"

40 raise hoist

Returns
VehicleLevelCtrl::Event - generated Event

Definition at line 278 of file VehicleCtrl.cpp.

◆ exitAction_loadVehicle()

void VehicleCtrl::exitAction_loadVehicle ( )
private

exit action of the loadVehicle

Definition at line 419 of file VehicleCtrl.cpp.

◆ entryAction_unloadVehicle()

void VehicleCtrl::entryAction_unloadVehicle ( )
private

entry action of the unloadVehicle

  • publish current state and position
  • publish empty targe pos to clear GUI-Entry

Definition at line 425 of file VehicleCtrl.cpp.

◆ doAction_unloadVehicle()

VehicleCtrl::Event VehicleCtrl::doAction_unloadVehicle ( )
private

main action of the unloadVehicle

VehicleCtrlUnload.png
  • check incomming message for error
  • return Event::Error
  • publish position and targetposition all TIME_BETWEEN_PUBLISH seconds

0 check actual sector and subscribe to handover

  • if in SorticHandover subscirbe to "Transfer/Handover" and switch state to 10 "search suitable targetPos Transfer"
  • if in TransferHandover subscirbe to "Sortic/Handover" and switch state to 20 "search suitable targetPos Sortic"

10 search suitable targetPos Transfer

  • listen for places with matching cargo till timeout is reached
  • listen to occupied places till timeout is reached
  • evaluate new targetposition
  • if targetposition is valid
    • publish targetposition and switch state to 11 "ensure valid target position Transfer"

11 ensure valid target position Transfer

  • publish target position and listen if not occupied

20 search suitable targetPos Sortic

  • listen to occupied places till timeout is reached
  • evaluate new targetposition
  • if targetposition is valid
    • publish targetposition and switch state to 21 "ensure valid target position Sortic"

21 ensure valid target position Sortic

  • publish target position and listen if not occupied

50 set targetposition

  • set Navigation TargetPosition
  • send Event MoveToTargetPosition to NavigationCtrl
  • switch to substate 100 "check position"

100 check position

  • if already in position switcht to substate 400
  • check in which sector and subscribe to actual gateway
    • if waiting for gateway Sortic subscribe to "Sortic/Gateway"
    • if waiting for gateway Transfer subscribe to "Transfer/Gateway"
    • switch substate to 200 "wait for free gateway"

200 wait for free gateway

  • listen if no token is published for current gateway for xx seconds + some random time

210 listen if only one in gateway

  • publish token for gateway and check if the only one for xx seconds
  • if not available go back to 200 "wait for free gateway"
  • else go to 20 "check which gateway to block"

300 check which gateway to block

  • if in sector SorticGateway go to 21 "block Gateway Sortic"
  • if in sector TransitGateway go to 22 "block gateway Transfer"

310 block gateway Sortic

  • publish token to Gateway as long as in sector Gateway
  • go to substate 400 "chek if in position"

320 block gateway Transfer

  • publish token to Gateway as long as in sector Gateway
  • go to substate 400 "chek if in position"

400 chek if in position

  • if current sector = target sector
    • go to 500 "lower hoist"
  • if current sector = TransitWaitForGatewaySortic
    • subscribe to "Sortic/Gateway"
    • go to 200 "wait for free gateway"
  • if current sector = TransitWaitForGatewayTransfer
    • subscribe to "Transfer/Gateway"
    • go to 200 "wait for free gateway"

500 lower hoist

  • if hoist is low go to 600 "publish position to Box"

600 publish position to Box

Returns
VehicleLevelCtrl::Event - generated Event

Definition at line 437 of file VehicleCtrl.cpp.

◆ exitAction_unloadVehicle()

void VehicleCtrl::exitAction_unloadVehicle ( )
private

exit action of the unloadVehicle

Definition at line 783 of file VehicleCtrl.cpp.

◆ entryAction_errorState()

void VehicleCtrl::entryAction_errorState ( )
private

entry action of the errorState

pass Errorevent to Hoist and NavCtrl

Definition at line 788 of file VehicleCtrl.cpp.

◆ doAction_errorState()

VehicleCtrl::Event VehicleCtrl::doAction_errorState ( )
private

main action of the errorState

check for reset message

Returns
VehicleLevelCtrl::Event - generated Event

Definition at line 799 of file VehicleCtrl.cpp.

◆ exitAction_errorState()

void VehicleCtrl::exitAction_errorState ( )
private

exit action of the errorState

Definition at line 822 of file VehicleCtrl.cpp.

◆ entryAction_resetState()

void VehicleCtrl::entryAction_resetState ( )
private

entry action of the resetState

Definition at line 828 of file VehicleCtrl.cpp.

◆ doAction_resetState()

VehicleCtrl::Event VehicleCtrl::doAction_resetState ( )
private

main action of the resetState

check for resume message

Returns
VehicleLevelCtrl::Event - generated Event

Definition at line 844 of file VehicleCtrl.cpp.

◆ exitAction_resetState()

void VehicleCtrl::exitAction_resetState ( )
private

exit action of the resetState

Definition at line 861 of file VehicleCtrl.cpp.

◆ decodeState()

String VehicleCtrl::decodeState ( State  state)
private

Decodes the State-Enum and returns a description.

Parameters
state- enum State
Returns
String - State as String

Definition at line 873 of file VehicleCtrl.cpp.

◆ decodeEvent()

String VehicleCtrl::decodeEvent ( Event  event)
private

Decodes the Event-Enum and returns a description.

Parameters
event- enum Event
Returns
String - Event as String

Definition at line 899 of file VehicleCtrl.cpp.

◆ publishState()

void VehicleCtrl::publishState ( State  state)
private

Update State and Publish actual state.

  • update vehicle state
  • publishMessage "Vehicle/vehicle.id/status" {"status":"vehicle.status"}
    Parameters
    state- state for update

Definition at line 974 of file VehicleCtrl.cpp.

◆ publishPosition()

void VehicleCtrl::publishPosition ( )
private

Update position and Publish actual position.

  • update vehicle position
  • publishMessage "Vehicle/vehicle.id/position" {"sector":vehicle.actualSector,"line":vehicle.actualLine"}

Definition at line 979 of file VehicleCtrl.cpp.

◆ publishTargetPosition()

void VehicleCtrl::publishTargetPosition ( )
private

Update position and Publish actual position.

  • publishMessage "Vehicle/vehicle.id/position" {"sector":vehicle.targetSector,"line":vehicle.targetLine"}

Definition at line 990 of file VehicleCtrl.cpp.

◆ publishTargetPositionBlockLine()

void VehicleCtrl::publishTargetPositionBlockLine ( )
private

Definition at line 997 of file VehicleCtrl.cpp.

◆ checkForError()

bool VehicleCtrl::checkForError ( )
private

Check if a new message with a error is received.

Returns
true - error received
false - no error received

Definition at line 961 of file VehicleCtrl.cpp.

◆ clearGui()

void VehicleCtrl::clearGui ( )
private

clear node Red gui

Definition at line 1020 of file VehicleCtrl.cpp.

Member Data Documentation

◆ vehicle

struct VehicleCtrl::Vehicle VehicleCtrl::vehicle

◆ lastStateBevorError

State VehicleCtrl::lastStateBevorError
private

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

Definition at line 116 of file VehicleCtrl.h.

◆ currentState

State VehicleCtrl::currentState
private

holds the current state of the FSM

Definition at line 117 of file VehicleCtrl.h.

◆ currentEvent

Event VehicleCtrl::currentEvent
private

holds the current event of the FSM

Definition at line 118 of file VehicleCtrl.h.

◆ substate

int VehicleCtrl::substate = 0
private

actual Substate of FSM

Definition at line 119 of file VehicleCtrl.h.

◆ pSorticPark

int VehicleCtrl::pSorticPark[SORTIC_MAX_LINE] = {0}
private

Sortic with 10 diffrent lines.

Definition at line 120 of file VehicleCtrl.h.

◆ pTransferPark

int VehicleCtrl::pTransferPark[SORTIC_MAX_LINE] = {1}
private

Sortic with 10 diffrent lines.

Definition at line 121 of file VehicleCtrl.h.

◆ pRandomDelayFactor

unsigned int VehicleCtrl::pRandomDelayFactor = 0
private

some sort of ALOHA stuff

Definition at line 122 of file VehicleCtrl.h.

◆ doActionFPtr

Event(VehicleCtrl::* VehicleCtrl::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 128 of file VehicleCtrl.h.

◆ pNavCtrl

NavigationCtrl VehicleCtrl::pNavCtrl
private

Navigation Controll object.

Definition at line 130 of file VehicleCtrl.h.

◆ pComm

Communication VehicleCtrl::pComm = Communication(DEFAULT_HOSTNAME)
private

Communication object.

Definition at line 131 of file VehicleCtrl.h.

◆ pHoistCtrl

HoistCtrl VehicleCtrl::pHoistCtrl
private

Hoist Controll object.

Definition at line 132 of file VehicleCtrl.h.

◆ currentMillis

unsigned long VehicleCtrl::currentMillis = 0
private

will store current time

Definition at line 134 of file VehicleCtrl.h.

◆ previousMillis

unsigned long VehicleCtrl::previousMillis = 0
private

will store last time published

Definition at line 135 of file VehicleCtrl.h.

◆ previousMillisPublishToken

unsigned long VehicleCtrl::previousMillisPublishToken = 0
private

will store last time token published

Definition at line 136 of file VehicleCtrl.h.

◆ previousMillisPublish

unsigned long VehicleCtrl::previousMillisPublish = 0
private

will store last publish time

Definition at line 137 of file VehicleCtrl.h.

◆ previousMillisPublishPos

unsigned long VehicleCtrl::previousMillisPublishPos = 0
private

will store last publish position time

Definition at line 138 of file VehicleCtrl.h.


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