Pass gamepad to all objects
This commit is contained in:
@@ -141,7 +141,9 @@ CourseCorrection Navigation::getCourseCorrection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Navigation::addCurrentPosToRoute() {
|
bool Navigation::addCurrentPosToRoute() {
|
||||||
|
std::cout << "Navigation::addCurrentPosToRoute: 1" << std::endl;
|
||||||
if (!this->currentPosition.isValid()) { return false; }
|
if (!this->currentPosition.isValid()) { return false; }
|
||||||
|
std::cout << "Navigation::addCurrentPosToRoute: 2" << std::endl;
|
||||||
|
|
||||||
// First Point
|
// First Point
|
||||||
if (this->route->getRouteInfo().totalPoints == 0) {
|
if (this->route->getRouteInfo().totalPoints == 0) {
|
||||||
@@ -149,6 +151,7 @@ bool Navigation::addCurrentPosToRoute() {
|
|||||||
this->lastPoint = this->currentPosition;
|
this->lastPoint = this->currentPosition;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
std::cout << "Navigation::addCurrentPosToRoute: 3" << std::endl;
|
||||||
|
|
||||||
// Every Point after the first
|
// Every Point after the first
|
||||||
if (MIN_DISTANCE_BETWEEN_POINTS <= this->currentPosition.distanceTo(this->lastPoint)) {
|
if (MIN_DISTANCE_BETWEEN_POINTS <= this->currentPosition.distanceTo(this->lastPoint)) {
|
||||||
@@ -156,6 +159,7 @@ bool Navigation::addCurrentPosToRoute() {
|
|||||||
this->lastPoint = this->currentPosition;
|
this->lastPoint = this->currentPosition;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
std::cout << "Navigation::addCurrentPosToRoute: 4" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "driveModi/Modi/Autopilot/autopilot.h"
|
#include "driveModi/Modi/Autopilot/autopilot.h"
|
||||||
|
|
||||||
Autopilot::Autopilot(MoveControl* moveControl, Navigation* navigation)
|
Autopilot::Autopilot(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation)
|
||||||
: ManualControl(moveControl) {
|
: ManualControl(moveControl, gamepad) {
|
||||||
this->navigation = navigation;
|
this->navigation = navigation;
|
||||||
this->navigationStarted = this->navigation->startNavigation();
|
this->navigationStarted = this->navigation->startNavigation();
|
||||||
this->routeInfo = this->navigation->getRouteInfo();
|
this->routeInfo = this->navigation->getRouteInfo();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Autopilot : public ManualControl {
|
|||||||
* @param moveControl for ManualControl
|
* @param moveControl for ManualControl
|
||||||
* @param navigation for route instructions
|
* @param navigation for route instructions
|
||||||
*/
|
*/
|
||||||
Autopilot(MoveControl* moveControl, Navigation* navigation);
|
Autopilot(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runAutopilot or ManualControl loop
|
* @brief Calls runAutopilot or ManualControl loop
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
||||||
|
|
||||||
CaptureRoute::CaptureRoute(MoveControl* moveControl, Navigation* navigation)
|
CaptureRoute::CaptureRoute(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation)
|
||||||
: ManualControl(moveControl) {
|
: ManualControl(moveControl, gamepad) {
|
||||||
this->navigation = navigation;
|
this->navigation = navigation;
|
||||||
this->routeInfo = RouteInfo{0, 0};
|
this->routeInfo = RouteInfo{0, 0};
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ void CaptureRoute::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CaptureRoute::runCaptureRoute() {
|
void CaptureRoute::runCaptureRoute() {
|
||||||
if (Ps3.data.button.triangle) {
|
if (this->gamepad->data.button.triangle) {
|
||||||
if (this->navigation->addCurrentPosToRoute()) {
|
if (this->navigation->addCurrentPosToRoute()) {
|
||||||
this->routeInfo = navigation->getRouteInfo();
|
this->routeInfo = navigation->getRouteInfo();
|
||||||
this->updateDisplay = true;
|
this->updateDisplay = true;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class CaptureRoute : public ManualControl {
|
|||||||
* @param moveControl for ManualControl
|
* @param moveControl for ManualControl
|
||||||
* @param navigation to add Points
|
* @param navigation to add Points
|
||||||
*/
|
*/
|
||||||
CaptureRoute(MoveControl* moveControl, Navigation* navigation);
|
CaptureRoute(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runCaptureRoute and ManualControl::loop
|
* @brief Calls runCaptureRoute and ManualControl::loop
|
||||||
@@ -50,12 +50,12 @@ class CaptureRoute : public ManualControl {
|
|||||||
*/
|
*/
|
||||||
void runCaptureRoute();
|
void runCaptureRoute();
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @brief Get the Navigation object
|
// * @brief Get the Navigation object
|
||||||
*
|
// *
|
||||||
* @return Navigation*
|
// * @return Navigation*
|
||||||
*/
|
// */
|
||||||
Navigation* getNavigation() const { return this->navigation; }
|
// Navigation* getNavigation() const { return this->navigation; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Route Info object
|
* @brief Get the Route Info object
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "manualControl.h"
|
#include "manualControl.h"
|
||||||
|
|
||||||
ManualControl::ManualControl(MoveControl *moveControl) {
|
ManualControl::ManualControl(MoveControl *moveControl, Ps3Controller *gamepad) {
|
||||||
this->moveControl = moveControl;
|
this->moveControl = moveControl;
|
||||||
|
this->gamepad = gamepad;
|
||||||
this->moveControl->setDrivingStatus(DrivingStatus::drive);
|
this->moveControl->setDrivingStatus(DrivingStatus::drive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
class ManualControl : public DriveModi {
|
class ManualControl : public DriveModi {
|
||||||
public:
|
public:
|
||||||
ManualControl(MoveControl *moveControl);
|
ManualControl(MoveControl *moveControl, Ps3Controller *gamepad);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Manual Control object
|
* @brief Destroy the Manual Control object
|
||||||
@@ -71,6 +71,7 @@ class ManualControl : public DriveModi {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
MoveControl *moveControl;
|
MoveControl *moveControl;
|
||||||
|
Ps3Controller *gamepad;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t lastMillis = 0;
|
uint32_t lastMillis = 0;
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ Modi& operator++(Modi& m, int) {
|
|||||||
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
|
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
DriveManager::DriveManager(MoveControl *moveControl, bool wifi) {
|
DriveManager::DriveManager(MoveControl *moveControl, Ps3Controller *gamepad, bool wifi) {
|
||||||
this->moveControl = moveControl;
|
this->moveControl = moveControl;
|
||||||
|
this->gamepad = gamepad;
|
||||||
|
|
||||||
this->spiPort = new SPIClass(HSPI);
|
this->spiPort = new SPIClass(HSPI);
|
||||||
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
||||||
@@ -65,17 +66,17 @@ void DriveManager::changeModus(Modi modus) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::ManualControl: {
|
case Modi::ManualControl: {
|
||||||
this->currentModusPtr = new ManualControl(this->moveControl);
|
this->currentModusPtr = new ManualControl(this->moveControl, this->gamepad);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::CaptureRoute: {
|
case Modi::CaptureRoute: {
|
||||||
this->currentModusPtr = new CaptureRoute(this->moveControl, this->navigation);
|
this->currentModusPtr = new CaptureRoute(this->moveControl, this->gamepad, this->navigation);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::Autopilot: {
|
case Modi::Autopilot: {
|
||||||
this->currentModusPtr = new Autopilot(this->moveControl, this->navigation);
|
this->currentModusPtr = new Autopilot(this->moveControl, this->gamepad, this->navigation);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class DriveManager {
|
|||||||
*
|
*
|
||||||
* @param moveControl
|
* @param moveControl
|
||||||
*/
|
*/
|
||||||
DriveManager(MoveControl *moveControl, bool wifi = false);
|
DriveManager(MoveControl *moveControl, Ps3Controller *gamepad, bool wifi = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Drive Manager object
|
* @brief Destroy the Drive Manager object
|
||||||
@@ -117,6 +117,7 @@ class DriveManager {
|
|||||||
private:
|
private:
|
||||||
Modi currentModus = Modi::Off;
|
Modi currentModus = Modi::Off;
|
||||||
MoveControl *moveControl;
|
MoveControl *moveControl;
|
||||||
|
Ps3Controller *gamepad;
|
||||||
DriveModi *currentModusPtr = nullptr;
|
DriveModi *currentModusPtr = nullptr;
|
||||||
Navigation* navigation;
|
Navigation* navigation;
|
||||||
SPIClass* spiPort;
|
SPIClass* spiPort;
|
||||||
|
|||||||
+1
-1
@@ -84,7 +84,7 @@ void setup() {
|
|||||||
Network::setIps();
|
Network::setIps();
|
||||||
Network::setupMQTT();
|
Network::setupMQTT();
|
||||||
wifiIsActive = Network::connectWifi();
|
wifiIsActive = Network::connectWifi();
|
||||||
driveManager = new DriveManager(&moveController, wifiIsActive);
|
driveManager = new DriveManager(&moveController, gamepad, wifiIsActive);
|
||||||
if (wifiIsActive) {
|
if (wifiIsActive) {
|
||||||
|
|
||||||
// const char* remoteHost = "www.google.com";
|
// const char* remoteHost = "www.google.com";
|
||||||
|
|||||||
Reference in New Issue
Block a user