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
|
||||
@@ -3,6 +3,7 @@
|
||||
CaptureRoute::CaptureRoute(MoveControl* moveControl, Navigation* navigation)
|
||||
: ManualControl(moveControl) {
|
||||
this->navigation = navigation;
|
||||
this->routeInfo = RouteInfo{0, 0};
|
||||
}
|
||||
|
||||
void CaptureRoute::loop() {
|
||||
@@ -18,5 +19,15 @@ void CaptureRoute::loop() {
|
||||
void CaptureRoute::runCaptureRoute() {
|
||||
if (Ps3.data.button.triangle) {
|
||||
this->navigation->addCurrentPosToRoute();
|
||||
this->routeInfo.totalPoints++;
|
||||
this->updateDisplay = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CaptureRoute::shouldUpdate() {
|
||||
if (this->updateDisplay) {
|
||||
this->updateDisplay = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -15,14 +15,17 @@ class CaptureRoute : public ManualControl {
|
||||
void runCaptureRoute();
|
||||
|
||||
Navigation* getNavigation() const { return this->navigation; }
|
||||
RouteInfo getRouteInfo() const { return this->routeInfo; }
|
||||
|
||||
bool shouldUpdate();
|
||||
private:
|
||||
Navigation* navigation;
|
||||
|
||||
uint16_t savedPoints = 0;
|
||||
RouteInfo routeInfo;
|
||||
|
||||
uint32_t last_millis = 0;
|
||||
uint16_t delay = 200;
|
||||
|
||||
bool updateDisplay = false;
|
||||
};
|
||||
|
||||
#endif // CAPTURE_ROUTE_H
|
||||
@@ -69,9 +69,10 @@ class ManualControl : public DriveModi{
|
||||
*/
|
||||
void setMaxRotation(double maxRotation) { max_rotation = maxRotation; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
MoveControl *moveControl;
|
||||
|
||||
private:
|
||||
uint32_t last_millis = 0;
|
||||
uint8_t delay = 10;
|
||||
double max_speed = 1;
|
||||
|
||||
@@ -60,8 +60,9 @@ void DriveManager::changeModus(Modi modus) {
|
||||
}
|
||||
break;
|
||||
|
||||
case Modi::Autopilot:
|
||||
this->currentModusPtr = nullptr;
|
||||
case Modi::Autopilot: {
|
||||
this->currentModusPtr = new Autopilot(this->moveControl, this->navigation);
|
||||
}
|
||||
break;
|
||||
|
||||
case Modi::ConsolControl:
|
||||
|
||||
Reference in New Issue
Block a user