Move initialisation in state machine
This commit is contained in:
parent
e7e40ef3b6
commit
e5fc3f9f38
@ -1 +1,40 @@
|
||||
#include "lfr_state_machine.h"
|
||||
|
||||
LFR_StateMachine::LFR_StateMachine(LFR_IState& startState):
|
||||
autonomousMode(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, [&](std::exception const &ex)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::cerr<<"camera exception:"<<ex.what()<<std::endl;
|
||||
return false;
|
||||
}),
|
||||
uartCommunicator(),
|
||||
socket([&](std::exception const &ex)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::cerr<<"socket exception:"<<ex.what()<<std::endl;
|
||||
return false;
|
||||
})
|
||||
{
|
||||
// Connect String parser to socket
|
||||
socket.addListener([&](LFR_Socket::LFR_Telegram telegram)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::cout << telegram;
|
||||
}, &mutex);
|
||||
socket.startLoop();
|
||||
|
||||
currentState = &startState;
|
||||
currentState->enter(this);
|
||||
|
||||
//Start the permanent loop
|
||||
char input;
|
||||
std::cout << "press q to quit" << std::endl;
|
||||
std::cin >> input;
|
||||
std::cout << "binned" << std::endl;
|
||||
while (input != 'q')
|
||||
{
|
||||
std::cin >> input;
|
||||
std::cout << "binned" << std::endl;
|
||||
}
|
||||
std::cout << "Exiting central" << std::endl;
|
||||
}
|
@ -1,15 +1,29 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <lfr.h>
|
||||
#include <lfr_socket.h>
|
||||
#include <uart_communication.h>
|
||||
#include "lfr_state_interface.h"
|
||||
|
||||
class LFR_StateMachine
|
||||
{
|
||||
LFR_IState* currentState;
|
||||
LFR_StateMachine() = delete;
|
||||
|
||||
const int thresholdBinary = 140;
|
||||
const int videoHeight = 720;
|
||||
const int videoWidth = 1280;
|
||||
const int gaussKernelSize = 11;
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
LFR autonomousMode;
|
||||
LFR_UART uartCommunicator;
|
||||
LFR_Socket socket;
|
||||
|
||||
|
||||
public:
|
||||
LFR_StateMachine(LFR_IState& startState){
|
||||
currentState = &startState;
|
||||
currentState->enter(this);
|
||||
}
|
||||
LFR_StateMachine(LFR_IState& startState);
|
||||
inline LFR_IState* getCurrentState() const {return currentState;}
|
||||
void setState(LFR_IState& newState)
|
||||
{
|
||||
|
56
main.cpp
56
main.cpp
@ -1,66 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <lfr.h>
|
||||
#include <lfr_socket.h>
|
||||
#include <uart_communication.h>
|
||||
#include "lfr_state_machine.h"
|
||||
#include "lfr_states.h"
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
std::cout << "started central" << std::endl;
|
||||
|
||||
const int thresholdBinary = 140;
|
||||
const int videoHeight = 720;
|
||||
const int videoWidth = 1280;
|
||||
const int gaussKernelSize = 11;
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
// Init State Machine;
|
||||
std::cout << "create State Machine" << std::endl;
|
||||
LFR_StateMachine stateMachine(State::Idle::getInstance());
|
||||
|
||||
// Init LFR Autonomous mode
|
||||
std::cout << "create lfr" << std::endl;
|
||||
LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, [&](std::exception const &ex)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::cerr<<"camera exception:"<<ex.what()<<std::endl;
|
||||
return false;
|
||||
});
|
||||
|
||||
// Init UART Communication
|
||||
std::cout << "create uart" << std::endl;
|
||||
LFR_UART uartCommunicator;
|
||||
|
||||
// Init Socket Communication
|
||||
std::cout << "create socket" << std::endl;
|
||||
LFR_Socket socket([&](std::exception const &ex)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::cerr<<"socket exception:"<<ex.what()<<std::endl;
|
||||
return false;
|
||||
});
|
||||
|
||||
// Connect String parser to socket
|
||||
socket.addListener([&](LFR_Socket::LFR_Telegram telegram)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::cout << telegram;
|
||||
}, &mutex);
|
||||
socket.startLoop();
|
||||
|
||||
|
||||
//Start the permanent loop
|
||||
char input;
|
||||
std::cout << "press q to quit" << std::endl;
|
||||
std::cin >> input;
|
||||
std::cout << "cinned" << std::endl;
|
||||
while (input != 'q')
|
||||
{
|
||||
std::cin >> input;
|
||||
std::cout << "cinned" << std::endl;
|
||||
}
|
||||
std::cout << "Exiting central" << std::endl;
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user