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

  1. #include <avr/interrupt.h>
  2. #include <avr/io.h>
  3. #include <Arduino.h>
  4. void inline clearCommands() {
  5. for(uint8_t i=0; i<32; i++) {
  6. commands[i] = 0xFF;
  7. }
  8. }
  9. void setup() {
  10. remoteControlInit();
  11. funkInit();
  12. Serial.begin(115200);
  13. driveTimeout = 50;
  14. /*
  15. commands[0] = speedA;
  16. commands[1] = 0xFF & (pwmA >> 8);
  17. commands[2] = 0xFF & pwmA;
  18. commands[3] = speedB;
  19. commands[4] = 0xFF & (pwmB >> 8);
  20. commands[5] = 0xFF & pwmB;
  21. commands[6] = goDrive;
  22. commands[9] = timeToDrive;
  23. commands[10] = 0xFF & (driveTimeout >> 8);
  24. commands[11] = 0xFF & driveTimeout; */
  25. clearCommands();
  26. }
  27. void loop() {
  28. //char text[32] = "Hello";
  29. // radio.write(&commands, sizeof(commands));
  30. //lcdMenu();
  31. //delay(10000);
  32. manualDrive();
  33. }
  34. void lcdMenu() {
  35. lcd.println("Platzhalter");
  36. if(tasten.getButtonCycle(buttonUp)) {
  37. tasten.clearAllButtons();
  38. }
  39. if(tasten.getButtonCycle(buttonDown)) {
  40. tasten.clearAllButtons();
  41. }
  42. }
  43. void manualDrive() {
  44. bool goOn = false;
  45. while(!tasten.getButtonCycle(buttonStart)) {
  46. clearCommands();
  47. if(!tasten.getAnyPressed()) {
  48. lcd.clear();
  49. lcd.println("Warte...");
  50. }
  51. if(tasten.checkButton(buttonB) || tasten.checkButton(buttonUp)) {
  52. pwmA = -215;
  53. pwmB = -255;
  54. // tasten.clearButton(buttonB);
  55. lcd.clear();
  56. lcd.println("geradeaus fahren");
  57. goOn =true;
  58. }
  59. if(tasten.checkButton(buttonC) || tasten.checkButton(buttonDown)) {
  60. pwmA = 100;
  61. pwmB = 255;
  62. // tasten.clearButton(buttonC);
  63. lcd.clear();
  64. lcd.println("rueckwaerts fahren");
  65. goOn =true;
  66. }
  67. if(tasten.checkButton(buttonRight)) {
  68. pwmA = -100; //rechter Motor
  69. pwmB = 100;
  70. //tasten.clearButton(buttonRight);
  71. lcd.clear();
  72. lcd.println("rechts lenken");
  73. goOn =true;
  74. }
  75. if(tasten.checkButton(buttonLeft)) {
  76. pwmB = -100;
  77. pwmA = 100;
  78. //tasten.clearButton(buttonLeft);
  79. lcd.clear();
  80. lcd.println("links lenken");
  81. goOn =true;
  82. }
  83. if(goOn) {
  84. commands[0] = speedA;
  85. commands[1] = highByte(pwmA);
  86. commands[2] = lowByte(pwmA);
  87. commands[3] = speedB;
  88. commands[4] = highByte(pwmB);
  89. commands[5] = lowByte(pwmB);
  90. commands[6] = timeToDrive;
  91. commands[7] = highByte(driveTimeout);
  92. commands[8] = lowByte(driveTimeout);
  93. commands[9] = goDrive;
  94. radio.write(&commands, sizeof(commands));
  95. goOn = false;
  96. }
  97. }
  98. tasten.clearAllButtons();
  99. }
  100. ISR(TIMER2_COMPA_vect) { // called by timer2
  101. tasten.checkButtons(); //Aufruf 1-mal pro Millisekunde
  102. }