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.
71 lines
2.8 KiB
71 lines
2.8 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 -> lowestValue, right -> highestValue);
|
|
}
|
|
|
|
void Steuerung::applyPWMValuesDependingOnReadings() {
|
|
//TODO faktor für die Bedinungen um die abweichung von left zu right auszugleichen
|
|
//float leftFaktor = (left -> highestValue) / 255
|
|
//
|
|
//vorher aber testen ob nur die this -> vor left und right vergessen wurde.
|
|
if ((abs(this -> xValue) > (this -> joystick -> spaceing)) || (abs(this -> yValue) > (this -> joystick -> spaceing))) {
|
|
if (this -> yValue >= 0) {
|
|
if (this -> xValue >= 0) {
|
|
//+y , +x
|
|
(this -> left -> PWMValue) = this -> yValue;
|
|
(this -> right -> PWMValue) = (this -> yValue) - (this -> xValue);
|
|
if ((this -> xValue) >= (this -> yValue)) {
|
|
(this -> left -> PWMValue) = this -> left -> highestValue;
|
|
(this -> right -> PWMValue) = this -> right -> lowestValue;
|
|
}
|
|
} else {
|
|
//+y , -x
|
|
(this -> left -> PWMValue) = this -> yValue;
|
|
(this -> right -> PWMValue) = (this -> yValue) + (this -> xValue);
|
|
if (abs(this -> xValue) >= (this -> yValue)) {
|
|
(this -> left -> PWMValue) = this -> left -> lowestValue;
|
|
(this -> right -> PWMValue) = this -> right -> highestValue;
|
|
}
|
|
}
|
|
} else {
|
|
if (this -> xValue >= 0) {
|
|
//-y , +x
|
|
(this -> left -> PWMValue) = this -> yValue;
|
|
(this -> right -> PWMValue) = (this -> yValue) + (this -> xValue);
|
|
if (this -> xValue >= abs(this -> yValue)) {
|
|
(this -> left -> PWMValue) = this -> left -> highestValue;
|
|
(this -> right -> PWMValue) = this -> right -> lowestValue;
|
|
}
|
|
} else {
|
|
//-y , -x
|
|
(this -> left -> PWMValue) = this -> yValue;
|
|
(this -> right -> PWMValue) = (this -> yValue) - (this -> xValue);
|
|
if (abs(this -> xValue) >= abs(this -> yValue)) {
|
|
(this -> left -> PWMValue) = this -> left -> lowestValue;
|
|
(this -> right -> PWMValue) = this -> right -> highestValue;
|
|
}
|
|
}
|
|
}
|
|
if (abs(this -> xValue) < (this -> joystick -> spaceing)) {
|
|
(this -> left -> PWMValue) = this -> yValue;
|
|
(this -> right -> PWMValue) = this -> yValue;
|
|
}
|
|
} else {
|
|
(this -> left -> PWMValue) = 0;
|
|
(this -> right -> PWMValue) = 0;
|
|
}
|
|
|
|
}
|
|
void Steuerung::updateValues() {
|
|
joystick -> checkJoystickInput();
|
|
mapReadingsToMatchPWMValues();
|
|
applyPWMValuesDependingOnReadings();
|
|
}
|