added digital control to manualControl
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.1.10"
|
#define VERSION "0.8.20"
|
||||||
#endif
|
#endif
|
||||||
#ifndef BUILD_TIMESTAMP
|
#ifndef BUILD_TIMESTAMP
|
||||||
#define BUILD_TIMESTAMP "2023-08-07 22:02:51.554203"
|
#define BUILD_TIMESTAMP "2023-08-08 14:33:17.266785"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -27,45 +27,53 @@ void MenuManualControl::printPage() const {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
lineOne = "Speed: ";
|
lineOne = "Input mode:";
|
||||||
lineOne.concat(this->manualControl->getMaxSpeed());
|
if (this->manualControl->getInputMode() == ManualControl::InputMode::Analog)
|
||||||
lineTwo = "Increase by 0.1";
|
lineTwo = "Analog";
|
||||||
|
else
|
||||||
|
lineTwo = "Digital";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
lineOne = "Speed: ";
|
lineOne = "Speed: ";
|
||||||
lineOne.concat(this->manualControl->getMaxSpeed());
|
lineOne.concat(this->manualControl->getMaxSpeed());
|
||||||
lineTwo = "Decrease by 0.1";
|
lineTwo = "Increase by 0.1";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
lineOne = "RotSpeed: ";
|
lineOne = "Speed: ";
|
||||||
lineOne.concat(this->manualControl->getMaxRotation());
|
lineOne.concat(this->manualControl->getMaxSpeed());
|
||||||
lineTwo = "Increase by 0.1";
|
lineTwo = "Decrease by 0.1";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
lineOne = "RotSpeed: ";
|
lineOne = "RotSpeed: ";
|
||||||
lineOne.concat(this->manualControl->getMaxRotation());
|
lineOne.concat(this->manualControl->getMaxRotation());
|
||||||
lineTwo = "Decrease by 0.1";
|
lineTwo = "Increase by 0.1";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
|
lineOne = "RotSpeed: ";
|
||||||
|
lineOne.concat(this->manualControl->getMaxRotation());
|
||||||
|
lineTwo = "Decrease by 0.1";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
lineOne = "Dutycycle Left:";
|
lineOne = "Dutycycle Left:";
|
||||||
lineTwo.concat(this->manualControl->getDutycycleLeft());
|
lineTwo.concat(this->manualControl->getDutycycleLeft());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 7:
|
||||||
lineOne = "Dutycycle Right:";
|
lineOne = "Dutycycle Right:";
|
||||||
lineTwo.concat(this->manualControl->getDutycycleRight());
|
lineTwo.concat(this->manualControl->getDutycycleRight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 8:
|
||||||
lineOne = "Azimuth:";
|
lineOne = "Azimuth:";
|
||||||
lineTwo.concat(this->driveManager->getNavigation()->getAzimuth());
|
lineTwo.concat(this->driveManager->getNavigation()->getAzimuth());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8: {
|
case 9: {
|
||||||
UBX_NAV_PVT_data_t* gpsData = this->driveManager->getNavigation()->getUbxData();
|
UBX_NAV_PVT_data_t* gpsData = this->driveManager->getNavigation()->getUbxData();
|
||||||
lineOne = "magDec: ";
|
lineOne = "magDec: ";
|
||||||
lineTwo = "magAcc: ";
|
lineTwo = "magAcc: ";
|
||||||
@@ -91,28 +99,31 @@ void MenuManualControl::init() {
|
|||||||
this->firstPrint = false;
|
this->firstPrint = false;
|
||||||
this->driveManager->changeModus(Modi::ManualControl);
|
this->driveManager->changeModus(Modi::ManualControl);
|
||||||
this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr();
|
this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr();
|
||||||
this->setCountPages(9);
|
this->setCountPages(10);
|
||||||
this->updateDelay = 500;
|
this->updateDelay = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManualControl::runCommand() const {
|
void MenuManualControl::runCommand() const {
|
||||||
switch (this->getCurrentPage()) {
|
switch (this->getCurrentPage()) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
this->manualControl->increaseMaxSpeed();
|
this->manualControl->switchInputMode();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
this->manualControl->decreaseMaxSpeed();
|
this->manualControl->increaseMaxSpeed();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
this->manualControl->increaseMaxRotation();
|
this->manualControl->decreaseMaxSpeed();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
this->manualControl->increaseMaxRotation();
|
this->manualControl->increaseMaxRotation();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
this->manualControl->increaseMaxRotation();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -26,14 +26,30 @@ void ManualControl::loop() {
|
|||||||
if (this->caliCompass)
|
if (this->caliCompass)
|
||||||
this->caliCompass->loop();
|
this->caliCompass->loop();
|
||||||
|
|
||||||
if (millis() - this->lastMillis < delay) {
|
if (millis() - this->lastMillis < delay)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
switch (this->inputMode) {
|
||||||
|
case InputMode::Analog :
|
||||||
|
this->analogControl();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InputMode::Digital :
|
||||||
|
this->digitalControl();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
this->runManualControl();
|
|
||||||
this->lastMillis = millis();
|
this->lastMillis = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualControl::runManualControl() {
|
void ManualControl::switchInputMode() {
|
||||||
|
this->inputMode = (this->inputMode == InputMode::Analog) ? InputMode::Digital : InputMode::Analog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualControl::analogControl() {
|
||||||
// Have to be int16_t to avoid overflow (int8_t = 255 - 127 = -128)
|
// Have to be int16_t to avoid overflow (int8_t = 255 - 127 = -128)
|
||||||
int16_t y = this->input->x - 127;
|
int16_t y = this->input->x - 127;
|
||||||
int16_t x = this->input->y - 127;
|
int16_t x = this->input->y - 127;
|
||||||
@@ -49,3 +65,25 @@ void ManualControl::runManualControl() {
|
|||||||
value_per_step = this->max_rotation * 2 / 256;
|
value_per_step = this->max_rotation * 2 / 256;
|
||||||
this->moveControl->setRotationSpeed(x * value_per_step);
|
this->moveControl->setRotationSpeed(x * value_per_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ManualControl::digitalControl() {
|
||||||
|
int16_t y = this->input->x - 127;
|
||||||
|
int16_t x = this->input->y - 127;
|
||||||
|
|
||||||
|
if (y > 120)
|
||||||
|
this->moveControl->setSpeed(-this->max_speed);
|
||||||
|
else if (y < -120)
|
||||||
|
this->moveControl->setSpeed(this->max_speed);
|
||||||
|
else
|
||||||
|
this->moveControl->setSpeed(0);
|
||||||
|
|
||||||
|
if (x > 120)
|
||||||
|
this->moveControl->setRotationSpeed(this->max_rotation);
|
||||||
|
else if (x < -120)
|
||||||
|
this->moveControl->setRotationSpeed(-this->max_rotation);
|
||||||
|
else
|
||||||
|
this->moveControl->setRotationSpeed(0);
|
||||||
|
|
||||||
|
if (this->directionChangeWrapper && (x > 120 || x < -120))
|
||||||
|
this->directionChangeWrapper->action();
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
#include "controlPadInput.h"
|
#include "controlPadInput.h"
|
||||||
#include "calibrateCompass.h"
|
#include "calibrateCompass.h"
|
||||||
|
|
||||||
|
class DirectionChangeWrapper {
|
||||||
|
public:
|
||||||
|
virtual void action() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Drive the Rover with a Joystick
|
* @brief Drive the Rover with a Joystick
|
||||||
*
|
*
|
||||||
@@ -26,6 +31,11 @@
|
|||||||
*/
|
*/
|
||||||
class ManualControl : public DriveModi {
|
class ManualControl : public DriveModi {
|
||||||
public:
|
public:
|
||||||
|
enum class InputMode : uint8_t {
|
||||||
|
Analog,
|
||||||
|
Digital
|
||||||
|
};
|
||||||
|
|
||||||
ManualControl(MoveControl *moveControl, const ControlPadInput *input);
|
ManualControl(MoveControl *moveControl, const ControlPadInput *input);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +45,7 @@ class ManualControl : public DriveModi {
|
|||||||
~ManualControl();
|
~ManualControl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runManualControl() to update all values.
|
* @brief Calls analogControl() to update all values.
|
||||||
*
|
*
|
||||||
* This function should be called every mainloop. If the delay is not reached, than the
|
* This function should be called every mainloop. If the delay is not reached, than the
|
||||||
* functions returns immediately.
|
* functions returns immediately.
|
||||||
@@ -44,12 +54,6 @@ class ManualControl : public DriveModi {
|
|||||||
*/
|
*/
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Noramly called repeatedly by loop() to calcluate new values.
|
|
||||||
* Set new values for speed and rotation in moveControl
|
|
||||||
*/
|
|
||||||
void runManualControl();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the min delay between each loop
|
* @brief Set the min delay between each loop
|
||||||
*
|
*
|
||||||
@@ -79,6 +83,11 @@ class ManualControl : public DriveModi {
|
|||||||
|
|
||||||
void setCalibrateCompass(CalibrateCompass* val = nullptr) { this->caliCompass = val; }
|
void setCalibrateCompass(CalibrateCompass* val = nullptr) { this->caliCompass = val; }
|
||||||
|
|
||||||
|
void switchInputMode();
|
||||||
|
void setInputMode(InputMode mode) { this->inputMode = mode; }
|
||||||
|
InputMode getInputMode() const { return this->inputMode; }
|
||||||
|
void setDirectionChangeCallback(DirectionChangeWrapper* callback) { this->directionChangeWrapper = callback; }
|
||||||
|
|
||||||
uint16_t getDutycycleLeft() const { return this->moveControl->getDutycycleLeft(); }
|
uint16_t getDutycycleLeft() const { return this->moveControl->getDutycycleLeft(); }
|
||||||
uint16_t getDutycycleRight() const { return this->moveControl->getDutycycleRight(); }
|
uint16_t getDutycycleRight() const { return this->moveControl->getDutycycleRight(); }
|
||||||
|
|
||||||
@@ -87,11 +96,20 @@ class ManualControl : public DriveModi {
|
|||||||
const ControlPadInput* input;
|
const ControlPadInput* input;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Noramly called repeatedly by loop() to calcluate new values.
|
||||||
|
* Set new values for speed and rotation in moveControl
|
||||||
|
*/
|
||||||
|
void analogControl();
|
||||||
|
void digitalControl();
|
||||||
|
|
||||||
uint32_t lastMillis = 0;
|
uint32_t lastMillis = 0;
|
||||||
uint8_t delay = 10;
|
uint8_t delay = 10;
|
||||||
double max_speed = 1;
|
double max_speed = 1;
|
||||||
double max_rotation = 7;
|
double max_rotation = 7;
|
||||||
CalibrateCompass* caliCompass = nullptr;
|
CalibrateCompass* caliCompass = nullptr;
|
||||||
|
DirectionChangeWrapper* directionChangeWrapper = nullptr;
|
||||||
|
InputMode inputMode = InputMode::Analog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MANUAL_CONTROL_H
|
#endif // MANUAL_CONTROL_H
|
||||||
|
|||||||
Reference in New Issue
Block a user