finished speed and sensor menu in modes

This commit is contained in:
2023-09-29 11:30:13 +02:00
parent d7357d4f95
commit 45264c6481
17 changed files with 96 additions and 78 deletions
+9 -11
View File
@@ -125,17 +125,13 @@ void Autopilot::init() {
this->courseCorrection.correction = 0;
this->courseCorrection.distance = 0;
this->updateDisplay = true;
this->maxRotationSpeed = 7;
this->maxForwardSpeed = 1.5;
}
void Autopilot::drive() {
this->moveControl->setRotationSpeed(0);
if (this->courseCorrection.distance >= this->minRemainingDistance)
this->moveControl->setSpeed(this->maxForwardSpeed);
else
this,moveControl->setSpeed(0);
DrivingSpeeds speeds = {0, 0};
if (this->courseCorrection.distance >= this->minRemainingDistance)
speeds.x = this->maxSpeeds.x;
this->moveControl->setSpeeds(speeds);
}
void Autopilot::beginRotate() {
@@ -145,11 +141,13 @@ void Autopilot::beginRotate() {
this->rotationAimAzimuth = this->getSensorData()->getRealAzimuth() + this->courseCorrection.correction;
this->rotationAimAzimuth = Navigation::fixDegree(this->rotationAimAzimuth);
this->moveControl->setSpeed(0);
DrivingSpeeds speeds = {0, 0};
if (this->courseCorrection.correction > 0)
this->moveControl->setRotationSpeed(-this->maxRotationSpeed);
speeds.rot = -this->maxSpeeds.rot;
else
this->moveControl->setRotationSpeed(this->maxRotationSpeed);
speeds.rot = this->maxSpeeds.rot;
this->moveControl->setSpeeds(speeds);
}
}
@@ -34,17 +34,11 @@ void ManualControl::analogControl() {
int16_t x = this->input->x - 127;
int16_t y = this->input->y - 127;
// static int counter = 0;
// if (counter % 60 == 0) {
// std::cout << "Input: x: " << (int) this->input->x << " y: " << (int) this->input->y << std::endl;
// std::cout << "Output: x: " << (int) x << " y: " << (int) y << std::endl;
// }
// counter++;
double value_per_step = this->maxForwardSpeed * 2 / UINT8_MAX;
double value_per_step = this->maxSpeeds.x * 2 / UINT8_MAX;
this->moveControl->setSpeed(-x * value_per_step);
value_per_step = this->maxRotationSpeed * 2 / UINT8_MAX;
value_per_step = this->maxSpeeds.rot * 2 / UINT8_MAX;
this->moveControl->setRotationSpeed(y * value_per_step);
}
@@ -53,16 +47,16 @@ void ManualControl::digitalControl() {
int16_t x = this->input->y - 127;
if (y > 120)
this->moveControl->setSpeed(-this->maxForwardSpeed);
this->moveControl->setSpeed(-this->maxSpeeds.x);
else if (y < -120)
this->moveControl->setSpeed(this->maxForwardSpeed);
this->moveControl->setSpeed(this->maxSpeeds.rot);
else
this->moveControl->setSpeed(0);
if (x > 120)
this->moveControl->setRotationSpeed(this->maxRotationSpeed);
this->moveControl->setRotationSpeed(this->maxSpeeds.rot);
else if (x < -120)
this->moveControl->setRotationSpeed(-this->maxRotationSpeed);
this->moveControl->setRotationSpeed(-this->maxSpeeds.rot);
else
this->moveControl->setRotationSpeed(0);
+8 -8
View File
@@ -37,9 +37,9 @@ bool TestMode::drive(int16_t cm, int16_t degree) {
this->moveControl->setSpeed(0);
if (degree < 0)
this->moveControl->setRotationSpeed(-this->maxRotationSpeed);
this->moveControl->setRotationSpeed(-this->maxSpeeds.rot);
else if (degree > 0)
this->moveControl->setRotationSpeed(this->maxRotationSpeed);
this->moveControl->setRotationSpeed(this->maxSpeeds.rot);
this->azimuth = this->getSensorData()->getRealAzimuth();
this->degree = degree;
@@ -53,11 +53,11 @@ bool TestMode::drive(int16_t cm, int16_t degree) {
this->moveControl->setRotationSpeed(0);
if (cm < 0)
this->moveControl->setSpeed(-this->maxForwardSpeed);
this->moveControl->setSpeed(-this->maxSpeeds.x);
else if (cm > 0)
this->moveControl->setSpeed(this->maxForwardSpeed);
this->moveControl->setSpeed(this->maxSpeeds.x);
this->maneuverTime = (uint32_t) (((double) abs(cm) / 100.0) / this->maxForwardSpeed) * 1000;
this->maneuverTime = (uint32_t) (((double) abs(cm) / 100.0) / this->maxSpeeds.x) * 1000;
this->busy = true;
this->maneuver = Maneuver::Drive;
return true;
@@ -65,11 +65,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->maxForwardSpeed);
this->moveControl->setSpeed(-this->maxSpeeds.x);
else if (cm > 0)
this->moveControl->setSpeed(this->maxForwardSpeed);
this->moveControl->setSpeed(this->maxSpeeds.x);
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->maxForwardSpeed) * 1000;
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->maxSpeeds.x) * 1000;
this->busy = true;
this->maneuver = Maneuver::Drive;
return true;