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

  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. if ((abs(this -> xValue) > (joystick -> spaceing)) || (abs(this -> yValue) > (joystick -> spaceing))) {
  13. if (this -> yValue >= 0) {
  14. if (this -> xValue >= 0) {
  15. //+y , +x
  16. (left -> PWMValue) = this -> yValue;
  17. (right -> PWMValue) = (this -> yValue) - (this -> xValue);
  18. if ((this -> xValue) >= (this -> yValue)) {
  19. (left -> PWMValue) = 255;
  20. (right -> PWMValue) = -255;
  21. }
  22. } else {
  23. //+y , -x
  24. (left -> PWMValue) = this -> yValue;
  25. (right -> PWMValue) = (this -> yValue) + (this -> xValue);
  26. if (abs(this -> xValue) >= (this -> yValue)) {
  27. (left -> PWMValue) = -255;
  28. (right -> PWMValue) = 255;
  29. }
  30. }
  31. } else {
  32. if (this -> xValue >= 0) {
  33. //-y , +x
  34. (left -> PWMValue) = this -> yValue;
  35. (right -> PWMValue) = (this -> yValue) + (this -> xValue);
  36. if (this -> xValue >= abs(this -> yValue)) {
  37. (left -> PWMValue) = 255;
  38. (right -> PWMValue) = -255;
  39. }
  40. } else {
  41. //-y , -x
  42. (left -> PWMValue) = this -> yValue;
  43. (right -> PWMValue) = (this -> yValue) - (this -> xValue);
  44. if (abs(this -> xValue) >= abs(this -> yValue)) {
  45. (left -> PWMValue) = -255;
  46. (right -> PWMValue) = 255;
  47. }
  48. }
  49. }
  50. if (abs(this -> xValue) < (joystick -> spaceing)) {
  51. (left -> PWMValue) = this -> yValue;
  52. (right -> PWMValue) = this -> yValue;
  53. }
  54. } else {
  55. (left -> PWMValue) = 0;
  56. (right -> PWMValue) = 0;
  57. }
  58. }
  59. void Steuerung::updateValues() {
  60. joystick -> checkJoystickInput();
  61. mapReadingsToMatchPWMValues();
  62. applyPWMValuesDependingOnReadings();
  63. }