ready to test capture Route and Autopiloz
This commit is contained in:
@@ -11,10 +11,61 @@
|
||||
|
||||
#include "driveModi/Modi/Autopilot/autopilot.h"
|
||||
|
||||
Autopilot::Autopilot() {
|
||||
Autopilot::Autopilot(MoveControl* moveControl, Navigation* navigation)
|
||||
: ManualControl(moveControl) {
|
||||
this->navigation = navigation;
|
||||
this->navigationStarted = this->navigation->startNavigation();
|
||||
this->courseCorrection.correction = 0;
|
||||
this->courseCorrection.distance = 0;
|
||||
}
|
||||
|
||||
void Autopilot::loop() {
|
||||
if (!this->selfDriving)
|
||||
ManualControl::loop();
|
||||
|
||||
if (millis() - this->last_millis < delay) {
|
||||
return;
|
||||
}
|
||||
this->runAutopilot();
|
||||
this->last_millis = millis();
|
||||
}
|
||||
|
||||
void Autopilot::runAutopilot() {
|
||||
this->courseCorrection = this->navigation->getCourseCorrection();
|
||||
if (selfDriving) {
|
||||
this->setSpeedInRelToDistance(this->courseCorrection.distance);
|
||||
this->setRotInRelToDistance(this->courseCorrection.correction);
|
||||
}
|
||||
}
|
||||
|
||||
void Autopilot::setSelfDriving(bool val) {
|
||||
if (!this->navigationStarted)
|
||||
return;
|
||||
|
||||
this->selfDriving = val;
|
||||
this->moveControl->setSpeed(0);
|
||||
this->moveControl->setRotationspeed(0);
|
||||
}
|
||||
|
||||
void Autopilot::setSpeedInRelToDistance(double distance) {
|
||||
// TODO: Delte Magic Numbers
|
||||
if (distance > 2)
|
||||
this->moveControl->setSpeed(1.5);
|
||||
else if (distance < 0.5)
|
||||
this->moveControl->setSpeed(1.5);
|
||||
else
|
||||
this->moveControl->setSpeed(0);
|
||||
}
|
||||
|
||||
void Autopilot::setRotInRelToDistance(int16_t course) {
|
||||
// TODO: Delte Magic Numbers
|
||||
int8_t steps = course / 30;
|
||||
|
||||
if (steps == 0 && abs(course) >= 5)
|
||||
steps = 1;
|
||||
|
||||
if (course == 0)
|
||||
this->moveControl->setRotationspeed(0);
|
||||
else
|
||||
this->moveControl->setRotationspeed(steps);
|
||||
}
|
||||
@@ -15,20 +15,29 @@
|
||||
|
||||
#include "navigation.h"
|
||||
#include "moveControl.h"
|
||||
#include "driveModi/driveModi.h"
|
||||
#include "driveModi/Modi/ManualControl/manualControl.h"
|
||||
|
||||
class Autopilot : DriveModi{
|
||||
class Autopilot : public ManualControl {
|
||||
public:
|
||||
Autopilot();
|
||||
Autopilot(MoveControl* moveControl, Navigation* navigation);
|
||||
|
||||
void loop();
|
||||
void runAutopilot();
|
||||
|
||||
|
||||
private:
|
||||
MoveControl* moveControl;
|
||||
Navigation* navigation;
|
||||
void setSelfDriving(bool val);
|
||||
void setSpeedInRelToDistance(double distance);
|
||||
void setRotInRelToDistance(int16_t course);
|
||||
|
||||
Navigation* navigation;
|
||||
CourseCorrection courseCorrection;
|
||||
|
||||
bool navigationStarted = false;
|
||||
bool selfDriving = false;
|
||||
|
||||
uint16_t last_millis = 0;
|
||||
uint8_t delay = 40;
|
||||
};
|
||||
|
||||
#endif // AUTOPILOT_H
|
||||
Reference in New Issue
Block a user