Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Roboshark_V6 by
Fahren.cpp@8:a7f1ee7840d0, 2018-05-06 (annotated)
- Committer:
- fluckmi1
- Date:
- Sun May 06 14:17:07 2018 +0000
- Revision:
- 8:a7f1ee7840d0
- Parent:
- 7:862d80e0ea2d
- Child:
- 9:bdbf4447b55e
Mit dem han ich bitz pr?blet,
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ahlervin | 7:862d80e0ea2d | 1 | /*Roboshark V6 |
ahlervin | 6:7bbcdd07bc2d | 2 | Fahren.cpp |
ahlervin | 6:7bbcdd07bc2d | 3 | Erstellt: J. Blunschi |
ahlervin | 6:7bbcdd07bc2d | 4 | geändert: V.Ahlers |
ahlervin | 6:7bbcdd07bc2d | 5 | V.5.18 |
ahlervin | 6:7bbcdd07bc2d | 6 | */ |
ahlervin | 6:7bbcdd07bc2d | 7 | |
Jacqueline | 0:6d0671ae4648 | 8 | #include "Fahren.h" |
Jacqueline | 0:6d0671ae4648 | 9 | #include <mbed.h> |
ahlervin | 6:7bbcdd07bc2d | 10 | #include "Regler.h" |
Jacqueline | 0:6d0671ae4648 | 11 | |
Jacqueline | 0:6d0671ae4648 | 12 | |
ahlervin | 6:7bbcdd07bc2d | 13 | using namespace std; |
ahlervin | 6:7bbcdd07bc2d | 14 | |
ahlervin | 7:862d80e0ea2d | 15 | const float Fahren :: PERIOD = 0.8f; |
ahlervin | 6:7bbcdd07bc2d | 16 | |
Jacqueline | 0:6d0671ae4648 | 17 | //Konstruktor |
ahlervin | 7:862d80e0ea2d | 18 | Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler, int reglerEin): |
fluckmi1 | 8:a7f1ee7840d0 | 19 | controller(controller), counterLeft(counterLeft), counterRight(counterRight), regler(regler), reglerEin(reglerEin) { //IRSENSOR IETAH |
Jacqueline | 0:6d0671ae4648 | 20 | |
ahlervin | 6:7bbcdd07bc2d | 21 | SpeedR = 50; |
ahlervin | 6:7bbcdd07bc2d | 22 | SpeedL = 50; |
ahlervin | 6:7bbcdd07bc2d | 23 | ticker.attach(callback(this, &Fahren::getSpeed), PERIOD); |
ahlervin | 6:7bbcdd07bc2d | 24 | } |
ahlervin | 6:7bbcdd07bc2d | 25 | |
Jacqueline | 0:6d0671ae4648 | 26 | //Dekonstruktor |
ahlervin | 6:7bbcdd07bc2d | 27 | Fahren::~Fahren() { |
ahlervin | 6:7bbcdd07bc2d | 28 | ticker.detach(); |
ahlervin | 6:7bbcdd07bc2d | 29 | } |
ahlervin | 7:862d80e0ea2d | 30 | |
ahlervin | 7:862d80e0ea2d | 31 | |
ahlervin | 6:7bbcdd07bc2d | 32 | //Korrigierte Geschwindigkeit aus der Klasse Regler aufrufen |
ahlervin | 6:7bbcdd07bc2d | 33 | void Fahren::getSpeed(){ |
ahlervin | 7:862d80e0ea2d | 34 | if(reglerEin == 1){ |
ahlervin | 7:862d80e0ea2d | 35 | SpeedR = regler.getSpeedR(); |
ahlervin | 7:862d80e0ea2d | 36 | SpeedL = regler.getSpeedL(); |
fluckmi1 | 8:a7f1ee7840d0 | 37 | }else {SpeedR = regler.getSpeedR(); |
fluckmi1 | 8:a7f1ee7840d0 | 38 | SpeedL = regler.getSpeedL(); |
ahlervin | 7:862d80e0ea2d | 39 | } |
ahlervin | 6:7bbcdd07bc2d | 40 | |
ahlervin | 6:7bbcdd07bc2d | 41 | //printf("SpeedR in F = %f\n",SpeedR); |
ahlervin | 6:7bbcdd07bc2d | 42 | //printf("SpeedL in F = %f\n",SpeedL); |
ahlervin | 6:7bbcdd07bc2d | 43 | } |
Jacqueline | 0:6d0671ae4648 | 44 | |
ahlervin | 7:862d80e0ea2d | 45 | |
ahlervin | 6:7bbcdd07bc2d | 46 | //Implementation der Methode geradeaus fahren ungeregelt |
ahlervin | 6:7bbcdd07bc2d | 47 | void Fahren::geradeausU(){ |
Jacqueline | 0:6d0671ae4648 | 48 | |
Jacqueline | 0:6d0671ae4648 | 49 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 50 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 51 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 52 | |
Jacqueline | 0:6d0671ae4648 | 53 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 6:7bbcdd07bc2d | 54 | wegRechts = 1773; |
ahlervin | 6:7bbcdd07bc2d | 55 | wegLinks = 1773; |
Jacqueline | 0:6d0671ae4648 | 56 | |
Jacqueline | 0:6d0671ae4648 | 57 | //Geschwindigkeit |
ahlervin | 7:862d80e0ea2d | 58 | //speedRight = 50; |
ahlervin | 7:862d80e0ea2d | 59 | //speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 60 | |
Jacqueline | 0:6d0671ae4648 | 61 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 62 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 63 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 64 | |
Jacqueline | 0:6d0671ae4648 | 65 | //Drehrichtung der Motoren |
ahlervin | 7:862d80e0ea2d | 66 | controller.setDesiredSpeedRight(SpeedR); |
ahlervin | 7:862d80e0ea2d | 67 | controller.setDesiredSpeedLeft(-(SpeedL)); |
Jacqueline | 0:6d0671ae4648 | 68 | |
Jacqueline | 0:6d0671ae4648 | 69 | |
Jacqueline | 0:6d0671ae4648 | 70 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 71 | |
Jacqueline | 0:6d0671ae4648 | 72 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 73 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 74 | |
Jacqueline | 0:6d0671ae4648 | 75 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 76 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 77 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 78 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 79 | } |
Jacqueline | 0:6d0671ae4648 | 80 | |
Jacqueline | 0:6d0671ae4648 | 81 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 82 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 83 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 84 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 85 | } |
Jacqueline | 0:6d0671ae4648 | 86 | |
Jacqueline | 0:6d0671ae4648 | 87 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 88 | return; |
Jacqueline | 0:6d0671ae4648 | 89 | } |
Jacqueline | 0:6d0671ae4648 | 90 | |
Jacqueline | 0:6d0671ae4648 | 91 | } |
Jacqueline | 0:6d0671ae4648 | 92 | |
Jacqueline | 0:6d0671ae4648 | 93 | } |
Jacqueline | 0:6d0671ae4648 | 94 | |
ahlervin | 6:7bbcdd07bc2d | 95 | //Implementation der Methode geradeaus fahren geregelt |
ahlervin | 6:7bbcdd07bc2d | 96 | void Fahren::geradeausG(){ |
ahlervin | 6:7bbcdd07bc2d | 97 | |
ahlervin | 6:7bbcdd07bc2d | 98 | //einlesen des aktuellen Encoder standes |
ahlervin | 6:7bbcdd07bc2d | 99 | initialClicksRight = counterRight.read(); |
ahlervin | 6:7bbcdd07bc2d | 100 | initialClicksLeft = counterLeft.read(); |
ahlervin | 6:7bbcdd07bc2d | 101 | |
ahlervin | 6:7bbcdd07bc2d | 102 | //Anzahl Clicks die der Encoder zählen soll |
fluckmi1 | 8:a7f1ee7840d0 | 103 | wegRechts = 1788; //vo 1773 |
fluckmi1 | 8:a7f1ee7840d0 | 104 | wegLinks = 1788; //vo 1773 |
ahlervin | 6:7bbcdd07bc2d | 105 | |
ahlervin | 6:7bbcdd07bc2d | 106 | //Geschwindigkeit |
ahlervin | 6:7bbcdd07bc2d | 107 | //speedRight = 50;//SpeedR |
ahlervin | 6:7bbcdd07bc2d | 108 | //speedLeft = 50;//SpeedL |
ahlervin | 6:7bbcdd07bc2d | 109 | |
fluckmi1 | 8:a7f1ee7840d0 | 110 | |
ahlervin | 6:7bbcdd07bc2d | 111 | //Zustand, dass der Roboter nicht gestoppt hat |
ahlervin | 6:7bbcdd07bc2d | 112 | stopRight = false; |
ahlervin | 6:7bbcdd07bc2d | 113 | stopLeft = false; |
ahlervin | 6:7bbcdd07bc2d | 114 | |
ahlervin | 6:7bbcdd07bc2d | 115 | //Drehrichtung der Motoren |
ahlervin | 6:7bbcdd07bc2d | 116 | controller.setDesiredSpeedRight(SpeedR); |
ahlervin | 6:7bbcdd07bc2d | 117 | controller.setDesiredSpeedLeft(-(SpeedL)); |
fluckmi1 | 8:a7f1ee7840d0 | 118 | //printf("SpeedR in F2= %f\n",SpeedR); |
fluckmi1 | 8:a7f1ee7840d0 | 119 | //printf("SpeedL in F2= %f\n",SpeedL); |
Jacqueline | 0:6d0671ae4648 | 120 | |
ahlervin | 6:7bbcdd07bc2d | 121 | while(1){ |
ahlervin | 6:7bbcdd07bc2d | 122 | |
ahlervin | 6:7bbcdd07bc2d | 123 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 6:7bbcdd07bc2d | 124 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 6:7bbcdd07bc2d | 125 | |
ahlervin | 6:7bbcdd07bc2d | 126 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 6:7bbcdd07bc2d | 127 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
ahlervin | 6:7bbcdd07bc2d | 128 | controller.setDesiredSpeedRight(0); |
ahlervin | 6:7bbcdd07bc2d | 129 | stopRight = true; |
ahlervin | 6:7bbcdd07bc2d | 130 | } |
ahlervin | 6:7bbcdd07bc2d | 131 | |
ahlervin | 6:7bbcdd07bc2d | 132 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
fluckmi1 | 8:a7f1ee7840d0 | 133 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks){ |
ahlervin | 6:7bbcdd07bc2d | 134 | controller.setDesiredSpeedLeft(0); |
ahlervin | 6:7bbcdd07bc2d | 135 | stopLeft = true; |
ahlervin | 6:7bbcdd07bc2d | 136 | } |
ahlervin | 6:7bbcdd07bc2d | 137 | |
ahlervin | 6:7bbcdd07bc2d | 138 | if(stopRight == true && stopLeft == true){ |
ahlervin | 6:7bbcdd07bc2d | 139 | return; |
ahlervin | 6:7bbcdd07bc2d | 140 | } |
ahlervin | 6:7bbcdd07bc2d | 141 | |
ahlervin | 6:7bbcdd07bc2d | 142 | } |
ahlervin | 6:7bbcdd07bc2d | 143 | |
ahlervin | 6:7bbcdd07bc2d | 144 | } |
ahlervin | 6:7bbcdd07bc2d | 145 | |
Jacqueline | 0:6d0671ae4648 | 146 | //Implementation der Methode 90 Grad Rechtsdrehen |
Jacqueline | 0:6d0671ae4648 | 147 | void Fahren::rechts90() { |
Jacqueline | 0:6d0671ae4648 | 148 | |
Jacqueline | 0:6d0671ae4648 | 149 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 150 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 151 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 152 | |
Jacqueline | 0:6d0671ae4648 | 153 | //Anzahl Clicks die der Encoder zählen soll |
fluckmi1 | 8:a7f1ee7840d0 | 154 | wegRechts = 863; |
fluckmi1 | 8:a7f1ee7840d0 | 155 | wegLinks = 863; |
Jacqueline | 0:6d0671ae4648 | 156 | |
Jacqueline | 0:6d0671ae4648 | 157 | //Geschwindigkeit |
fluckmi1 | 8:a7f1ee7840d0 | 158 | speedRight = 50; |
fluckmi1 | 8:a7f1ee7840d0 | 159 | speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 160 | |
Jacqueline | 0:6d0671ae4648 | 161 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 162 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 163 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 164 | |
Jacqueline | 0:6d0671ae4648 | 165 | //Drehrichtung der Motoren |
fluckmi1 | 8:a7f1ee7840d0 | 166 | controller.setDesiredSpeedRight(SpeedR); |
fluckmi1 | 8:a7f1ee7840d0 | 167 | controller.setDesiredSpeedLeft(SpeedL); |
fluckmi1 | 8:a7f1ee7840d0 | 168 | //printf("SpeedR in F = %f\n", SpeedR); |
fluckmi1 | 8:a7f1ee7840d0 | 169 | //printf("SpeedL in F = %f\n", SpeedL); |
Jacqueline | 0:6d0671ae4648 | 170 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 171 | |
Jacqueline | 0:6d0671ae4648 | 172 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 173 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 174 | |
Jacqueline | 0:6d0671ae4648 | 175 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 176 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 177 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 178 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 179 | } |
Jacqueline | 0:6d0671ae4648 | 180 | |
Jacqueline | 0:6d0671ae4648 | 181 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 182 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 183 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 184 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 185 | } |
Jacqueline | 0:6d0671ae4648 | 186 | |
Jacqueline | 0:6d0671ae4648 | 187 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 188 | return; |
Jacqueline | 0:6d0671ae4648 | 189 | } |
Jacqueline | 0:6d0671ae4648 | 190 | |
Jacqueline | 0:6d0671ae4648 | 191 | } |
Jacqueline | 0:6d0671ae4648 | 192 | |
Jacqueline | 0:6d0671ae4648 | 193 | } |
Jacqueline | 0:6d0671ae4648 | 194 | |
Jacqueline | 0:6d0671ae4648 | 195 | |
Jacqueline | 0:6d0671ae4648 | 196 | |
Jacqueline | 0:6d0671ae4648 | 197 | //Implementation der Methode 180 Grad Rechtsdrehen |
Jacqueline | 0:6d0671ae4648 | 198 | void Fahren::rechts180() { |
Jacqueline | 0:6d0671ae4648 | 199 | |
Jacqueline | 0:6d0671ae4648 | 200 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 201 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 202 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 203 | |
Jacqueline | 0:6d0671ae4648 | 204 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 7:862d80e0ea2d | 205 | wegRechts = 1752; |
ahlervin | 7:862d80e0ea2d | 206 | wegLinks = 1752; |
Jacqueline | 0:6d0671ae4648 | 207 | |
Jacqueline | 0:6d0671ae4648 | 208 | //Geschwindigkeit |
ahlervin | 7:862d80e0ea2d | 209 | //speedRight = 50; |
ahlervin | 7:862d80e0ea2d | 210 | //speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 211 | |
Jacqueline | 0:6d0671ae4648 | 212 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 213 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 214 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 215 | |
Jacqueline | 0:6d0671ae4648 | 216 | //Drehrichtung der Motoren |
ahlervin | 7:862d80e0ea2d | 217 | controller.setDesiredSpeedRight((SpeedR)); |
ahlervin | 7:862d80e0ea2d | 218 | controller.setDesiredSpeedLeft((SpeedL)); |
Jacqueline | 0:6d0671ae4648 | 219 | |
Jacqueline | 0:6d0671ae4648 | 220 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 221 | |
Jacqueline | 0:6d0671ae4648 | 222 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 223 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 224 | |
Jacqueline | 0:6d0671ae4648 | 225 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 226 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 227 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 228 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 229 | } |
Jacqueline | 0:6d0671ae4648 | 230 | |
Jacqueline | 0:6d0671ae4648 | 231 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 232 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 233 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 234 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 235 | } |
Jacqueline | 0:6d0671ae4648 | 236 | |
Jacqueline | 0:6d0671ae4648 | 237 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 238 | return; |
Jacqueline | 0:6d0671ae4648 | 239 | } |
Jacqueline | 0:6d0671ae4648 | 240 | |
Jacqueline | 0:6d0671ae4648 | 241 | } |
Jacqueline | 0:6d0671ae4648 | 242 | |
Jacqueline | 0:6d0671ae4648 | 243 | } |
Jacqueline | 0:6d0671ae4648 | 244 | |
Jacqueline | 0:6d0671ae4648 | 245 | |
Jacqueline | 2:402b1a74fff6 | 246 | //Implementation der Methode 90 Grad Linksdrehen |
Jacqueline | 2:402b1a74fff6 | 247 | void Fahren::links90() { |
Jacqueline | 0:6d0671ae4648 | 248 | |
Jacqueline | 0:6d0671ae4648 | 249 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 250 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 251 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 252 | |
Jacqueline | 0:6d0671ae4648 | 253 | //Anzahl Clicks die der Encoder zählen soll |
Jacqueline | 2:402b1a74fff6 | 254 | wegRechts = 878; |
Jacqueline | 2:402b1a74fff6 | 255 | wegLinks = 878; |
Jacqueline | 0:6d0671ae4648 | 256 | |
Jacqueline | 0:6d0671ae4648 | 257 | //Geschwindigkeit |
ahlervin | 7:862d80e0ea2d | 258 | //speedRight = 50; |
ahlervin | 7:862d80e0ea2d | 259 | //speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 260 | |
Jacqueline | 0:6d0671ae4648 | 261 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 262 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 263 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 264 | |
Jacqueline | 0:6d0671ae4648 | 265 | //Drehrichtung der Motoren |
ahlervin | 7:862d80e0ea2d | 266 | controller.setDesiredSpeedRight((-SpeedR)); |
ahlervin | 7:862d80e0ea2d | 267 | controller.setDesiredSpeedLeft((-SpeedL)); |
Jacqueline | 0:6d0671ae4648 | 268 | |
Jacqueline | 0:6d0671ae4648 | 269 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 270 | |
Jacqueline | 0:6d0671ae4648 | 271 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 272 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 273 | |
Jacqueline | 0:6d0671ae4648 | 274 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 275 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 276 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 277 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 278 | } |
Jacqueline | 0:6d0671ae4648 | 279 | |
Jacqueline | 0:6d0671ae4648 | 280 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 281 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 282 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 283 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 284 | } |
Jacqueline | 0:6d0671ae4648 | 285 | |
Jacqueline | 0:6d0671ae4648 | 286 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 287 | return; |
Jacqueline | 0:6d0671ae4648 | 288 | } |
Jacqueline | 0:6d0671ae4648 | 289 | |
Jacqueline | 0:6d0671ae4648 | 290 | } |
Jacqueline | 0:6d0671ae4648 | 291 | |
Jacqueline | 0:6d0671ae4648 | 292 | } |
Jacqueline | 0:6d0671ae4648 | 293 | |
ahlervin | 4:767fd282dd9c | 294 | |
ahlervin | 4:767fd282dd9c | 295 | //Implementation der Methode Ziel erreicht |
ahlervin | 4:767fd282dd9c | 296 | void Fahren::ziel() { |
ahlervin | 4:767fd282dd9c | 297 | |
ahlervin | 4:767fd282dd9c | 298 | //einlesen des aktuellen Encoder standes |
ahlervin | 4:767fd282dd9c | 299 | initialClicksRight = counterRight.read(); |
ahlervin | 4:767fd282dd9c | 300 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 301 | |
ahlervin | 4:767fd282dd9c | 302 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 4:767fd282dd9c | 303 | wegRechts = 7050; |
ahlervin | 4:767fd282dd9c | 304 | wegLinks = 7050; |
ahlervin | 4:767fd282dd9c | 305 | |
ahlervin | 4:767fd282dd9c | 306 | //Geschwindigkeit |
ahlervin | 7:862d80e0ea2d | 307 | //speedRight = 80; |
ahlervin | 7:862d80e0ea2d | 308 | //speedLeft = 80; |
ahlervin | 4:767fd282dd9c | 309 | |
ahlervin | 4:767fd282dd9c | 310 | //Zustand, dass der Roboter nicht gestoppt hat |
ahlervin | 4:767fd282dd9c | 311 | stopRight = false; |
ahlervin | 4:767fd282dd9c | 312 | stopLeft = false; |
ahlervin | 4:767fd282dd9c | 313 | |
ahlervin | 4:767fd282dd9c | 314 | //Drehrichtung der Motoren |
ahlervin | 7:862d80e0ea2d | 315 | controller.setDesiredSpeedRight((SpeedR)); |
ahlervin | 7:862d80e0ea2d | 316 | controller.setDesiredSpeedLeft((SpeedR)); |
ahlervin | 4:767fd282dd9c | 317 | |
ahlervin | 4:767fd282dd9c | 318 | while(1){ |
ahlervin | 4:767fd282dd9c | 319 | |
ahlervin | 4:767fd282dd9c | 320 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 321 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 322 | |
ahlervin | 4:767fd282dd9c | 323 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 324 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
ahlervin | 4:767fd282dd9c | 325 | controller.setDesiredSpeedRight(0); |
ahlervin | 4:767fd282dd9c | 326 | stopRight = true; |
ahlervin | 4:767fd282dd9c | 327 | } |
ahlervin | 4:767fd282dd9c | 328 | |
ahlervin | 4:767fd282dd9c | 329 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 330 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
ahlervin | 4:767fd282dd9c | 331 | controller.setDesiredSpeedLeft(0); |
ahlervin | 4:767fd282dd9c | 332 | stopLeft = true; |
ahlervin | 4:767fd282dd9c | 333 | } |
ahlervin | 4:767fd282dd9c | 334 | |
ahlervin | 4:767fd282dd9c | 335 | if(stopRight == true && stopLeft == true){ |
ahlervin | 4:767fd282dd9c | 336 | return; |
ahlervin | 4:767fd282dd9c | 337 | } |
ahlervin | 4:767fd282dd9c | 338 | } |
ahlervin | 4:767fd282dd9c | 339 | |
ahlervin | 4:767fd282dd9c | 340 | } |
Jacqueline | 0:6d0671ae4648 | 341 | |
ahlervin | 4:767fd282dd9c | 342 | //Implementation der Methode stopp |
ahlervin | 4:767fd282dd9c | 343 | void Fahren::stopp(){ |
ahlervin | 4:767fd282dd9c | 344 | |
ahlervin | 4:767fd282dd9c | 345 | //einlesen des aktuellen Encoder standes |
ahlervin | 4:767fd282dd9c | 346 | initialClicksRight = counterRight.read(); |
ahlervin | 4:767fd282dd9c | 347 | initialClicksLeft = counterLeft.read(); |
ahlervin | 4:767fd282dd9c | 348 | |
ahlervin | 4:767fd282dd9c | 349 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 4:767fd282dd9c | 350 | wegRechts = 0; |
ahlervin | 4:767fd282dd9c | 351 | wegLinks = 0; |
ahlervin | 4:767fd282dd9c | 352 | |
ahlervin | 4:767fd282dd9c | 353 | //Geschwindigkeit |
ahlervin | 4:767fd282dd9c | 354 | speedRight = 0; |
ahlervin | 4:767fd282dd9c | 355 | speedLeft = 0; |
ahlervin | 4:767fd282dd9c | 356 | |
ahlervin | 4:767fd282dd9c | 357 | //Zustand, dass der Roboter nicht gestoppt hat |
ahlervin | 4:767fd282dd9c | 358 | stopRight = false; |
ahlervin | 4:767fd282dd9c | 359 | stopLeft = false; |
ahlervin | 4:767fd282dd9c | 360 | |
ahlervin | 4:767fd282dd9c | 361 | //Drehrichtung der Motoren |
ahlervin | 4:767fd282dd9c | 362 | controller.setDesiredSpeedRight(speedRight); |
ahlervin | 4:767fd282dd9c | 363 | controller.setDesiredSpeedLeft(-(speedLeft)); |
ahlervin | 4:767fd282dd9c | 364 | |
ahlervin | 4:767fd282dd9c | 365 | |
ahlervin | 4:767fd282dd9c | 366 | while(1){ |
ahlervin | 4:767fd282dd9c | 367 | |
ahlervin | 4:767fd282dd9c | 368 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 369 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 370 | |
ahlervin | 4:767fd282dd9c | 371 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 372 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
ahlervin | 4:767fd282dd9c | 373 | controller.setDesiredSpeedRight(0); |
ahlervin | 4:767fd282dd9c | 374 | stopRight = true; |
ahlervin | 4:767fd282dd9c | 375 | } |
ahlervin | 4:767fd282dd9c | 376 | |
ahlervin | 4:767fd282dd9c | 377 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 378 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
ahlervin | 4:767fd282dd9c | 379 | controller.setDesiredSpeedLeft(0); |
ahlervin | 4:767fd282dd9c | 380 | stopLeft = true; |
ahlervin | 4:767fd282dd9c | 381 | } |
ahlervin | 4:767fd282dd9c | 382 | |
ahlervin | 4:767fd282dd9c | 383 | if(stopRight == true && stopLeft == true){ |
ahlervin | 4:767fd282dd9c | 384 | return; |
ahlervin | 4:767fd282dd9c | 385 | } |
ahlervin | 4:767fd282dd9c | 386 | |
ahlervin | 4:767fd282dd9c | 387 | } |
ahlervin | 4:767fd282dd9c | 388 | |
ahlervin | 4:767fd282dd9c | 389 | } |