autopilot inherits speed from manualControl

spelling
refactor
This commit is contained in:
2023-08-14 15:28:21 +02:00
parent 99dc1709d8
commit c7a19163ff
4 changed files with 22 additions and 21 deletions
+6 -3
View File
@@ -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);
}
}
-2
View File
@@ -144,8 +144,6 @@ class Autopilot : public ManualControl {
int16_t rotationAimAzimuth;
double drivingSpeed = 1;
double rotationSpeed = 4.5;
double minRemainingDistance = 0.25;
};
@@ -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);
@@ -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;