11#ifndef STATEMACHINEHANDLER_H
12#define STATEMACHINEHANDLER_H
16#include "../states/ApproachingMarkerState.h"
17#include "../states/ApproachingObjectState.h"
18#include "../states/AvoidanceState.h"
19#include "../states/IdleState.h"
20#include "../states/NavigatingState.h"
21#include "../states/ReversingState.h"
22#include "../states/SearchPatternState.h"
23#include "../states/StuckState.h"
24#include "../states/VerifyingMarkerState.h"
25#include "../states/VerifyingObjectState.h"
26#include "../states/VerifyingPositionState.h"
29#include <RoveComm/RoveComm.h>
30#include <RoveComm/RoveCommManifest.h>
32#include <shared_mutex>
51 std::shared_ptr<statemachine::State> m_pCurrentState;
52 std::shared_ptr<statemachine::State> m_pPreviousState;
53 std::unordered_map<statemachine::States, std::shared_ptr<statemachine::State>> m_umSavedStates;
54 std::shared_mutex m_muStateMutex;
55 std::shared_mutex m_muEventMutex;
56 std::atomic_bool m_bSwitchingStates;
78 [
this](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
85 LOG_INFO(logging::g_qSharedLogger,
"Incoming Packet: Start Autonomy!");
99 const std::function<void(
const rovecomm::RoveCommPacket<uint8_t>&,
const sockaddr_in&)>
AutonomyStopCallback =
100 [
this](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
107 LOG_INFO(logging::g_qSharedLogger,
"Incoming Packet: Abort Autonomy!");
110 this->
HandleEvent(statemachine::Event::eAbort,
true);
122 [
this](
const rovecomm::RoveCommPacket<float>& stPacket,
const sockaddr_in& stdAddr)
128 double dTotalCellVoltages = 0.0;
129 int nValidCellVoltageValues = 0;
132 for (
int nIter = 0; nIter < stPacket.unDataCount; ++nIter)
135 if (stPacket.vData[nIter] >= 0.1)
138 dTotalCellVoltages += stPacket.vData[nIter];
140 ++nValidCellVoltageValues;
144 double dAverageCellVoltage = dTotalCellVoltages / nValidCellVoltageValues;
147 LOG_DEBUG(logging::g_qSharedLogger,
"Incoming Packet: PMS Cell Voltages. Average voltage is: {}", dAverageCellVoltage);
150 if (constants::BATTERY_CHECKS_ENABLED && dAverageCellVoltage < constants::BATTERY_MINIMUM_CELL_VOLTAGE &&
154 LOG_CRITICAL(logging::g_qSharedLogger,
155 "Incoming PMS Packet: Average cell voltage is {} which is below the safe minimum of {}. Entering Idle state...",
157 constants::BATTERY_MINIMUM_CELL_VOLTAGE);
160 this->
HandleEvent(statemachine::Event::eAbort,
true);
Defines the CameraHandler class.
Interface class used to easily multithread a child class.
Definition AutonomyThread.hpp:38
IPS & GetIPS()
Accessor for the Frame I P S private member.
Definition AutonomyThread.hpp:224
The StateMachineHandler class serves as the main state machine for Autonomy Software....
Definition StateMachineHandler.h:46
void StartStateMachine()
This method will start the state machine. It will set the first state to Idle and start the thread po...
Definition StateMachineHandler.cpp:178
void ClearSavedState(statemachine::States eState)
Clear a saved state based on the given state.
Definition StateMachineHandler.cpp:378
const std::function< void(const rovecomm::RoveCommPacket< uint8_t > &, const sockaddr_in &)> AutonomyStartCallback
Callback function used to trigger the start of autonomy. No matter what state we are in,...
Definition StateMachineHandler.h:77
void ClearSavedStates()
Clear all saved states.
Definition StateMachineHandler.cpp:360
statemachine::States GetCurrentState() const
Accessor for the Current State private member.
Definition StateMachineHandler.cpp:394
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> PMSCellVoltageCallback
Callback function used to force autonomy into Idle state if battery voltage gets too low....
Definition StateMachineHandler.h:121
void PooledLinearCode() override
This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method....
Definition StateMachineHandler.cpp:321
std::shared_ptr< statemachine::State > CreateState(statemachine::States eState)
Create a State object based of of the State enum.
Definition StateMachineHandler.cpp:74
void RealignZEDPosition(CameraHandler::ZEDCamName eCameraName, const geoops::UTMCoordinate &stNewCameraPosition, const double dNewCameraHeading)
This is used to realign the ZEDs forward direction with the rover's current compass heading....
Definition StateMachineHandler.cpp:427
const std::function< void(const rovecomm::RoveCommPacket< uint8_t > &, const sockaddr_in &)> AutonomyStopCallback
Callback function used to trigger autonomy to stop. No matter what state we are in,...
Definition StateMachineHandler.h:99
void ThreadedContinuousCode() override
This code will run continuously in a separate thread. The State Machine Handler will check the curren...
Definition StateMachineHandler.cpp:227
StateMachineHandler()
Construct a new State Machine Handler object.
Definition StateMachineHandler.cpp:23
statemachine::States GetPreviousState() const
Accessor for the Previous State private member.
Definition StateMachineHandler.cpp:407
~StateMachineHandler()
Destroy the State Machine Handler:: State Machine Handler object.
Definition StateMachineHandler.cpp:55
void StopStateMachine()
This method will stop the state machine. It will signal whatever state is currently running to abort ...
Definition StateMachineHandler.cpp:200
void HandleEvent(statemachine::Event eEvent, const bool bSaveCurrentState=false)
This method Handles Events that are passed to the State Machine Handler. It will check the current st...
Definition StateMachineHandler.cpp:337
void ChangeState(statemachine::States eNextState, const bool bSaveCurrentState=false)
Transition to a new state. This function is called by the HandleEvent and checks to see if this state...
Definition StateMachineHandler.cpp:110
void SaveCurrentState()
Save the current state to the map of exited states. This is used to store the state when the state ma...
Definition StateMachineHandler.cpp:163
This class serves as a middle inheritor between the Camera interface and the ZEDCam class....
Definition ZEDCamera.hpp:33
Event
The events that can be triggered in the state machine.
Definition State.hpp:54
States
The states that the state machine can be in.
Definition State.hpp:31
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:148
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:244