From c7a19163ff689583280fde8ece81f68e4f667792 Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Mon, 14 Aug 2023 15:28:21 +0200 Subject: [PATCH] autopilot inherits speed from manualControl spelling refactor --- src/driveModi/Modi/Autopilot/autopilot.cpp | 9 ++++++--- src/driveModi/Modi/Autopilot/autopilot.h | 2 -- .../Modi/ManualControl/manualControl.cpp | 12 +++++------ .../Modi/ManualControl/manualControl.h | 20 +++++++++---------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/driveModi/Modi/Autopilot/autopilot.cpp b/src/driveModi/Modi/Autopilot/autopilot.cpp index 5e64608..bb2dee7 100644 --- a/src/driveModi/Modi/Autopilot/autopilot.cpp +++ b/src/driveModi/Modi/Autopilot/autopilot.cpp @@ -139,12 +139,15 @@ void Autopilot::init() { this->courseCorrection.correction = 0; this->courseCorrection.distance = 0; this->updateDisplay = true; + + this->maxRotationSpeed = 4.5; + this->maxForwardSpeed = 1; } void Autopilot::drive() { this->moveControl->setRotationSpeed(0); if (this->courseCorrection.distance >= this->minRemainingDistance) - this->moveControl->setSpeed(this->drivingSpeed); + this->moveControl->setSpeed(this->maxForwardSpeed); else this,moveControl->setSpeed(0); } @@ -158,9 +161,9 @@ void Autopilot::beginRotate() { this->moveControl->setSpeed(0); if (this->courseCorrection.correction > 0) - this->moveControl->setRotationSpeed(-this->rotationSpeed); + this->moveControl->setRotationSpeed(-this->maxRotationSpeed); else - this->moveControl->setRotationSpeed(this->rotationSpeed); + this->moveControl->setRotationSpeed(this->maxRotationSpeed); } } diff --git a/src/driveModi/Modi/Autopilot/autopilot.h b/src/driveModi/Modi/Autopilot/autopilot.h index b50bf45..0f00347 100644 --- a/src/driveModi/Modi/Autopilot/autopilot.h +++ b/src/driveModi/Modi/Autopilot/autopilot.h @@ -144,8 +144,6 @@ class Autopilot : public ManualControl { int16_t rotationAimAzimuth; - double drivingSpeed = 1; - double rotationSpeed = 4.5; double minRemainingDistance = 0.25; }; diff --git a/src/driveModi/Modi/ManualControl/manualControl.cpp b/src/driveModi/Modi/ManualControl/manualControl.cpp index 0a9858c..e967dcd 100644 --- a/src/driveModi/Modi/ManualControl/manualControl.cpp +++ b/src/driveModi/Modi/ManualControl/manualControl.cpp @@ -59,10 +59,10 @@ void ManualControl::analogControl() { // std::cout << "x: " << (int) x << " y: " << (int) y << std::endl; // } - double value_per_step = this->max_speed * 2 / UINT8_MAX; + double value_per_step = this->maxForwardSpeed * 2 / UINT8_MAX; this->moveControl->setSpeed(-y * value_per_step); - value_per_step = this->max_rotation * 2 / UINT8_MAX; + value_per_step = this->maxRotationSpeed * 2 / UINT8_MAX; this->moveControl->setRotationSpeed(x * value_per_step); } @@ -71,16 +71,16 @@ void ManualControl::digitalControl() { int16_t x = this->input->y - 127; if (y > 120) - this->moveControl->setSpeed(-this->max_speed); + this->moveControl->setSpeed(-this->maxForwardSpeed); else if (y < -120) - this->moveControl->setSpeed(this->max_speed); + this->moveControl->setSpeed(this->maxForwardSpeed); else this->moveControl->setSpeed(0); if (x > 120) - this->moveControl->setRotationSpeed(this->max_rotation); + this->moveControl->setRotationSpeed(this->maxRotationSpeed); else if (x < -120) - this->moveControl->setRotationSpeed(-this->max_rotation); + this->moveControl->setRotationSpeed(-this->maxRotationSpeed); else this->moveControl->setRotationSpeed(0); diff --git a/src/driveModi/Modi/ManualControl/manualControl.h b/src/driveModi/Modi/ManualControl/manualControl.h index 35d242d..82b69d7 100644 --- a/src/driveModi/Modi/ManualControl/manualControl.h +++ b/src/driveModi/Modi/ManualControl/manualControl.h @@ -66,20 +66,20 @@ class ManualControl : public DriveModi { * * @param maxSpeed in m/s */ - void setMaxSpeed(double maxSpeed) { max_speed = maxSpeed; } - void increaseMaxSpeed(double increase = 0.1) { max_speed += increase; } - void decreaseMaxSpeed(double increase = 0.1) { max_speed -= increase; } - double getMaxSpeed() { return this->max_speed; } + void setMaxSpeed(double maxForwardSpeed) { maxForwardSpeed = maxForwardSpeed; } + void increaseMaxSpeed(double increase = 0.1) { maxForwardSpeed += increase; } + void decreaseMaxSpeed(double increase = 0.1) { maxForwardSpeed -= increase; } + double getMaxSpeed() { return this->maxForwardSpeed; } /** * @brief Set the max rotation * * @param maxRotation in rad/s (maybe) */ - void setMaxRotation(double maxRotation) { max_rotation = maxRotation; } - void increaseMaxRotation(double increase = 0.1) { max_rotation += increase; } - void decreaseMaxRotation(double increase = 0.1) { max_rotation -= increase; } - double getMaxRotation() { return this->max_rotation; } + void setMaxRotation(double maxRotation) { maxRotationSpeed = maxRotation; } + void increaseMaxRotation(double increase = 0.1) { maxRotationSpeed += increase; } + void decreaseMaxRotation(double increase = 0.1) { maxRotationSpeed -= increase; } + double getMaxRotation() { return this->maxRotationSpeed; } void setCalibrateCompass(CalibrateCompass* val = nullptr) { this->caliCompass = val; } @@ -94,6 +94,8 @@ class ManualControl : public DriveModi { protected: MoveControl *moveControl; const ControlPadInput* input; + double maxForwardSpeed = 1; + double maxRotationSpeed = 7; private: /** @@ -106,8 +108,6 @@ class ManualControl : public DriveModi { bool lastLoopTurned = false; uint8_t delay = 10; uint32_t lastMillis = 0; - double max_speed = 1; - double max_rotation = 7; CalibrateCompass* caliCompass = nullptr; DirectionChangeWrapper* directionChangeWrapper = nullptr; InputMode inputMode = InputMode::Analog;