clangtidy corrections part 1
This commit is contained in:
@@ -4,138 +4,161 @@
|
||||
* @brief Contains the implementation of the class Autopilot
|
||||
* @version 0.1
|
||||
* @date 2022-02-02
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "driveModi/Modi/Autopilot/autopilot.h"
|
||||
#include "autopilot.h"
|
||||
|
||||
DirectionChangeSignal::DirectionChangeSignal(Autopilot* pilot) {
|
||||
this->pilot = pilot;
|
||||
DirectionChangeSignal::DirectionChangeSignal(Autopilot *pilot)
|
||||
: pilot {pilot}
|
||||
{
|
||||
this->action();
|
||||
}
|
||||
|
||||
DirectionChangeSignal::~DirectionChangeSignal() {
|
||||
CalcAzimuth* calcAzimuth = pilot->getSensorData()->getCalcCompass();
|
||||
if (calcAzimuth)
|
||||
DirectionChangeSignal::~DirectionChangeSignal()
|
||||
{
|
||||
CalcAzimuth *calcAzimuth = pilot->getSensorData()->getCalcCompass();
|
||||
if (static_cast<bool>(calcAzimuth))
|
||||
{
|
||||
calcAzimuth->disableCalcAzimuth();
|
||||
}
|
||||
}
|
||||
|
||||
void DirectionChangeSignal::action() {
|
||||
CalcAzimuth* calcAzimuth = pilot->getSensorData()->getCalcCompass();
|
||||
if (calcAzimuth)
|
||||
void DirectionChangeSignal::action()
|
||||
{
|
||||
CalcAzimuth *calcAzimuth = pilot->getSensorData()->getCalcCompass();
|
||||
if (static_cast<bool>(calcAzimuth))
|
||||
{
|
||||
calcAzimuth->drivingDirectionChange(pilot->getSensorData()->getCurrentPos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Autopilot::Autopilot() {
|
||||
|
||||
}
|
||||
|
||||
Autopilot::~Autopilot() {
|
||||
Autopilot::~Autopilot()
|
||||
{
|
||||
delete this->directionChangeSignal;
|
||||
// this->navigation->getNTRIPClient()->setActivated(false);
|
||||
}
|
||||
|
||||
void Autopilot::run() {
|
||||
void Autopilot::run()
|
||||
{
|
||||
this->routeInfo = this->navigation->getRouteInfo();
|
||||
|
||||
switch (this->state) {
|
||||
case State::InsufficientAccuracy:
|
||||
this->askNavigationForOrder();
|
||||
return;
|
||||
switch (this->state)
|
||||
{
|
||||
case State::InsufficientAccuracy:
|
||||
this->askNavigationForOrder();
|
||||
return;
|
||||
|
||||
case State::NoRoute:
|
||||
return;
|
||||
case State::NoRoute:
|
||||
return;
|
||||
|
||||
case State::None:
|
||||
return;
|
||||
case State::None:
|
||||
return;
|
||||
|
||||
case State::NavigationStarted:
|
||||
this->askNavigationForOrder();
|
||||
this->checkButtonInput();
|
||||
break;
|
||||
case State::NavigationStarted:
|
||||
this->askNavigationForOrder();
|
||||
this->checkButtonInput();
|
||||
break;
|
||||
|
||||
case State::GetToStartPoint:
|
||||
ManualControl::run();
|
||||
this->askNavigationForOrder();
|
||||
if (this->routeInfo.currentPoint >= 2)
|
||||
this->state = State::SelfDrivingAvailable;
|
||||
break;
|
||||
case State::GetToStartPoint:
|
||||
ManualControl::run();
|
||||
this->askNavigationForOrder();
|
||||
if (this->routeInfo.currentPoint >= 2){
|
||||
this->state = State::SelfDrivingAvailable;
|
||||
}
|
||||
break;
|
||||
|
||||
case State::SelfDrivingAvailable:
|
||||
ManualControl::run();
|
||||
this->askNavigationForOrder();
|
||||
this->checkButtonInput();
|
||||
break;
|
||||
case State::SelfDrivingAvailable:
|
||||
ManualControl::run();
|
||||
this->askNavigationForOrder();
|
||||
this->checkButtonInput();
|
||||
break;
|
||||
|
||||
case State::SelfDriving:
|
||||
this->askNavigationForOrder();
|
||||
this->checkButtonInput();
|
||||
this->selfDriving();
|
||||
break;
|
||||
case State::SelfDriving:
|
||||
this->askNavigationForOrder();
|
||||
this->checkButtonInput();
|
||||
this->selfDriving();
|
||||
break;
|
||||
|
||||
case SelfDrivingRotate:
|
||||
this->checkButtonInput();
|
||||
this->rotate();
|
||||
break;
|
||||
case SelfDrivingRotate:
|
||||
this->checkButtonInput();
|
||||
this->rotate();
|
||||
break;
|
||||
|
||||
case State::TargetReached:
|
||||
if (this->loopMode)
|
||||
this->restartLoop();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case State::TargetReached:
|
||||
if (this->loopMode){
|
||||
this->restartLoop();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::restart() {
|
||||
void Autopilot::restart()
|
||||
{
|
||||
this->init();
|
||||
}
|
||||
|
||||
bool Autopilot::shouldUpdate() {
|
||||
if (this->updateDisplay) {
|
||||
bool Autopilot::shouldUpdate()
|
||||
{
|
||||
if (this->updateDisplay)
|
||||
{
|
||||
this->updateDisplay = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Autopilot::testRotate(int16_t degree) {
|
||||
if (!degree)
|
||||
void Autopilot::testRotate(int16_t degree)
|
||||
{
|
||||
if (!static_cast<bool>(degree))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->courseCorrection.correction = degree;
|
||||
this->beginRotate();
|
||||
}
|
||||
|
||||
void Autopilot::init() {
|
||||
void Autopilot::init()
|
||||
{
|
||||
if (this->navigation->startNavigation())
|
||||
this->state = State::NavigationStarted;
|
||||
else
|
||||
this->state = State::NoRoute;
|
||||
this->routeInfo = this->navigation->getRouteInfo();
|
||||
this->sensorData->getNtripClient()->setAutoReconnect(true);
|
||||
{
|
||||
this->state = State::NavigationStarted;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->state = State::NoRoute;
|
||||
}
|
||||
this->routeInfo = this->navigation->getRouteInfo();
|
||||
this->sensorData->getNtripClient()->setAutoReconnect(true);
|
||||
|
||||
this->lastOrderStatus = this->navigation->getCourseCorrection(this->courseCorrection, true);
|
||||
this->lastOrderStatus = this->navigation->getCourseCorrection(this->courseCorrection, true);
|
||||
|
||||
this->courseCorrection.correction = 0;
|
||||
this->courseCorrection.distance = 0;
|
||||
this->updateDisplay = true;
|
||||
this->courseCorrection.correction = 0;
|
||||
this->courseCorrection.distance = 0;
|
||||
this->updateDisplay = true;
|
||||
}
|
||||
|
||||
void Autopilot::drive() {
|
||||
void Autopilot::drive()
|
||||
{
|
||||
DrivingSpeeds speeds = {0, 0};
|
||||
if (this->courseCorrection.distance >= this->minRemainingDistance)
|
||||
{
|
||||
speeds.x = this->maxSpeeds.x;
|
||||
}
|
||||
this->moveControl->setSpeeds(speeds);
|
||||
}
|
||||
|
||||
void Autopilot::beginRotate() {
|
||||
if (this->state != State::SelfDrivingRotate) {
|
||||
void Autopilot::beginRotate()
|
||||
{
|
||||
if (this->state != State::SelfDrivingRotate)
|
||||
{
|
||||
this->lastState = this->state;
|
||||
this->state = State::SelfDrivingRotate;
|
||||
this->rotationAimAzimuth = this->getSensorData()->getRealAzimuth() + this->courseCorrection.correction;
|
||||
@@ -143,35 +166,40 @@ void Autopilot::beginRotate() {
|
||||
|
||||
DrivingSpeeds speeds = {0, 0};
|
||||
if (this->courseCorrection.correction > 0)
|
||||
{
|
||||
speeds.rot = -this->maxSpeeds.rot;
|
||||
}
|
||||
else
|
||||
{
|
||||
speeds.rot = this->maxSpeeds.rot;
|
||||
}
|
||||
|
||||
this->moveControl->setSpeeds(speeds);
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::rotate() {
|
||||
if (abs(this->getSensorData()->getRealAzimuth() - this->rotationAimAzimuth) < this->maxCourseDeviationBeforeAct) {
|
||||
void Autopilot::rotate()
|
||||
{
|
||||
if (abs(this->getSensorData()->getRealAzimuth() - this->rotationAimAzimuth) < this->maxCourseDeviationBeforeAct)
|
||||
{
|
||||
this->endRotate();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((abs(this->getSensorData()->getRealAzimuth() - this->rotationAimAzimuth) < this->maxCourseDeviationBeforeAct * 3)
|
||||
&&
|
||||
((this->courseCorrection.correction > 0
|
||||
&& this->rotationAimAzimuth < this->getSensorData()->getRealAzimuth())
|
||||
|| (this->courseCorrection.correction < 0
|
||||
&& this->rotationAimAzimuth > this->getSensorData()->getRealAzimuth())))
|
||||
if ((abs(this->getSensorData()->getRealAzimuth() - this->rotationAimAzimuth) < this->maxCourseDeviationBeforeAct * 3) &&
|
||||
((this->courseCorrection.correction > 0 && this->rotationAimAzimuth < this->getSensorData()->getRealAzimuth()) || (this->courseCorrection.correction < 0 && this->rotationAimAzimuth > this->getSensorData()->getRealAzimuth())))
|
||||
{
|
||||
this->endRotate();
|
||||
std::cout << "Autopilot::rotate: Rover rotated too far" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::endRotate() {
|
||||
void Autopilot::endRotate()
|
||||
{
|
||||
if (this->state != State::SelfDrivingRotate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->state = this->lastState;
|
||||
this->sensorData->getCalcCompass()->drivingDirectionChange(this->sensorData->getCurrentPos());
|
||||
@@ -180,65 +208,85 @@ void Autopilot::endRotate() {
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Drive);
|
||||
}
|
||||
|
||||
void Autopilot::checkButtonInput() {
|
||||
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)
|
||||
&& millis() - this->lastAutopilotChangeMillis > this->autopilotChangeDelayMillis) {
|
||||
|
||||
if (this->state == State::SelfDrivingAvailable)
|
||||
void Autopilot::checkButtonInput()
|
||||
{
|
||||
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action) && millis() - this->lastAutopilotChangeMillis > this->autopilotChangeDelayMillis)
|
||||
{
|
||||
|
||||
if (this->state == State::SelfDrivingAvailable)
|
||||
{
|
||||
this->state = State::SelfDriving;
|
||||
}
|
||||
else if (this->state == State::SelfDriving || this->state == State::SelfDrivingRotate)
|
||||
{
|
||||
this->state = State::SelfDrivingAvailable;
|
||||
}
|
||||
else if (this->state == State::NavigationStarted)
|
||||
{
|
||||
this->state = State::GetToStartPoint;
|
||||
}
|
||||
this->updateDisplay = true;
|
||||
this->lastAutopilotChangeMillis = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::askNavigationForOrder() {
|
||||
void Autopilot::askNavigationForOrder()
|
||||
{
|
||||
this->lastOrderStatus = this->navigation->getCourseCorrection(this->courseCorrection);
|
||||
switch (this->lastOrderStatus) {
|
||||
case Navigation::Status::Complete:
|
||||
this->state = State::TargetReached;
|
||||
this->moveControl->setSpeed(0);
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
break;
|
||||
|
||||
case Navigation::Status::InsufficientAccuracy:
|
||||
if (this->state == State::InsufficientAccuracy)
|
||||
break;
|
||||
this->lastState = this->state;
|
||||
this->state = State::InsufficientAccuracy;
|
||||
this->moveControl->setSpeed(0);
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
break;
|
||||
switch (this->lastOrderStatus)
|
||||
{
|
||||
case Navigation::Status::Complete:
|
||||
this->state = State::TargetReached;
|
||||
this->moveControl->setSpeed(0);
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
break;
|
||||
|
||||
case Navigation::Status::Unchanged:
|
||||
if (this->state == State::InsufficientAccuracy)
|
||||
this->state = this->lastState;
|
||||
case Navigation::Status::InsufficientAccuracy:
|
||||
if (this->state == State::InsufficientAccuracy){
|
||||
break;
|
||||
}
|
||||
this->lastState = this->state;
|
||||
this->state = State::InsufficientAccuracy;
|
||||
this->moveControl->setSpeed(0);
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
break;
|
||||
|
||||
case Navigation::Status::Updated:
|
||||
if (this->state == State::InsufficientAccuracy)
|
||||
this->state = this->lastState;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case Navigation::Status::Unchanged:
|
||||
if (this->state == State::InsufficientAccuracy){
|
||||
this->state = this->lastState;
|
||||
}
|
||||
break;
|
||||
|
||||
case Navigation::Status::Updated:
|
||||
if (this->state == State::InsufficientAccuracy){
|
||||
this->state = this->lastState;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::selfDriving() {
|
||||
void Autopilot::selfDriving()
|
||||
{
|
||||
if (this->state != State::SelfDriving)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (abs(this->courseCorrection.correction) >= this->maxCourseDeviationBeforeAct)
|
||||
{
|
||||
this->beginRotate();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->drive();
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::restartLoop() {
|
||||
void Autopilot::restartLoop()
|
||||
{
|
||||
this->navigation->startNavigation();
|
||||
this->state = State::SelfDriving;
|
||||
this->routeInfo = this->navigation->getRouteInfo();
|
||||
@@ -246,7 +294,8 @@ void Autopilot::restartLoop() {
|
||||
this->updateDisplay = true;
|
||||
}
|
||||
|
||||
void Autopilot::afterActivate() {
|
||||
void Autopilot::afterActivate()
|
||||
{
|
||||
this->setInputMode(ManualControl::InputMode::Digital);
|
||||
this->directionChangeSignal = new DirectionChangeSignal(this);
|
||||
this->setDirectionChangeCallback(this->directionChangeSignal);
|
||||
|
||||
@@ -41,14 +41,6 @@ class Autopilot : public ManualControl {
|
||||
TargetReached
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Construct a new Autopilot object
|
||||
*
|
||||
* @param moveControl for ManualControl
|
||||
* @param navigation for route instructions
|
||||
*/
|
||||
Autopilot();
|
||||
|
||||
/**
|
||||
* @brief Destroy the Autopilot object
|
||||
*
|
||||
@@ -104,13 +96,13 @@ class Autopilot : public ManualControl {
|
||||
void restartLoop();
|
||||
void afterActivate() override;
|
||||
|
||||
Navigation* navigation;
|
||||
CourseCorrection courseCorrection;
|
||||
RouteInfo routeInfo;
|
||||
Navigation* navigation = nullptr;
|
||||
CourseCorrection courseCorrection{0, 0};
|
||||
RouteInfo routeInfo{0, 0};
|
||||
State state = State::None;
|
||||
State lastState = State::None;
|
||||
Navigation::Status lastOrderStatus;
|
||||
DirectionChangeSignal* directionChangeSignal;
|
||||
DirectionChangeSignal* directionChangeSignal = nullptr;
|
||||
|
||||
bool updateDisplay = false;
|
||||
bool loopMode = false;
|
||||
@@ -119,7 +111,7 @@ class Autopilot : public ManualControl {
|
||||
uint16_t autopilotChangeDelayMillis = 500;
|
||||
uint32_t lastAutopilotChangeMillis = 0;
|
||||
|
||||
int16_t rotationAimAzimuth;
|
||||
int16_t rotationAimAzimuth = 0;
|
||||
|
||||
double minRemainingDistance = 0.25;
|
||||
};
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
|
||||
|
||||
void CalibrateCompassM::setCalibrateCompass(CalibrateCompass *caliCompass) {
|
||||
if (caliCompass) {
|
||||
if (static_cast<bool>(caliCompass)) {
|
||||
this->caliCompass = caliCompass;
|
||||
this->addChildComponent(this->caliCompass);
|
||||
} else if (this->caliCompass) {
|
||||
} else if (static_cast<bool>(this->caliCompass)) {
|
||||
this->removeChildComponent(this->caliCompass);
|
||||
this->caliCompass = caliCompass;
|
||||
}
|
||||
|
||||
@@ -4,27 +4,32 @@
|
||||
* @brief Contains the implementation of the class CaptureRoute
|
||||
* @version 0.1
|
||||
* @date 2022-02-15
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
||||
#include "captureRoute.h"
|
||||
|
||||
CaptureRoute::~CaptureRoute() {
|
||||
if (this->navigation)
|
||||
delete this->navigation;
|
||||
CaptureRoute::~CaptureRoute()
|
||||
{
|
||||
delete this->navigation;
|
||||
|
||||
if (this->sensorData->getNtripClient())
|
||||
if (static_cast<bool>(this->sensorData->getNtripClient()))
|
||||
{
|
||||
this->sensorData->getNtripClient()->setActivated(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureRoute::run() {
|
||||
void CaptureRoute::run()
|
||||
{
|
||||
ManualControl::run();
|
||||
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)) {
|
||||
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action))
|
||||
{
|
||||
this->status = this->navigation->addCurrentPosToRoute();
|
||||
if (this->status == Navigation::Status::Updated) {
|
||||
if (this->status == Navigation::Status::Updated)
|
||||
{
|
||||
this->lastSavedPoint = this->navigation->getCurrentPosition();
|
||||
this->routeInfo = navigation->getRouteInfo();
|
||||
this->updateDisplay = true;
|
||||
@@ -32,21 +37,27 @@ void CaptureRoute::run() {
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureRoute::afterActivate() {
|
||||
void CaptureRoute::afterActivate()
|
||||
{
|
||||
this->navigation = new Navigation(this->sensorData);
|
||||
this->navigation->getRoute()->clear();
|
||||
this->sensorData->getNtripClient()->setAutoReconnect(true);
|
||||
this->routeInfo = navigation->getRouteInfo();
|
||||
this->navigation->getRoute()->clear();
|
||||
this->sensorData->getNtripClient()->setAutoReconnect(true);
|
||||
this->routeInfo = navigation->getRouteInfo();
|
||||
}
|
||||
|
||||
double CaptureRoute::getDistanceToLastPoint() const {
|
||||
double CaptureRoute::getDistanceToLastPoint() const
|
||||
{
|
||||
if (!this->lastSavedPoint.isInit())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this->lastSavedPoint.distanceTo(this->navigation->getCurrentPosition());
|
||||
}
|
||||
|
||||
bool CaptureRoute::shouldUpdate() {
|
||||
if (this->updateDisplay) {
|
||||
bool CaptureRoute::shouldUpdate()
|
||||
{
|
||||
if (this->updateDisplay)
|
||||
{
|
||||
this->updateDisplay = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,67 +4,89 @@
|
||||
* @brief Implementation of the class manualControl.h
|
||||
* @version 0.1
|
||||
* @date 2021-12-13
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "manualControl.h"
|
||||
|
||||
void ManualControl::run() {
|
||||
switch (this->inputMode) {
|
||||
case InputMode::Analog :
|
||||
this->analogControl();
|
||||
break;
|
||||
void ManualControl::run()
|
||||
{
|
||||
switch (this->inputMode)
|
||||
{
|
||||
case InputMode::Analog:
|
||||
this->analogControl();
|
||||
break;
|
||||
|
||||
case InputMode::Digital :
|
||||
this->digitalControl();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case InputMode::Digital:
|
||||
this->digitalControl();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ManualControl::switchInputMode() {
|
||||
void ManualControl::switchInputMode()
|
||||
{
|
||||
this->inputMode = (this->inputMode == InputMode::Analog) ? InputMode::Digital : InputMode::Analog;
|
||||
}
|
||||
|
||||
void ManualControl::analogControl() {
|
||||
void ManualControl::analogControl()
|
||||
{
|
||||
// Have to be int16_t to avoid overflow (int8_t = 255 - 127 = -128)
|
||||
int16_t x = this->input->x - 127;
|
||||
int16_t y = this->input->y - 127;
|
||||
|
||||
const int16_t xAxis = this->input->x - 127;
|
||||
const int16_t yAxis = this->input->y - 127;
|
||||
|
||||
double value_per_step = this->maxSpeeds.x * 2 / UINT8_MAX;
|
||||
this->moveControl->setSpeed(-x * value_per_step);
|
||||
this->moveControl->setSpeed(-xAxis * value_per_step);
|
||||
|
||||
value_per_step = this->maxSpeeds.rot * 2 / UINT8_MAX;
|
||||
this->moveControl->setRotationSpeed(y * value_per_step);
|
||||
this->moveControl->setRotationSpeed(yAxis * value_per_step);
|
||||
}
|
||||
|
||||
void ManualControl::digitalControl() {
|
||||
int16_t y = this->input->x - 127;
|
||||
int16_t x = this->input->y - 127;
|
||||
void ManualControl::digitalControl()
|
||||
{
|
||||
static constexpr uint8_t deadzone = 120;
|
||||
const int16_t yAxis = this->input->x - 127;
|
||||
const int16_t xAxis = this->input->y - 127;
|
||||
|
||||
if (y > 120)
|
||||
if (yAxis > deadzone)
|
||||
{
|
||||
this->moveControl->setSpeed(-this->maxSpeeds.x);
|
||||
else if (y < -120)
|
||||
}
|
||||
else if (yAxis < -deadzone)
|
||||
{
|
||||
this->moveControl->setSpeed(this->maxSpeeds.rot);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->moveControl->setSpeed(0);
|
||||
}
|
||||
|
||||
if (x > 120)
|
||||
if (xAxis > deadzone)
|
||||
{
|
||||
this->moveControl->setRotationSpeed(this->maxSpeeds.rot);
|
||||
else if (x < -120)
|
||||
}
|
||||
else if (xAxis < -deadzone)
|
||||
{
|
||||
this->moveControl->setRotationSpeed(-this->maxSpeeds.rot);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
}
|
||||
|
||||
if (this->directionChangeWrapper && (x > 120 || x < -120))
|
||||
if (static_cast<bool>(this->directionChangeWrapper) && (xAxis > deadzone || xAxis < -deadzone))
|
||||
{
|
||||
this->lastLoopTurned = true;
|
||||
else if (this->lastLoopTurned) {
|
||||
if (this->directionChangeWrapper)
|
||||
}
|
||||
else if (this->lastLoopTurned)
|
||||
{
|
||||
if (static_cast<bool>(this->directionChangeWrapper))
|
||||
{
|
||||
this->directionChangeWrapper->action();
|
||||
}
|
||||
this->lastLoopTurned = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,24 @@
|
||||
* @brief Contains the implementation of the class TestMode.
|
||||
* @version 0.1
|
||||
* @date 2022-09-08
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "testMode.h"
|
||||
|
||||
void TestMode::run() {
|
||||
if (this->maneuver == Maneuver::Turn) {
|
||||
void TestMode::run()
|
||||
{
|
||||
if (this->maneuver == Maneuver::Turn)
|
||||
{
|
||||
uint16_t delta = abs(this->azimuth - this->getSensorData()->getRealAzimuth());
|
||||
if (delta > this->degree)
|
||||
if (delta > this->degree) {
|
||||
this->abort = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->busy && millis() - this->actionStart > this->maneuverTime || this->abort) {
|
||||
if (this->busy && millis() - this->actionStart > this->maneuverTime || this->abort)
|
||||
{
|
||||
this->busy = false;
|
||||
this->abort = false;
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
@@ -25,62 +29,76 @@ void TestMode::run() {
|
||||
}
|
||||
}
|
||||
|
||||
bool TestMode::drive(int16_t cm, int16_t degree) {
|
||||
if (this->busy)
|
||||
bool TestMode::drive(int16_t cmDistance, int16_t degree)
|
||||
{
|
||||
if (this->busy){
|
||||
return false;
|
||||
}
|
||||
|
||||
this->actionStart = millis();
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Drive);
|
||||
|
||||
if (cm == 0) {
|
||||
//Only left or right
|
||||
if (cmDistance == 0)
|
||||
{
|
||||
// Only left or right
|
||||
this->moveControl->setSpeed(0);
|
||||
|
||||
if (degree < 0)
|
||||
if (degree < 0){
|
||||
this->moveControl->setRotationSpeed(-this->maxSpeeds.rot);
|
||||
else if (degree > 0)
|
||||
}
|
||||
else if (degree > 0){
|
||||
this->moveControl->setRotationSpeed(this->maxSpeeds.rot);
|
||||
|
||||
}
|
||||
|
||||
this->azimuth = this->getSensorData()->getRealAzimuth();
|
||||
this->degree = degree;
|
||||
|
||||
this->maneuverTime = 5 * 1000;
|
||||
this->busy = true;
|
||||
return true;
|
||||
|
||||
} else if (degree == 0) {
|
||||
//Only forward or backward
|
||||
}
|
||||
if (degree == 0)
|
||||
{
|
||||
// Only forward or backward
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
|
||||
if (cm < 0)
|
||||
if (cmDistance < 0){
|
||||
this->moveControl->setSpeed(-this->maxSpeeds.x);
|
||||
else if (cm > 0)
|
||||
}
|
||||
else if (cmDistance > 0){
|
||||
this->moveControl->setSpeed(this->maxSpeeds.x);
|
||||
|
||||
this->maneuverTime = (uint32_t) (((double) abs(cm) / 100.0) / this->maxSpeeds.x) * 1000;
|
||||
}
|
||||
|
||||
this->maneuverTime = static_cast<uint32_t>(((abs(cmDistance) / 100.0) / this->maxSpeeds.x) * 1000);
|
||||
this->busy = true;
|
||||
this->maneuver = Maneuver::Drive;
|
||||
return true;
|
||||
} else {
|
||||
//forward or backward and left or right
|
||||
// TODO: Calculate roationspeed
|
||||
if (cm < 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
// forward or backward and left or right
|
||||
// TODO: Calculate roationspeed
|
||||
if (cmDistance < 0){
|
||||
this->moveControl->setSpeed(-this->maxSpeeds.x);
|
||||
else if (cm > 0)
|
||||
}
|
||||
else if (cmDistance > 0){
|
||||
this->moveControl->setSpeed(this->maxSpeeds.x);
|
||||
|
||||
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->maxSpeeds.x) * 1000;
|
||||
}
|
||||
|
||||
this->maneuverTime = static_cast<uint32_t>(((cmDistance / 100.0) / this->maxSpeeds.x) * 1000);
|
||||
this->busy = true;
|
||||
this->maneuver = Maneuver::Drive;
|
||||
return true;
|
||||
}
|
||||
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->engineInit(powerPercentage, seconds)) {
|
||||
bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->engineInit(powerPercentage, seconds))
|
||||
{
|
||||
this->moveControl->setRawPowerLeft(powerPercentage);
|
||||
this->maneuver = Maneuver::LeftEngine;
|
||||
std::cout << "TestMode::leftEngine" << std::endl;
|
||||
@@ -89,8 +107,10 @@ bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->engineInit(powerPercentage, seconds)) {
|
||||
bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->engineInit(powerPercentage, seconds))
|
||||
{
|
||||
this->moveControl->setRawPowerRight(powerPercentage);
|
||||
this->maneuver = Maneuver::RightEngine;
|
||||
return true;
|
||||
@@ -98,8 +118,10 @@ bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->engineInit(powerPercentage, seconds)) {
|
||||
bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->engineInit(powerPercentage, seconds))
|
||||
{
|
||||
this->moveControl->setRawPowerLeft(powerPercentage);
|
||||
this->moveControl->setRawPowerRight(powerPercentage);
|
||||
this->maneuver = Maneuver::BothEngine;
|
||||
@@ -108,23 +130,30 @@ bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void TestMode::abortManeuver() {
|
||||
void TestMode::abortManeuver()
|
||||
{
|
||||
this->abort = true;
|
||||
}
|
||||
|
||||
uint8_t TestMode::getRemainingManeuverTime() const {
|
||||
if (this->busy)
|
||||
return (uint8_t) ((this->maneuverTime - (millis() - this->actionStart)) / 1000);
|
||||
uint8_t TestMode::getRemainingManeuverTime() const
|
||||
{
|
||||
if (this->busy){
|
||||
return static_cast<uint8_t>((this->maneuverTime - (millis() - this->actionStart)) / 1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool TestMode::engineInit(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->busy)
|
||||
bool TestMode::engineInit(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->busy){
|
||||
return false;
|
||||
if (powerPercentage > 100 || powerPercentage < -100)
|
||||
}
|
||||
if (powerPercentage > TestMode::maxPercentage || powerPercentage < -TestMode::maxPercentage){
|
||||
return false;
|
||||
if (seconds < 0)
|
||||
}
|
||||
if (seconds < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
this->actionStart = millis();
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Raw);
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
* @brief Contains a class to test different functions from the rover.
|
||||
* @version 0.1
|
||||
* @date 2022-09-08
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef TEST_MODE_H
|
||||
#ifndef TEST_MODE_H
|
||||
#define TEST_MODE_H
|
||||
|
||||
#include <iostream>
|
||||
@@ -16,97 +16,100 @@
|
||||
#include "moveControl.h"
|
||||
#include "driveModi/driveModi.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Test different functions from the rover.
|
||||
*
|
||||
*
|
||||
* You can test engine, engine controller, light and speed meter.
|
||||
*/
|
||||
class TestMode : public DriveModi {
|
||||
public:
|
||||
/**
|
||||
* @brief Different states to test the engine
|
||||
*
|
||||
*/
|
||||
enum Maneuver {
|
||||
None,
|
||||
LeftEngine,
|
||||
RightEngine,
|
||||
BothEngine,
|
||||
Turn,
|
||||
Drive
|
||||
};
|
||||
class TestMode : public DriveModi
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Different states to test the engine
|
||||
*
|
||||
*/
|
||||
enum Maneuver
|
||||
{
|
||||
None,
|
||||
LeftEngine,
|
||||
RightEngine,
|
||||
BothEngine,
|
||||
Turn,
|
||||
Drive
|
||||
};
|
||||
|
||||
bool drive(int16_t cm = 0, int16_t degree = 0);
|
||||
bool drive(int16_t cmDistance = 0, int16_t degree = 0);
|
||||
|
||||
/**
|
||||
* @brief Sets the left Engine to a specific power value.
|
||||
*
|
||||
* This start a maneuver with the given time.
|
||||
*
|
||||
* @param powerPercentage from 0% to 100%
|
||||
* @param seconds time to run the engine
|
||||
* @return true success
|
||||
* @return false failure
|
||||
*/
|
||||
bool leftEngine(int16_t powerPercentage, int16_t seconds);
|
||||
/**
|
||||
* @brief Sets the left Engine to a specific power value.
|
||||
*
|
||||
* This start a maneuver with the given time.
|
||||
*
|
||||
* @param powerPercentage from 0% to 100%
|
||||
* @param seconds time to run the engine
|
||||
* @return true success
|
||||
* @return false failure
|
||||
*/
|
||||
bool leftEngine(int16_t powerPercentage, int16_t seconds);
|
||||
|
||||
/**
|
||||
* @brief See leftEngine
|
||||
*
|
||||
* @param powerPercentage
|
||||
* @param seconds
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool rightEngine(int16_t powerPercentage, int16_t seconds);
|
||||
/**
|
||||
* @brief See leftEngine
|
||||
*
|
||||
* @param powerPercentage
|
||||
* @param seconds
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool rightEngine(int16_t powerPercentage, int16_t seconds);
|
||||
|
||||
/**
|
||||
* @brief See leftEngine
|
||||
*
|
||||
* @param powerPercentage
|
||||
* @param seconds
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool bothEngine(int16_t powerPercentage, int16_t seconds);
|
||||
/**
|
||||
* @brief See leftEngine
|
||||
*
|
||||
* @param powerPercentage
|
||||
* @param seconds
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool bothEngine(int16_t powerPercentage, int16_t seconds);
|
||||
|
||||
/**
|
||||
* @brief Abort the running maneuver.
|
||||
*
|
||||
* Stops all movement. This is the only possibility to cancel a maneuver
|
||||
* before the time is up.
|
||||
*/
|
||||
void abortManeuver();
|
||||
/**
|
||||
* @brief Abort the running maneuver.
|
||||
*
|
||||
* Stops all movement. This is the only possibility to cancel a maneuver
|
||||
* before the time is up.
|
||||
*/
|
||||
void abortManeuver();
|
||||
|
||||
uint8_t getRemainingManeuverTime() const;
|
||||
uint8_t getRemainingManeuverTime() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if a maneuver is running
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool getBusy() const { return this->busy; }
|
||||
Maneuver getManeuver() const { return this->maneuver; }
|
||||
Speedometer* getSpeedometerLeft() const { return this->moveControl->getSpeedometerLeft(); }
|
||||
Speedometer* getSpeedometerRight() const { return this->moveControl->getSpeedometerRight(); }
|
||||
/**
|
||||
* @brief Returns true if a maneuver is running
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool getBusy() const { return this->busy; }
|
||||
Maneuver getManeuver() const { return this->maneuver; }
|
||||
Speedometer *getSpeedometerLeft() const { return this->moveControl->getSpeedometerLeft(); }
|
||||
Speedometer *getSpeedometerRight() const { return this->moveControl->getSpeedometerRight(); }
|
||||
|
||||
private:
|
||||
void run() override;
|
||||
bool engineInit(int16_t powerPercentage, int16_t seconds);
|
||||
private:
|
||||
void run() override;
|
||||
bool engineInit(int16_t powerPercentage, int16_t seconds);
|
||||
|
||||
Maneuver maneuver = Maneuver::None;
|
||||
int16_t maneuverValueOne = 0;
|
||||
int16_t maneuverValueTwo = 0;
|
||||
Maneuver maneuver = Maneuver::None;
|
||||
int16_t maneuverValueOne = 0;
|
||||
int16_t maneuverValueTwo = 0;
|
||||
|
||||
bool busy = false;
|
||||
bool abort = false;
|
||||
|
||||
uint16_t azimuth;
|
||||
int16_t degree;
|
||||
uint32_t maneuverTime = 0;
|
||||
uint32_t actionStart = 0;
|
||||
bool busy = false;
|
||||
bool abort = false;
|
||||
|
||||
uint16_t azimuth;
|
||||
int16_t degree;
|
||||
uint32_t maneuverTime = 0;
|
||||
uint32_t actionStart = 0;
|
||||
|
||||
static constexpr int8_t maxPercentage = 100;
|
||||
};
|
||||
|
||||
#endif // TEST_MODE_H
|
||||
|
||||
Reference in New Issue
Block a user