Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.2 KiB

#include "Steuerung.h"
Steuerung::Steuerung(Joystick* joystick, Motor* left, Motor* right) {
this -> joystick = joystick;
this -> left = left;
this -> right = right;
}
void Steuerung::mapReadingsToMatchPWMValues() {
(this -> xValue) = map(joystick -> xAxisReading, joystick -> lowestValue, joystick -> highestValue, left -> lowestValue, left -> highestValue);
(this -> yValue) = map(joystick -> yAxisReading, joystick -> lowestValue, joystick -> highestValue, right -> highestValue, right -> lowestValue);
}
void Steuerung::applyPWMValuesDependingOnReadings() {
if ((abs(this -> xValue) > (joystick -> spaceing)) || (abs(this -> yValue) > (joystick -> spaceing))) {
if (this -> yValue >= 0) {
if (this -> xValue >= 0) {
//+y , +x
(left -> PWMValue) = this -> yValue;
(right -> PWMValue) = (this -> yValue) - (this -> xValue);
if ((this -> xValue) >= (this -> yValue)) {
(left -> PWMValue) = 255;
(right -> PWMValue) = -255;
}
} else {
//+y , -x
(left -> PWMValue) = this -> yValue;
(right -> PWMValue) = (this -> yValue) + (this -> xValue);
if (abs(this -> xValue) >= (this -> yValue)) {
(left -> PWMValue) = -255;
(right -> PWMValue) = 255;
}
}
} else {
if (this -> xValue >= 0) {
//-y , +x
(left -> PWMValue) = this -> yValue;
(right -> PWMValue) = (this -> yValue) + (this -> xValue);
if (this -> xValue >= abs(this -> yValue)) {
(left -> PWMValue) = 255;
(right -> PWMValue) = -255;
}
} else {
//-y , -x
(left -> PWMValue) = this -> yValue;
(right -> PWMValue) = (this -> yValue) - (this -> xValue);
if (abs(this -> xValue) >= abs(this -> yValue)) {
(left -> PWMValue) = -255;
(right -> PWMValue) = 255;
}
}
}
if (abs(this -> xValue) < (joystick -> spaceing)) {
(left -> PWMValue) = this -> yValue;
(right -> PWMValue) = this -> yValue;
}
} else {
(left -> PWMValue) = 0;
(right -> PWMValue) = 0;
}
}
void Steuerung::updateValues() {
joystick -> checkJoystickInput();
mapReadingsToMatchPWMValues();
applyPWMValuesDependingOnReadings();
}