restart the work
This commit is contained in:
@@ -19,19 +19,44 @@ void ManualControl::runManualControl() {
|
||||
if (millis() - this->last_millis < RUN_MANUALCONTROL_DELAY) {
|
||||
return;
|
||||
}
|
||||
//Reset if this function was called a long time ago
|
||||
if (millis() - this->last_millis > 1000) {
|
||||
this->reset();
|
||||
controlMode = ControMode::halt;
|
||||
debug->sendMsg(Loglevel::info, "Changed ControlMode to halt by Timereset");
|
||||
}
|
||||
this->last_millis = millis();
|
||||
|
||||
switch (this->drive_mode) {
|
||||
case DriveMode::stop:
|
||||
//Change controlMode
|
||||
if (this->controlMode == ControMode::halt && Ps3.data.button.l3) {
|
||||
this->reset();
|
||||
controlMode = ControMode::joystick;
|
||||
debug->sendMsg(Loglevel::info, "Changed ControlMode to Joystick by Gamepad");
|
||||
} else if (this->controlMode == ControMode::halt && Ps3.data.button.r3) {
|
||||
this->reset();
|
||||
controlMode = ControMode::trigger;
|
||||
debug->sendMsg(Loglevel::info, "Changed ControlMode to ShoulderTrigger by Gamepad");
|
||||
} else if (this->controlMode == ControMode::joystick && Ps3.data.button.r3) {
|
||||
this->reset();
|
||||
controlMode = ControMode::trigger;
|
||||
debug->sendMsg(Loglevel::info, "Changed ControlMode to ShoulderTrigger by Gamepad");
|
||||
} else if (this->controlMode == ControMode::trigger && Ps3.data.button.l3) {
|
||||
this->reset();
|
||||
controlMode = ControMode::joystick;
|
||||
debug->sendMsg(Loglevel::info, "Changed ControlMode to Joystick by Gamepad");
|
||||
}
|
||||
|
||||
switch (this->controlMode) {
|
||||
case ControMode::halt:
|
||||
this->reset();
|
||||
break;
|
||||
|
||||
case DriveMode::joystick:
|
||||
case ControMode::joystick:
|
||||
this->driveWithControllerJoystick();
|
||||
this->moveControl->runMoveControl();
|
||||
break;
|
||||
|
||||
case DriveMode::trigger:
|
||||
case ControMode::trigger:
|
||||
this->driveWithControllerShoulderTrigger();
|
||||
break;
|
||||
|
||||
@@ -46,21 +71,30 @@ void ManualControl::driveWithControllerJoystick() {
|
||||
|
||||
double value_per_step = MANUALCONTROL_MAX_SPEED * 2 / 256;
|
||||
this->moveControl->setSpeed((y * -1) * value_per_step);
|
||||
char str[64];
|
||||
sprintf(str, "%f", (y * -1) * value_per_step);
|
||||
debug->sendMsg(Loglevel::debug, str);
|
||||
|
||||
value_per_step = MANUALCONTROL_MAX_ROTATION * 2 / 256;
|
||||
this->moveControl->setRotationspeed(x * value_per_step);
|
||||
}
|
||||
|
||||
void ManualControl::changeDriveMode(DriveMode drive_mode) {
|
||||
this->drive_mode = drive_mode;
|
||||
void ManualControl::changeDriveMode(ControMode drive_mode) {
|
||||
this->reset();
|
||||
controlMode = drive_mode;
|
||||
debug->sendMsg(Loglevel::info, "Changed ControlMode by function");
|
||||
}
|
||||
|
||||
void ManualControl::driveWithControllerShoulderTrigger() {
|
||||
uint8_t nowL = Ps3.data.analog.button.l2;
|
||||
uint8_t nowR = Ps3.data.analog.button.r2;
|
||||
uint8_t nowR = Ps3.data.analog.button.r2;;
|
||||
|
||||
map(nowL, 0, 255, 0, 100);
|
||||
map(nowR, 0, 255, 0, 100);
|
||||
nowL = map(nowL, 0, 255, 0, 100);
|
||||
nowR = map(nowR, 0, 255, 0, 100);
|
||||
|
||||
// char str[64];
|
||||
// sprintf(str, "nachher: nowL: %u, nowR: %u", nowL, nowR);
|
||||
// debug->sendMsg(Loglevel::debug, str);
|
||||
|
||||
if (nowL != this->oldL) {
|
||||
this->motorControlLeft->setTargetPower(nowL);
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
#include "hardware/motorControl.h"
|
||||
#include "debugMqtt.h"
|
||||
|
||||
enum DriveMode {stop, joystick, trigger};
|
||||
enum ControMode {halt, joystick, trigger};
|
||||
class ManualControl {
|
||||
public:
|
||||
ManualControl();
|
||||
void init(MoveControl *moveControl, MotorControl *motorControlLeft, MotorControl *motorControlRight);
|
||||
void runManualControl();
|
||||
void changeDriveMode(DriveMode drive_mode);
|
||||
void changeDriveMode(ControMode drive_mode);
|
||||
|
||||
private:
|
||||
void driveWithControllerJoystick();
|
||||
@@ -25,7 +25,7 @@ class ManualControl {
|
||||
MotorControl *motorControlRight;
|
||||
DebugMqtt *debug;
|
||||
|
||||
DriveMode drive_mode = DriveMode::stop;
|
||||
ControMode controlMode = ControMode::halt;
|
||||
uint32_t last_millis = 0;
|
||||
|
||||
// Is needed for driveWithControllerShoulderTrigger()
|
||||
|
||||
Reference in New Issue
Block a user