Files
Bachelorarbeit-Rover/src/driveModi/Modi/ManualControl/manualControl.cpp
T
2022-12-27 13:55:36 +01:00

43 lines
1.1 KiB
C++

/**
* @file manualControl.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief Implementation of the class manualControl.h
* @version 0.1
* @date 2021-12-13
*
* @copyright Copyright (c) 2021
*
*/
#include "manualControl.h"
ManualControl::ManualControl(MoveControl *moveControl, Ps3Controller *gamepad) {
this->moveControl = moveControl;
this->gamepad = gamepad;
this->moveControl->setDrivingStatus(DrivingStatus::drive);
}
ManualControl::~ManualControl() {
this->moveControl->setSpeed(0);
this->moveControl->setRotationSpeed(0);
this->moveControl->setDrivingStatus(DrivingStatus::stop);
}
void ManualControl::loop() {
if (millis() - this->lastMillis < delay) {
return;
}
this->runManualControl();
this->lastMillis = millis();
}
void ManualControl::runManualControl() {
int8_t x = this->gamepad->data.analog.stick.lx;
int8_t y = this->gamepad->data.analog.stick.ly;
double value_per_step = this->max_speed * 2 / 256;
this->moveControl->setSpeed((y * -1) * value_per_step);
value_per_step = this->max_rotation * 2 / 256;
this->moveControl->setRotationSpeed(-x * value_per_step);
}