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

  1. #include "Steuerung.h"
  2. Steuerung::Steuerung(Joystick* joystick, Motor* left, Motor* right) {
  3. this -> joystick = joystick;
  4. this -> left = left;
  5. this -> right = right;
  6. }
  7. void Steuerung::mapReadingsToMatchPWMValues() {
  8. (this -> xValue) = map(joystick -> xAxisReading, joystick -> lowestValue, joystick -> highestValue, left -> lowestValue, left -> highestValue);
  9. (this -> yValue) = map(joystick -> yAxisReading, joystick -> lowestValue, joystick -> highestValue, right -> highestValue, right -> lowestValue);
  10. }
  11. void Steuerung::applyPWMValuesDependingOnReadings() {
  12. //TODO faktor für die Bedinungen um die abweichung von left zu right auszugleichen
  13. //float leftFaktor = (left -> highestValue) / 255
  14. //
  15. //vorher aber testen ob nur die this -> vor left und right vergessen wurde.
  16. if ((abs(this -> xValue) > (this -> joystick -> spaceing)) || (abs(this -> yValue) > (this -> joystick -> spaceing))) {
  17. if (this -> yValue >= 0) {
  18. if (this -> xValue >= 0) {
  19. //+y , +x
  20. (this -> left -> PWMValue) = this -> yValue;
  21. (this -> right -> PWMValue) = (this -> yValue) - (this -> xValue);
  22. if ((this -> xValue) >= (this -> yValue)) {
  23. (this -> left -> PWMValue) = this -> left -> highestValue;
  24. (this -> right -> PWMValue) = this -> right -> lowestValue;
  25. }
  26. } else {
  27. //+y , -x
  28. (this -> left -> PWMValue) = this -> yValue;
  29. (this -> right -> PWMValue) = (this -> yValue) + (this -> xValue);
  30. if (abs(this -> xValue) >= (this -> yValue)) {
  31. (this -> left -> PWMValue) = this -> left -> lowestValue;
  32. (this -> right -> PWMValue) = this -> right -> highestValue;
  33. }
  34. }
  35. } else {
  36. if (this -> xValue >= 0) {
  37. //-y , +x
  38. (this -> left -> PWMValue) = this -> yValue;
  39. (this -> right -> PWMValue) = (this -> yValue) + (this -> xValue);
  40. if (this -> xValue >= abs(this -> yValue)) {
  41. (this -> left -> PWMValue) = this -> left -> highestValue;
  42. (this -> right -> PWMValue) = this -> right -> lowestValue;
  43. }
  44. } else {
  45. //-y , -x
  46. (this -> left -> PWMValue) = this -> yValue;
  47. (this -> right -> PWMValue) = (this -> yValue) - (this -> xValue);
  48. if (abs(this -> xValue) >= abs(this -> yValue)) {
  49. (this -> left -> PWMValue) = this -> left -> lowestValue;
  50. (this -> right -> PWMValue) = this -> right -> highestValue;
  51. }
  52. }
  53. }
  54. if (abs(this -> xValue) < (this -> joystick -> spaceing)) {
  55. (this -> left -> PWMValue) = this -> yValue;
  56. (this -> right -> PWMValue) = this -> yValue;
  57. }
  58. } else {
  59. (this -> left -> PWMValue) = 0;
  60. (this -> right -> PWMValue) = 0;
  61. }
  62. }
  63. void Steuerung::updateValues() {
  64. joystick -> checkJoystickInput();
  65. mapReadingsToMatchPWMValues();
  66. applyPWMValuesDependingOnReadings();
  67. }