refactore
all components now have a base class compnent for loop functions
This commit is contained in:
2023-08-18 10:47:35 +02:00
parent 25d37e3970
commit 11d21e2e89
35 changed files with 303 additions and 511 deletions
+11 -24
View File
@@ -10,8 +10,8 @@
*/
#include "testMode.h"
TestMode::TestMode(MoveControl *moveControl, Navigation* navigation) {
this->moveControl = moveControl;
TestMode::TestMode(MoveControl *moveControl, Navigation* navigation)
: DriveModi(moveControl) {
this->navigation = navigation;
}
@@ -19,10 +19,7 @@ TestMode::~TestMode() {
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
}
void TestMode::loop() {
if (millis() - this->lastMillis < this->delay)
return;
void TestMode::run() {
if (this->maneuver == Maneuver::Turn) {
uint16_t delta = abs(this->azimuth - this->navigation->getAzimuth());
if (delta > this->degree)
@@ -35,16 +32,6 @@ void TestMode::loop() {
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
this->maneuver = Maneuver::None;
}
this->lastMillis = millis();
}
void TestMode::setSpeed(int16_t speed) {
this->speed = (double) speed / 100.0;
}
void TestMode::setRotationSpeed(int16_t speed) {
this->rotationSpeed = (double) speed / 100.0;
}
bool TestMode::drive(int16_t cm, int16_t degree) {
@@ -59,9 +46,9 @@ bool TestMode::drive(int16_t cm, int16_t degree) {
this->moveControl->setSpeed(0);
if (degree < 0)
this->moveControl->setRotationSpeed(-this->rotationSpeed);
this->moveControl->setRotationSpeed(-this->maxRotationSpeed);
else if (degree > 0)
this->moveControl->setRotationSpeed(this->rotationSpeed);
this->moveControl->setRotationSpeed(this->maxRotationSpeed);
this->azimuth = this->navigation->getAzimuth();
this->degree = degree;
@@ -75,11 +62,11 @@ bool TestMode::drive(int16_t cm, int16_t degree) {
this->moveControl->setRotationSpeed(0);
if (cm < 0)
this->moveControl->setSpeed(-this->speed);
this->moveControl->setSpeed(-this->maxForwardSpeed);
else if (cm > 0)
this->moveControl->setSpeed(this->speed);
this->moveControl->setSpeed(this->maxForwardSpeed);
this->maneuverTime = (uint32_t) (((double) abs(cm) / 100.0) / this->speed) * 1000;
this->maneuverTime = (uint32_t) (((double) abs(cm) / 100.0) / this->maxForwardSpeed) * 1000;
this->busy = true;
this->maneuver = Maneuver::Drive;
return true;
@@ -87,11 +74,11 @@ bool TestMode::drive(int16_t cm, int16_t degree) {
//forward or backward and left or right
// TODO: Calculate roationspeed
if (cm < 0)
this->moveControl->setSpeed(-this->speed);
this->moveControl->setSpeed(-this->maxForwardSpeed);
else if (cm > 0)
this->moveControl->setSpeed(this->speed);
this->moveControl->setSpeed(this->maxForwardSpeed);
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->speed) * 1000;
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->maxForwardSpeed) * 1000;
this->busy = true;
this->maneuver = Maneuver::Drive;
return true;