Files
Bachelorarbeit-Rover/src/driveModi/driveManager.cpp
T

83 lines
2.0 KiB
C++

/**
* @file driveManager.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief Implemention of the class DriveManager
* @version 0.1
* @date 2021-12-14
*
* @copyright Copyright (c) 2021
*
*/
#include "driveModi/driveManager.h"
Modi& operator++(Modi& m, int) {
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
}
DriveManager::DriveManager(MoveControl *moveControl) {
this->moveControl = moveControl;
// TODO: Delete magic numbers
this->navigation = new Navigation(17, 16);
}
DriveManager::~DriveManager() {
delete this->navigation;
}
void DriveManager::loop() {
this->moveControl->loop();
this->navigation->loop();
if (currentModusPtr)
this->currentModusPtr->loop();
}
void DriveManager::nextModus() {
changeModus(this->currentModus++);
}
void DriveManager::changeModus(Modi modus) {
this->currentModus = modus;
//Set moveControl to a safe state
delete this->currentModusPtr;
this->moveControl->setSpeed(0);
this->moveControl->setRotationspeed(0);
this->moveControl->setDrivingStatus(DrivingStatus::stop);
switch (modus) {
case Modi::Off:
this->currentModusPtr = nullptr;
break;
case Modi::ManualControl: {
this->currentModusPtr = new ManualControl(this->moveControl);
}
break;
case Modi::CaptureRoute: {
this->currentModusPtr = new CaptureRoute(this->moveControl, this->navigation);
}
break;
case Modi::Autopilot: {
this->currentModusPtr = new Autopilot(this->moveControl, this->navigation);
}
break;
case Modi::ConsolControl:
this->currentModusPtr = nullptr;
break;
case Modi::TestMode:
this->currentModusPtr = nullptr;
break;
default:
this->currentModusPtr = nullptr;
break;
}
}