refactore and fixes
first route successfully absolved
This commit is contained in:
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
// AUTO GENERATED FILE, DO NOT EDIT
|
// AUTO GENERATED FILE, DO NOT EDIT
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
#define VERSION "0.8.28"
|
#define VERSION "0.8.36"
|
||||||
#endif
|
#endif
|
||||||
#ifndef BUILD_TIMESTAMP
|
#ifndef BUILD_TIMESTAMP
|
||||||
#define BUILD_TIMESTAMP "2023-08-09 19:28:27.390516"
|
#define BUILD_TIMESTAMP "2023-08-13 15:13:34.491991"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -66,6 +66,10 @@ void MenuAutopilot::printPage() const {
|
|||||||
lineTwo = "Autopilot active";
|
lineTwo = "Autopilot active";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Autopilot::State::SelfDrivingRotate :
|
||||||
|
lineTwo = "Rotating";
|
||||||
|
break;
|
||||||
|
|
||||||
case Autopilot::State::TargetReached :
|
case Autopilot::State::TargetReached :
|
||||||
lineTwo = "Target reached";
|
lineTwo = "Target reached";
|
||||||
break;
|
break;
|
||||||
@@ -204,17 +208,17 @@ void MenuAutopilot::printPage() const {
|
|||||||
|
|
||||||
case 13:
|
case 13:
|
||||||
lineOne = "Test rotate";
|
lineOne = "Test rotate";
|
||||||
lineTwo = "45 degree";
|
lineTwo = "270 degree";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 14:
|
case 14:
|
||||||
lineOne = "Test rotate";
|
lineOne = "Test rotate";
|
||||||
lineTwo = "15 degree";
|
lineTwo = "45 degree";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 15:
|
case 15:
|
||||||
lineOne = "Test rotate";
|
lineOne = "Test rotate";
|
||||||
lineTwo = "5 degree";
|
lineTwo = "20 degree";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -257,19 +261,19 @@ void MenuAutopilot::runCommand() const {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 12:
|
case 12:
|
||||||
this->autopilot->rotate(180);
|
this->autopilot->testRotate(180);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 13:
|
case 13:
|
||||||
this->autopilot->rotate(45);
|
this->autopilot->testRotate(270);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 14:
|
case 14:
|
||||||
this->autopilot->rotate(15);
|
this->autopilot->testRotate(45);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 15:
|
case 15:
|
||||||
this->autopilot->rotate(5);
|
this->autopilot->testRotate(20);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -116,9 +116,12 @@ bool Autopilot::shouldUpdate() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::rotate(int16_t degree) {
|
void Autopilot::testRotate(int16_t degree) {
|
||||||
|
if (!degree)
|
||||||
|
return;
|
||||||
|
|
||||||
this->courseCorrection.correction = degree;
|
this->courseCorrection.correction = degree;
|
||||||
this->rotate();
|
this->beginRotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::init() {
|
void Autopilot::init() {
|
||||||
@@ -144,24 +147,48 @@ void Autopilot::drive() {
|
|||||||
this,moveControl->setSpeed(0);
|
this,moveControl->setSpeed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::rotate() {
|
void Autopilot::beginRotate() {
|
||||||
if (this->state != State::SelfDrivingRotate) {
|
if (this->state != State::SelfDrivingRotate) {
|
||||||
this->lastState = this->state;
|
this->lastState = this->state;
|
||||||
this->state = State::SelfDrivingRotate;
|
this->state = State::SelfDrivingRotate;
|
||||||
this->rotationAimAzimuth = this->navigation->getAzimuth() + this->courseCorrection.correction;
|
this->rotationAimAzimuth = this->navigation->getAzimuth() + this->courseCorrection.correction;
|
||||||
|
this->rotationAimAzimuth = Navigation::fixDegree(this->rotationAimAzimuth);
|
||||||
|
|
||||||
this->moveControl->setSpeed(0);
|
this->moveControl->setSpeed(0);
|
||||||
if (this->courseCorrection.correction > 0)
|
if (this->courseCorrection.correction > 0)
|
||||||
this->moveControl->setRotationSpeed(-this->rotationSpeed);
|
this->moveControl->setRotationSpeed(-this->rotationSpeed);
|
||||||
else
|
else
|
||||||
this->moveControl->setRotationSpeed(this->rotationSpeed);
|
this->moveControl->setRotationSpeed(this->rotationSpeed);
|
||||||
} else {
|
}
|
||||||
if (abs(this->navigation->getAzimuth() - this->rotationAimAzimuth) < 3) {
|
}
|
||||||
|
|
||||||
|
void Autopilot::rotate() {
|
||||||
|
if (abs(this->navigation->getAzimuth() - this->rotationAimAzimuth) < 5) {
|
||||||
|
this->endRotate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((abs(this->navigation->getAzimuth() - this->rotationAimAzimuth) < 15)
|
||||||
|
&&
|
||||||
|
((this->courseCorrection.correction > 0
|
||||||
|
&& this->rotationAimAzimuth < this->navigation->getAzimuth())
|
||||||
|
|| (this->courseCorrection.correction < 0
|
||||||
|
&& this->rotationAimAzimuth > this->navigation->getAzimuth())))
|
||||||
|
{
|
||||||
|
this->endRotate();
|
||||||
|
std::cout << "Autopilot::rotate: Rover rotated too far" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Autopilot::endRotate() {
|
||||||
|
if (this->state != State::SelfDrivingRotate)
|
||||||
|
return;
|
||||||
|
|
||||||
this->state = this->lastState;
|
this->state = this->lastState;
|
||||||
this->navigation->drivingDirectionChange();
|
this->navigation->drivingDirectionChange();
|
||||||
this->moveControl->setRotationSpeed(0);
|
this->moveControl->setRotationSpeed(0);
|
||||||
}
|
this->moveControl->emergencyStop();
|
||||||
}
|
this->moveControl->setDrivingStatus(MoveControl::Status::Drive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::checkButtonInput() {
|
void Autopilot::checkButtonInput() {
|
||||||
@@ -211,8 +238,11 @@ void Autopilot::askNavigationForOrder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::selfDriving() {
|
void Autopilot::selfDriving() {
|
||||||
|
if (this->state != State::SelfDriving)
|
||||||
|
return;
|
||||||
|
|
||||||
if (abs(this->courseCorrection.correction) >= this->maxCourseDeviationBerforeAct)
|
if (abs(this->courseCorrection.correction) >= this->maxCourseDeviationBerforeAct)
|
||||||
this->rotate();
|
this->beginRotate();
|
||||||
else
|
else
|
||||||
this->drive();
|
this->drive();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,11 +107,13 @@ class Autopilot : public ManualControl {
|
|||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
bool shouldUpdate();
|
bool shouldUpdate();
|
||||||
void rotate(int16_t degree);
|
void testRotate(int16_t degree);
|
||||||
|
void endRotate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void drive();
|
void drive();
|
||||||
|
void beginRotate();
|
||||||
void rotate();
|
void rotate();
|
||||||
void runAutopilot();
|
void runAutopilot();
|
||||||
void checkButtonInput();
|
void checkButtonInput();
|
||||||
|
|||||||
Reference in New Issue
Block a user