SmartVehicle-Sortic
SmartFactory
VehicleCtrl.h
Go to the documentation of this file.
1 
17 #ifndef BOXCTRL_H__
18 #define BOXCTRL_H__
19 
20 #include <Arduino.h>
21 
22 // own files:
23 #include "Configuration.h"
24 
25 #include "HoistCtrl.h"
26 #include "MQTTCommunication.h"
27 #include "NavigationCtrl.h"
28 
34 class VehicleCtrl {
35  //=====PUBLIC====================================================================================
36  public:
41  struct Vehicle {
42  String id = DEFAULT_HOSTNAME;
47  String cargo = "null";
48  String status = "null";
49  String substate = "null";
50  String ack = "null";
51  String req = "null";
52  } vehicle;
53 
58  enum class Event { PosReached,
59  HSsucessful,
62  Error,
63  Resume,
64  Reset,
65  NoEvent
66  };
67 
80  VehicleCtrl();
85  void loop();
86 
92  void loop(Event currentEvent);
93 
94  //=====PRIVATE====================================================================================
95  private:
101  void process(Event e);
102 
108  enum class State { waitForBox,
109  handshake,
110  loadVehicle,
111  unloadVehicle,
112  resetState,
113  errorState
114  };
115 
119  int substate = 0;
122  unsigned int pRandomDelayFactor = 0;
123 
128  Event (VehicleCtrl::*doActionFPtr)(void) = nullptr;
129 
131  Communication pComm = Communication(DEFAULT_HOSTNAME);
132  HoistCtrl pHoistCtrl;
133 
134  unsigned long currentMillis = 0;
135  unsigned long previousMillis = 0;
136  unsigned long previousMillisPublishToken = 0;
137  unsigned long previousMillisPublish = 0;
138  unsigned long previousMillisPublishPos = 0;
139 
140  //=====StateFunctions===============================================================
141  //==waitForBox==========================================================
151  void entryAction_waitForBox();
152 
167 
175  void exitAction_waitForBox();
176 
177  //==handshake==========================================================
184  void entryAction_handshake();
185 
207 
213  void exitAction_handshake();
214 
215  //==loadVehicle==========================================================
225 
270 
275  void exitAction_loadVehicle();
276 
277  //==unloadVehicle==========================================================
285 
369 
375 
376  //==errorState==========================================================
382  void entryAction_errorState();
383 
392 
397  void exitAction_errorState();
398 
399  //==resetState==========================================================
404  void entryAction_resetState();
405 
414 
419  void exitAction_resetState();
420  //============================================================================
421  //==Aux-Function==============================================================
428  String decodeState(State state);
429 
436  String decodeEvent(Event event);
437 
444  void publishState(State state);
445 
451  void publishPosition();
452 
457  void publishTargetPosition();
458 
460 
467  bool checkForError();
468 
473  void clearGui();
474 };
475 #endif
unsigned int pRandomDelayFactor
some sort of ALOHA stuff
Definition: VehicleCtrl.h:122
Event currentEvent
holds the current event of the FSM
Definition: VehicleCtrl.h:118
int actualLine
actual line initialised with 1
Definition: VehicleCtrl.h:44
VehicleCtrl::Event doAction_resetState()
main action of the resetState
void publishTargetPosition()
Update position and Publish actual position.
VehicleCtrl::Event doAction_unloadVehicle()
main action of the unloadVehicle
VehicleCtrl::Event doAction_waitForBox()
main action of the waitForBox
Handshake was sucessful.
NavigationCtrl::Sector targetSector
actual sector initialise with Sortic handover
Definition: VehicleCtrl.h:45
void publishTargetPositionBlockLine()
bool checkForError()
Check if a new message with a error is received.
Resume after Error occured.
unsigned long previousMillisPublishToken
will store last time token published
Definition: VehicleCtrl.h:136
String ack
ack for handshake vehicle
Definition: VehicleCtrl.h:50
Event
Enum holds all possible events.
Definition: VehicleCtrl.h:58
String req
req for handshake vehicle
Definition: VehicleCtrl.h:51
VehicleCtrl::Event doAction_errorState()
main action of the errorState
void entryAction_loadVehicle()
entry action of the loadVehicle
VehicleCtrl()
Construct a new Vehicle Ctrl object.
Definition: VehicleCtrl.cpp:15
wait for box to transport
unsigned long previousMillis
will store last time published
Definition: VehicleCtrl.h:135
Event(VehicleCtrl::* doActionFPtr)(void)
Functionpointer to call the current states do-function.
Definition: VehicleCtrl.h:128
No event generated.
void exitAction_handshake()
exit action of the handshake
HoistCtrl pHoistCtrl
Hoist Controll object.
Definition: VehicleCtrl.h:132
void process(Event e)
changes the state of the FSM based on the event
Definition: VehicleCtrl.cpp:43
The Vehicle Controll class contains the FSM for the complete Vehicle.
Definition: VehicleCtrl.h:34
NavigationCtrl::Sector actualSector
actual sector initialise with Sortic handover
Definition: VehicleCtrl.h:43
NavigationCtrl pNavCtrl
Navigation Controll object.
Definition: VehicleCtrl.h:130
String substate
substatus of the Vhicle
Definition: VehicleCtrl.h:49
int pTransferPark[SORTIC_MAX_LINE]
Sortic with 10 diffrent lines.
Definition: VehicleCtrl.h:121
State
Enum holds all possible state's.
Definition: VehicleCtrl.h:108
int pSorticPark[SORTIC_MAX_LINE]
Sortic with 10 diffrent lines.
Definition: VehicleCtrl.h:120
void clearGui()
clear node Red gui
Contains the FSM for the Navigation.
const int DEFAUL_HOSTNAME_NUMBER
defines also startline.
Definition: Configuration.h:25
String cargo
cargo; not used atm
Definition: VehicleCtrl.h:47
VehicleCtrl::Event doAction_loadVehicle()
main action of the loadVehicle
VehicleCtrl::Event doAction_handshake()
main action of the handshake
void exitAction_waitForBox()
exit action of the waitForBox
unsigned long previousMillisPublish
will store last publish time
Definition: VehicleCtrl.h:137
Communication pComm
Communication object.
Definition: VehicleCtrl.h:131
unsigned long currentMillis
will store current time
Definition: VehicleCtrl.h:134
void exitAction_unloadVehicle()
exit action of the unloadVehicle
void exitAction_errorState()
exit action of the errorState
Vehicle is in position.
The Navigation Controll class contains the FSM for the Navigation.
State currentState
holds the current state of the FSM
Definition: VehicleCtrl.h:117
String status
status of the Vehicle FSM
Definition: VehicleCtrl.h:48
void entryAction_waitForBox()
entry action of the waitForBox
String decodeState(State state)
Decodes the State-Enum and returns a description.
void entryAction_errorState()
entry action of the errorState
const unsigned int SORTIC_MAX_LINE
How many lines are available. Needed atm to choose a free line without handshake with sortic.
Definition: Configuration.h:22
void loop()
Calls the do-function of the active state and hence generates Events.
Definition: VehicleCtrl.cpp:31
Holds all relevant infos for the Vehicle.
Definition: VehicleCtrl.h:41
int targetLine
tartget line initialised with 1
Definition: VehicleCtrl.h:46
struct VehicleCtrl::Vehicle vehicle
void exitAction_resetState()
exit action of the resetState
void entryAction_resetState()
entry action of the resetState
void publishState(State state)
Update State and Publish actual state.
unsigned long previousMillisPublishPos
will store last publish position time
Definition: VehicleCtrl.h:138
void entryAction_handshake()
entry action of the handshake
#define DEFAULT_HOSTNAME
Hostname of the vehicle. Used for Communication and identification. Needs to be unique.
Definition: Configuration.h:26
int substate
actual Substate of FSM
Definition: VehicleCtrl.h:119
String decodeEvent(Event event)
Decodes the Event-Enum and returns a description.
void entryAction_unloadVehicle()
entry action of the unloadVehicle
void exitAction_loadVehicle()
exit action of the loadVehicle
void publishPosition()
Update position and Publish actual position.
State lastStateBevorError
holds the last state of the FSM so it's possible to resume after error
Definition: VehicleCtrl.h:116
File that contains the configuratioindetails of the different modules.
Reset after Error occured.
Sector
Enum holds all possible sectors.