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.

115 lines
2.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #define xPin A5
  2. #define yPin A6
  3. #define leftMax 255//215
  4. #define leftMin -255//-100
  5. #define rightMax 255
  6. #define rightMin -255
  7. volatile int16_t xValue = 0;
  8. volatile int16_t yValue = 0;
  9. volatile int16_t leftPWM = 0;
  10. volatile int16_t rightPWM = 0;
  11. const int16_t deadZone = 40;
  12. void motorMapping() {
  13. static long temp = millis();
  14. koordinaten(analogRead(xPin), analogRead(yPin));
  15. motorPWM();
  16. pwmB = map(leftPWM, -255,255,leftMin,leftMax);
  17. pwmA = map(rightPWM, -255,255,rightMin,rightMax);
  18. if((millis() - temp) > 100) {
  19. <<<<<<< HEAD
  20. //lcd.clear();
  21. lcd.println("Links: ");
  22. lcd.println(pwmB);
  23. lcd.gotoXY(0,2);
  24. lcd.println("Rechts: ");
  25. lcd.println(pwmA);
  26. =======
  27. // lcd.clear();
  28. // lcd.println("Links: ");
  29. lcdLines[0] = "Links: " + String(pwmB, DEC);
  30. // lcd.println(pwmB);
  31. // lcd.gotoXY(0,2);
  32. // lcd.println("Rechts: ");
  33. lcdLines[0] = "Rechts: " + String(pwmA, DEC);
  34. // lcd.println(pwmA);
  35. >>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05
  36. }
  37. senden();
  38. }
  39. void senden() {
  40. commands[0] = speedA;
  41. commands[1] = highByte(pwmA);
  42. commands[2] = lowByte(pwmA);
  43. commands[3] = speedB;
  44. commands[4] = highByte(pwmB);
  45. commands[5] = lowByte(pwmB);
  46. commands[6] = timeToDrive;
  47. commands[7] = highByte(driveTimeout);
  48. commands[8] = lowByte(driveTimeout);
  49. commands[9] = goDrive;
  50. commands[10] = getDistance;
  51. radio.write(&commands, sizeof(commands));
  52. }
  53. void koordinaten(uint16_t x, uint16_t y) {
  54. //9-bit reichen, der ADC schafft bestenfalls 8-bit praezision
  55. x = x >> 1;
  56. y = y >> 1;
  57. xValue = map(x, 0, 511, -255, 255);
  58. yValue = map(y, 0, 511, 255, -255);
  59. }
  60. void motorPWM() {
  61. if((abs(xValue) > deadZone) || (abs(yValue) > deadZone)) {
  62. if(yValue >= 0) {
  63. if(xValue >= 0) {
  64. //+y , +x
  65. leftPWM = yValue;
  66. rightPWM = yValue - xValue;
  67. if(xValue >= yValue) {
  68. leftPWM = 255;
  69. rightPWM = -255;
  70. }
  71. } else {
  72. //+y , -x
  73. leftPWM = yValue;
  74. rightPWM = yValue + xValue;
  75. if(abs(xValue) >= yValue) {
  76. leftPWM = -255;
  77. rightPWM = 255;
  78. }
  79. }
  80. } else {
  81. if(xValue >= 0) {
  82. //-y , +x
  83. leftPWM = yValue;
  84. rightPWM = yValue + xValue;
  85. if(xValue >= abs(yValue)) {
  86. leftPWM = 255;
  87. rightPWM = -255;
  88. }
  89. } else {
  90. //-y , -x
  91. leftPWM = yValue;
  92. rightPWM = yValue - xValue;
  93. if(abs(xValue) >= abs(yValue)) {
  94. leftPWM = -255;
  95. rightPWM = 255;
  96. }
  97. }
  98. }
  99. if(abs(xValue) < deadZone) {
  100. leftPWM = yValue;
  101. rightPWM = yValue;
  102. }
  103. } else {
  104. leftPWM = 0;
  105. rightPWM = 0;
  106. }
  107. }