driveManager gets now the object
This commit is contained in:
@@ -26,12 +26,11 @@ void DirectionChangeSignal::action() {
|
||||
}
|
||||
|
||||
|
||||
Autopilot::Autopilot(DriveModiParams params, Navigation* navigation)
|
||||
: ManualControl(params) {
|
||||
Autopilot::Autopilot() {
|
||||
this->setInputMode(ManualControl::InputMode::Digital);
|
||||
this->directionChangeSignal = new DirectionChangeSignal(this);
|
||||
this->setDirectionChangeCallback(this->directionChangeSignal);
|
||||
this->navigation = navigation;
|
||||
this->navigation = new Navigation(this->sensorData);
|
||||
this->init();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class Autopilot : public ManualControl {
|
||||
* @param moveControl for ManualControl
|
||||
* @param navigation for route instructions
|
||||
*/
|
||||
Autopilot(DriveModiParams params, Navigation* navigation);
|
||||
Autopilot();
|
||||
|
||||
/**
|
||||
* @brief Destroy the Autopilot object
|
||||
@@ -78,6 +78,7 @@ class Autopilot : public ManualControl {
|
||||
* @return State
|
||||
*/
|
||||
State getState() const { return this->state; }
|
||||
Navigation* getNavigation() const { return this->navigation; }
|
||||
|
||||
/**
|
||||
* @brief Tells if there are new informations to display
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include "calibrateCompassM.h"
|
||||
|
||||
CalibrateCompassM::CalibrateCompassM(DriveModiParams params) : ManualControl(params) {}
|
||||
|
||||
void CalibrateCompassM::setCalibrateCompass(CalibrateCompass *caliCompass) {
|
||||
if (caliCompass) {
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
class CalibrateCompassM : public ManualControl {
|
||||
public:
|
||||
CalibrateCompassM(DriveModiParams params);
|
||||
|
||||
void setCalibrateCompass(CalibrateCompass* caliCompass = nullptr);
|
||||
|
||||
private:
|
||||
|
||||
@@ -11,9 +11,8 @@
|
||||
|
||||
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
||||
|
||||
CaptureRoute::CaptureRoute(DriveModiParams params, Navigation* navigation)
|
||||
: ManualControl(params) {
|
||||
this->navigation = navigation;
|
||||
CaptureRoute::CaptureRoute() {
|
||||
this->navigation = new Navigation(this->sensorData);
|
||||
this->navigation->getRoute()->clear();
|
||||
this->sensorData->getNtripClient()->setAutoReconnect(true);
|
||||
this->routeInfo = navigation->getRouteInfo();
|
||||
|
||||
@@ -27,13 +27,7 @@
|
||||
*/
|
||||
class CaptureRoute : public ManualControl {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Capture Route object
|
||||
*
|
||||
* @param moveControl for ManualControl
|
||||
* @param navigation to add Points
|
||||
*/
|
||||
CaptureRoute(DriveModiParams params, Navigation* navigation);
|
||||
CaptureRoute();
|
||||
|
||||
/**
|
||||
* @brief Destroy the Capture Route object
|
||||
@@ -56,6 +50,7 @@ class CaptureRoute : public ManualControl {
|
||||
*/
|
||||
RouteInfo getRouteInfo() const { return this->routeInfo; }
|
||||
Navigation::Status getLastStatus() const { return this->status; }
|
||||
Navigation* getNavigation() const { return this->navigation; }
|
||||
|
||||
/**
|
||||
* @brief Get the distance to the last saved oint
|
||||
|
||||
@@ -33,8 +33,6 @@ class ManualControl : public DriveModi {
|
||||
Digital
|
||||
};
|
||||
|
||||
ManualControl(DriveModiParams params) : DriveModi(params){};
|
||||
|
||||
void switchInputMode();
|
||||
void setInputMode(InputMode mode) { this->inputMode = mode; }
|
||||
InputMode getInputMode() const { return this->inputMode; }
|
||||
|
||||
@@ -10,15 +10,6 @@
|
||||
*/
|
||||
#include "testMode.h"
|
||||
|
||||
TestMode::TestMode(DriveModiParams params, Navigation* navigation)
|
||||
: DriveModi(params) {
|
||||
this->navigation = navigation;
|
||||
}
|
||||
|
||||
TestMode::~TestMode() {
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
}
|
||||
|
||||
void TestMode::run() {
|
||||
if (this->maneuver == Maneuver::Turn) {
|
||||
uint16_t delta = abs(this->azimuth - this->getSensorData()->getRealAzimuth());
|
||||
|
||||
@@ -38,15 +38,6 @@ class TestMode : public DriveModi {
|
||||
Drive
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Construct a new Test Mode object
|
||||
*
|
||||
* @param moveControl
|
||||
* @param navigation
|
||||
*/
|
||||
TestMode(DriveModiParams params, Navigation* navigation);
|
||||
~TestMode();
|
||||
|
||||
bool drive(int16_t cm = 0, int16_t degree = 0);
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,59 +25,21 @@ DriveManager::DriveManager(DriveModiParams params){
|
||||
this->init();
|
||||
}
|
||||
|
||||
DriveManager::~DriveManager() {
|
||||
delete this->navigation;
|
||||
}
|
||||
|
||||
void DriveManager::changeModus(Modi modus) {
|
||||
this->currentModus = modus;
|
||||
|
||||
void DriveManager::changeModus(DriveModi* modus) {
|
||||
if (this->currentModusPtr) {
|
||||
this->removeChildComponent(this->currentModusPtr);
|
||||
delete this->currentModusPtr;
|
||||
this->currentModusPtr = nullptr;
|
||||
}
|
||||
//Reset Route to first point
|
||||
this->navigation->startNavigation();
|
||||
|
||||
switch (modus) {
|
||||
case Modi::Off:
|
||||
this->currentModusPtr = nullptr;
|
||||
break;
|
||||
|
||||
case Modi::ManualControl: {
|
||||
this->currentModusPtr = new ManualControl(this->driveModiParams);
|
||||
}
|
||||
break;
|
||||
|
||||
case Modi::CaptureRoute: {
|
||||
this->currentModusPtr = new CaptureRoute(this->driveModiParams, this->navigation);
|
||||
}
|
||||
break;
|
||||
|
||||
case Modi::Autopilot: {
|
||||
this->currentModusPtr = new Autopilot(this->driveModiParams, this->navigation);
|
||||
}
|
||||
break;
|
||||
|
||||
case Modi::TestMode: {
|
||||
this->currentModusPtr = new TestMode(driveModiParams, this->navigation);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
this->currentModusPtr = nullptr;
|
||||
break;
|
||||
}
|
||||
this->currentModusPtr = modus;
|
||||
|
||||
if (this->currentModusPtr)
|
||||
this->currentModusPtr->activate(this->driveModiParams);
|
||||
this->addChildComponent(this->currentModusPtr);
|
||||
}
|
||||
|
||||
void DriveManager::init() {
|
||||
this->navigation = new Navigation(this->driveModiParams.sensorData);
|
||||
|
||||
this->addChildComponent(this->driveModiParams.moveControl);
|
||||
this->addChildComponent(this->navigation);
|
||||
this->activateOnlyChilds();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,38 +12,14 @@
|
||||
#ifndef DRIVE_MANAGER_H
|
||||
#define DRIVE_MANAGER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#include "moveControl.h"
|
||||
#include "driveModi/driveModi.h"
|
||||
#include "navigation.h"
|
||||
#include "config.h"
|
||||
#include "networkConfig.h"
|
||||
#include "debugTimes.h"
|
||||
#include "controlPadInput.h"
|
||||
#include "component.h"
|
||||
#include "sensorData.h"
|
||||
|
||||
// All Drive Modi
|
||||
#include "driveModi/Modi/ManualControl/manualControl.h"
|
||||
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
||||
#include "driveModi/Modi/Autopilot/autopilot.h"
|
||||
#include "driveModi/Modi/TestMode/testMode.h"
|
||||
|
||||
/**
|
||||
* @brief An enum to choose the DriveMode
|
||||
*
|
||||
*/
|
||||
enum class Modi {
|
||||
Off,
|
||||
ManualControl,
|
||||
CalibrateCompass,
|
||||
CaptureRoute,
|
||||
Autopilot,
|
||||
TestMode
|
||||
};
|
||||
|
||||
class DriveManager : public Component {
|
||||
public:
|
||||
/**
|
||||
@@ -70,14 +46,7 @@ class DriveManager : public Component {
|
||||
*
|
||||
* @param modus
|
||||
*/
|
||||
void changeModus(Modi modus);
|
||||
|
||||
/**
|
||||
* @brief Get the Navigation object
|
||||
*
|
||||
* @return Navigation*
|
||||
*/
|
||||
Navigation* getNavigation() const {return this->navigation;}
|
||||
void changeModus(DriveModi* modus = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Get the DriveModi Ptr object
|
||||
@@ -91,20 +60,14 @@ class DriveManager : public Component {
|
||||
*/
|
||||
DriveModi* getDriveModiPtr() const { return this->currentModusPtr; }
|
||||
|
||||
/**
|
||||
* @brief Get the DriveModi enum
|
||||
*
|
||||
* @return Modi
|
||||
*/
|
||||
Modi getDriveModi() const { return this->currentModus; }
|
||||
|
||||
bool isActive() const { return this->currentModusPtr; }
|
||||
|
||||
private:
|
||||
void run() override {};
|
||||
void init();
|
||||
|
||||
Modi currentModus = Modi::Off;
|
||||
DriveModi *currentModusPtr = nullptr;
|
||||
Navigation* navigation;
|
||||
DriveModiParams driveModiParams;
|
||||
};
|
||||
|
||||
|
||||
+16
-12
@@ -1,17 +1,7 @@
|
||||
#include "driveModi.h"
|
||||
|
||||
DriveModi::DriveModi(MoveControl* moveControl, ControlPadInput* input, SensorData* sensorData) {
|
||||
this->moveControl = moveControl;
|
||||
this->input = input;
|
||||
this->sensorData = sensorData;
|
||||
this->init();
|
||||
}
|
||||
|
||||
DriveModi::DriveModi(DriveModiParams params){
|
||||
this->moveControl = params.moveControl;
|
||||
this->input = params.input;
|
||||
this->sensorData = params.sensorData;
|
||||
this->init();
|
||||
DriveModi::DriveModi() {
|
||||
this->loopDelay = 0;
|
||||
}
|
||||
|
||||
DriveModi::~DriveModi() {
|
||||
@@ -20,6 +10,20 @@ DriveModi::~DriveModi() {
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
}
|
||||
|
||||
void DriveModi::activate(MoveControl* moveControl, ControlPadInput* input, SensorData* sensorData) {
|
||||
this->moveControl = moveControl;
|
||||
this->input = input;
|
||||
this->sensorData = sensorData;
|
||||
this->init();
|
||||
}
|
||||
|
||||
void DriveModi::activate(DriveModiParams params){
|
||||
this->moveControl = params.moveControl;
|
||||
this->input = params.input;
|
||||
this->sensorData = params.sensorData;
|
||||
this->init();
|
||||
}
|
||||
|
||||
void DriveModi::init() {
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Drive);
|
||||
this->loopDelay = 40;
|
||||
|
||||
@@ -31,12 +31,14 @@ struct DriveModiParams {
|
||||
*/
|
||||
class DriveModi : public Component {
|
||||
public:
|
||||
DriveModi(MoveControl* moveControl, ControlPadInput* input, SensorData* sensorData);
|
||||
DriveModi(DriveModiParams);
|
||||
DriveModi();
|
||||
virtual ~DriveModi();
|
||||
|
||||
const SensorData* getSensorData() const { return this->sensorData; }
|
||||
|
||||
void activate(MoveControl* moveControl, ControlPadInput* input, SensorData* sensorData);
|
||||
void activate(DriveModiParams params);
|
||||
|
||||
/**
|
||||
* @brief Set the max speed
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user