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_V9 by
Fahren.cpp@6:7bbcdd07bc2d, 2018-05-03 (annotated)
- Committer:
- ahlervin
- Date:
- Thu May 03 19:36:16 2018 +0000
- Revision:
- 6:7bbcdd07bc2d
- Parent:
- 4:767fd282dd9c
- Child:
- 7:862d80e0ea2d
Aufgemotzter Regler noch nicht ganz fertig
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ahlervin | 6:7bbcdd07bc2d | 1 | /*Roboshark V4 |
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 | 6:7bbcdd07bc2d | 15 | const float Fahren :: PERIOD = 0.2f; |
ahlervin | 6:7bbcdd07bc2d | 16 | |
Jacqueline | 0:6d0671ae4648 | 17 | //Konstruktor |
ahlervin | 6:7bbcdd07bc2d | 18 | Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler): |
ahlervin | 6:7bbcdd07bc2d | 19 | controller(controller), counterLeft(counterLeft), counterRight(counterRight), regler(regler){ |
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 | 6:7bbcdd07bc2d | 30 | //Korrigierte Geschwindigkeit aus der Klasse Regler aufrufen |
ahlervin | 6:7bbcdd07bc2d | 31 | void Fahren::getSpeed(){ |
ahlervin | 6:7bbcdd07bc2d | 32 | SpeedR = regler.get_SpeedR(); |
ahlervin | 6:7bbcdd07bc2d | 33 | SpeedL = regler.get_SpeedL(); |
ahlervin | 6:7bbcdd07bc2d | 34 | |
ahlervin | 6:7bbcdd07bc2d | 35 | //printf("SpeedR in F = %f\n",SpeedR); |
ahlervin | 6:7bbcdd07bc2d | 36 | //printf("SpeedL in F = %f\n",SpeedL); |
ahlervin | 6:7bbcdd07bc2d | 37 | } |
Jacqueline | 0:6d0671ae4648 | 38 | |
ahlervin | 6:7bbcdd07bc2d | 39 | |
ahlervin | 6:7bbcdd07bc2d | 40 | //Implementation der Methode geradeaus fahren ungeregelt |
ahlervin | 6:7bbcdd07bc2d | 41 | void Fahren::geradeausU(){ |
Jacqueline | 0:6d0671ae4648 | 42 | |
Jacqueline | 0:6d0671ae4648 | 43 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 44 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 45 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 46 | |
Jacqueline | 0:6d0671ae4648 | 47 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 6:7bbcdd07bc2d | 48 | wegRechts = 1773; |
ahlervin | 6:7bbcdd07bc2d | 49 | wegLinks = 1773; |
Jacqueline | 0:6d0671ae4648 | 50 | |
Jacqueline | 0:6d0671ae4648 | 51 | //Geschwindigkeit |
ahlervin | 6:7bbcdd07bc2d | 52 | speedRight = 50; |
ahlervin | 6:7bbcdd07bc2d | 53 | speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 54 | |
Jacqueline | 0:6d0671ae4648 | 55 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 56 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 57 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 58 | |
Jacqueline | 0:6d0671ae4648 | 59 | //Drehrichtung der Motoren |
Jacqueline | 0:6d0671ae4648 | 60 | controller.setDesiredSpeedRight(speedRight); |
Jacqueline | 0:6d0671ae4648 | 61 | controller.setDesiredSpeedLeft(-(speedLeft)); |
Jacqueline | 0:6d0671ae4648 | 62 | |
Jacqueline | 0:6d0671ae4648 | 63 | |
Jacqueline | 0:6d0671ae4648 | 64 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 65 | |
Jacqueline | 0:6d0671ae4648 | 66 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 67 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 68 | |
Jacqueline | 0:6d0671ae4648 | 69 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 70 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 71 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 72 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 73 | } |
Jacqueline | 0:6d0671ae4648 | 74 | |
Jacqueline | 0:6d0671ae4648 | 75 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 76 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 77 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 78 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 79 | } |
Jacqueline | 0:6d0671ae4648 | 80 | |
Jacqueline | 0:6d0671ae4648 | 81 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 82 | return; |
Jacqueline | 0:6d0671ae4648 | 83 | } |
Jacqueline | 0:6d0671ae4648 | 84 | |
Jacqueline | 0:6d0671ae4648 | 85 | } |
Jacqueline | 0:6d0671ae4648 | 86 | |
Jacqueline | 0:6d0671ae4648 | 87 | } |
Jacqueline | 0:6d0671ae4648 | 88 | |
ahlervin | 6:7bbcdd07bc2d | 89 | //Implementation der Methode geradeaus fahren geregelt |
ahlervin | 6:7bbcdd07bc2d | 90 | void Fahren::geradeausG(){ |
ahlervin | 6:7bbcdd07bc2d | 91 | |
ahlervin | 6:7bbcdd07bc2d | 92 | //einlesen des aktuellen Encoder standes |
ahlervin | 6:7bbcdd07bc2d | 93 | initialClicksRight = counterRight.read(); |
ahlervin | 6:7bbcdd07bc2d | 94 | initialClicksLeft = counterLeft.read(); |
ahlervin | 6:7bbcdd07bc2d | 95 | |
ahlervin | 6:7bbcdd07bc2d | 96 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 6:7bbcdd07bc2d | 97 | wegRechts = 1773; |
ahlervin | 6:7bbcdd07bc2d | 98 | wegLinks = 1773; |
ahlervin | 6:7bbcdd07bc2d | 99 | |
ahlervin | 6:7bbcdd07bc2d | 100 | //Geschwindigkeit |
ahlervin | 6:7bbcdd07bc2d | 101 | //speedRight = 50;//SpeedR |
ahlervin | 6:7bbcdd07bc2d | 102 | //speedLeft = 50;//SpeedL |
ahlervin | 6:7bbcdd07bc2d | 103 | |
ahlervin | 6:7bbcdd07bc2d | 104 | //printf("SpeedR in F2= %f\n",SpeedR); |
ahlervin | 6:7bbcdd07bc2d | 105 | //printf("SpeedL in F2= %f\n",SpeedL); |
ahlervin | 6:7bbcdd07bc2d | 106 | |
ahlervin | 6:7bbcdd07bc2d | 107 | //Zustand, dass der Roboter nicht gestoppt hat |
ahlervin | 6:7bbcdd07bc2d | 108 | stopRight = false; |
ahlervin | 6:7bbcdd07bc2d | 109 | stopLeft = false; |
ahlervin | 6:7bbcdd07bc2d | 110 | |
ahlervin | 6:7bbcdd07bc2d | 111 | //Drehrichtung der Motoren |
ahlervin | 6:7bbcdd07bc2d | 112 | controller.setDesiredSpeedRight(SpeedR); |
ahlervin | 6:7bbcdd07bc2d | 113 | controller.setDesiredSpeedLeft(-(SpeedL)); |
Jacqueline | 0:6d0671ae4648 | 114 | |
Jacqueline | 0:6d0671ae4648 | 115 | |
ahlervin | 6:7bbcdd07bc2d | 116 | while(1){ |
ahlervin | 6:7bbcdd07bc2d | 117 | |
ahlervin | 6:7bbcdd07bc2d | 118 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 6:7bbcdd07bc2d | 119 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 6:7bbcdd07bc2d | 120 | |
ahlervin | 6:7bbcdd07bc2d | 121 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 6:7bbcdd07bc2d | 122 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
ahlervin | 6:7bbcdd07bc2d | 123 | controller.setDesiredSpeedRight(0); |
ahlervin | 6:7bbcdd07bc2d | 124 | stopRight = true; |
ahlervin | 6:7bbcdd07bc2d | 125 | } |
ahlervin | 6:7bbcdd07bc2d | 126 | |
ahlervin | 6:7bbcdd07bc2d | 127 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 6:7bbcdd07bc2d | 128 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
ahlervin | 6:7bbcdd07bc2d | 129 | controller.setDesiredSpeedLeft(0); |
ahlervin | 6:7bbcdd07bc2d | 130 | stopLeft = true; |
ahlervin | 6:7bbcdd07bc2d | 131 | } |
ahlervin | 6:7bbcdd07bc2d | 132 | |
ahlervin | 6:7bbcdd07bc2d | 133 | if(stopRight == true && stopLeft == true){ |
ahlervin | 6:7bbcdd07bc2d | 134 | return; |
ahlervin | 6:7bbcdd07bc2d | 135 | } |
ahlervin | 6:7bbcdd07bc2d | 136 | |
ahlervin | 6:7bbcdd07bc2d | 137 | } |
ahlervin | 6:7bbcdd07bc2d | 138 | |
ahlervin | 6:7bbcdd07bc2d | 139 | } |
ahlervin | 6:7bbcdd07bc2d | 140 | |
Jacqueline | 0:6d0671ae4648 | 141 | //Implementation der Methode 90 Grad Rechtsdrehen |
Jacqueline | 0:6d0671ae4648 | 142 | void Fahren::rechts90() { |
Jacqueline | 0:6d0671ae4648 | 143 | |
Jacqueline | 0:6d0671ae4648 | 144 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 145 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 146 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 147 | |
Jacqueline | 0:6d0671ae4648 | 148 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 6:7bbcdd07bc2d | 149 | wegRechts = 872; |
ahlervin | 6:7bbcdd07bc2d | 150 | wegLinks = 872; |
Jacqueline | 0:6d0671ae4648 | 151 | |
Jacqueline | 0:6d0671ae4648 | 152 | //Geschwindigkeit |
Jacqueline | 0:6d0671ae4648 | 153 | speedRight = 50; |
Jacqueline | 0:6d0671ae4648 | 154 | speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 155 | |
Jacqueline | 0:6d0671ae4648 | 156 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 157 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 158 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 159 | |
Jacqueline | 0:6d0671ae4648 | 160 | //Drehrichtung der Motoren |
Jacqueline | 0:6d0671ae4648 | 161 | controller.setDesiredSpeedRight((speedRight)); |
Jacqueline | 0:6d0671ae4648 | 162 | controller.setDesiredSpeedLeft((speedLeft)); |
Jacqueline | 0:6d0671ae4648 | 163 | |
Jacqueline | 0:6d0671ae4648 | 164 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 165 | |
Jacqueline | 0:6d0671ae4648 | 166 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 167 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 168 | |
Jacqueline | 0:6d0671ae4648 | 169 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 170 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 171 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 172 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 173 | } |
Jacqueline | 0:6d0671ae4648 | 174 | |
Jacqueline | 0:6d0671ae4648 | 175 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 176 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 177 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 178 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 179 | } |
Jacqueline | 0:6d0671ae4648 | 180 | |
Jacqueline | 0:6d0671ae4648 | 181 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 182 | return; |
Jacqueline | 0:6d0671ae4648 | 183 | } |
Jacqueline | 0:6d0671ae4648 | 184 | |
Jacqueline | 0:6d0671ae4648 | 185 | } |
Jacqueline | 0:6d0671ae4648 | 186 | |
Jacqueline | 0:6d0671ae4648 | 187 | } |
Jacqueline | 0:6d0671ae4648 | 188 | |
Jacqueline | 0:6d0671ae4648 | 189 | |
Jacqueline | 0:6d0671ae4648 | 190 | |
Jacqueline | 0:6d0671ae4648 | 191 | //Implementation der Methode 180 Grad Rechtsdrehen |
Jacqueline | 0:6d0671ae4648 | 192 | void Fahren::rechts180() { |
Jacqueline | 0:6d0671ae4648 | 193 | |
Jacqueline | 0:6d0671ae4648 | 194 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 195 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 196 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 197 | |
Jacqueline | 0:6d0671ae4648 | 198 | //Anzahl Clicks die der Encoder zählen soll |
Jacqueline | 0:6d0671ae4648 | 199 | wegRechts = 1755; |
Jacqueline | 0:6d0671ae4648 | 200 | wegLinks = 1755; |
Jacqueline | 0:6d0671ae4648 | 201 | |
Jacqueline | 0:6d0671ae4648 | 202 | //Geschwindigkeit |
Jacqueline | 0:6d0671ae4648 | 203 | speedRight = 50; |
Jacqueline | 0:6d0671ae4648 | 204 | speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 205 | |
Jacqueline | 0:6d0671ae4648 | 206 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 207 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 208 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 209 | |
Jacqueline | 0:6d0671ae4648 | 210 | //Drehrichtung der Motoren |
Jacqueline | 0:6d0671ae4648 | 211 | controller.setDesiredSpeedRight((speedRight)); |
Jacqueline | 0:6d0671ae4648 | 212 | controller.setDesiredSpeedLeft((speedLeft)); |
Jacqueline | 0:6d0671ae4648 | 213 | |
Jacqueline | 0:6d0671ae4648 | 214 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 215 | |
Jacqueline | 0:6d0671ae4648 | 216 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 217 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 218 | |
Jacqueline | 0:6d0671ae4648 | 219 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 220 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 221 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 222 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 223 | } |
Jacqueline | 0:6d0671ae4648 | 224 | |
Jacqueline | 0:6d0671ae4648 | 225 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 226 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 227 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 228 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 229 | } |
Jacqueline | 0:6d0671ae4648 | 230 | |
Jacqueline | 0:6d0671ae4648 | 231 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 232 | return; |
Jacqueline | 0:6d0671ae4648 | 233 | } |
Jacqueline | 0:6d0671ae4648 | 234 | |
Jacqueline | 0:6d0671ae4648 | 235 | } |
Jacqueline | 0:6d0671ae4648 | 236 | |
Jacqueline | 0:6d0671ae4648 | 237 | } |
Jacqueline | 0:6d0671ae4648 | 238 | |
Jacqueline | 0:6d0671ae4648 | 239 | |
Jacqueline | 2:402b1a74fff6 | 240 | //Implementation der Methode 90 Grad Linksdrehen |
Jacqueline | 2:402b1a74fff6 | 241 | void Fahren::links90() { |
Jacqueline | 0:6d0671ae4648 | 242 | |
Jacqueline | 0:6d0671ae4648 | 243 | //einlesen des aktuellen Encoder standes |
Jacqueline | 0:6d0671ae4648 | 244 | initialClicksRight = counterRight.read(); |
Jacqueline | 0:6d0671ae4648 | 245 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 246 | |
Jacqueline | 0:6d0671ae4648 | 247 | //Anzahl Clicks die der Encoder zählen soll |
Jacqueline | 2:402b1a74fff6 | 248 | wegRechts = 878; |
Jacqueline | 2:402b1a74fff6 | 249 | wegLinks = 878; |
Jacqueline | 0:6d0671ae4648 | 250 | |
Jacqueline | 0:6d0671ae4648 | 251 | //Geschwindigkeit |
Jacqueline | 0:6d0671ae4648 | 252 | speedRight = 50; |
Jacqueline | 0:6d0671ae4648 | 253 | speedLeft = 50; |
Jacqueline | 0:6d0671ae4648 | 254 | |
Jacqueline | 0:6d0671ae4648 | 255 | //Zustand, dass der Roboter nicht gestoppt hat |
Jacqueline | 0:6d0671ae4648 | 256 | stopRight = false; |
Jacqueline | 0:6d0671ae4648 | 257 | stopLeft = false; |
Jacqueline | 0:6d0671ae4648 | 258 | |
Jacqueline | 0:6d0671ae4648 | 259 | //Drehrichtung der Motoren |
Jacqueline | 2:402b1a74fff6 | 260 | controller.setDesiredSpeedRight((-speedRight)); |
Jacqueline | 2:402b1a74fff6 | 261 | controller.setDesiredSpeedLeft((-speedLeft)); |
Jacqueline | 0:6d0671ae4648 | 262 | |
Jacqueline | 0:6d0671ae4648 | 263 | while(1){ |
Jacqueline | 0:6d0671ae4648 | 264 | |
Jacqueline | 0:6d0671ae4648 | 265 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 266 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
Jacqueline | 0:6d0671ae4648 | 267 | |
Jacqueline | 0:6d0671ae4648 | 268 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 269 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
Jacqueline | 0:6d0671ae4648 | 270 | controller.setDesiredSpeedRight(0); |
Jacqueline | 0:6d0671ae4648 | 271 | stopRight = true; |
Jacqueline | 0:6d0671ae4648 | 272 | } |
Jacqueline | 0:6d0671ae4648 | 273 | |
Jacqueline | 0:6d0671ae4648 | 274 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
Jacqueline | 0:6d0671ae4648 | 275 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
Jacqueline | 0:6d0671ae4648 | 276 | controller.setDesiredSpeedLeft(0); |
Jacqueline | 0:6d0671ae4648 | 277 | stopLeft = true; |
Jacqueline | 0:6d0671ae4648 | 278 | } |
Jacqueline | 0:6d0671ae4648 | 279 | |
Jacqueline | 0:6d0671ae4648 | 280 | if(stopRight == true && stopLeft == true){ |
Jacqueline | 0:6d0671ae4648 | 281 | return; |
Jacqueline | 0:6d0671ae4648 | 282 | } |
Jacqueline | 0:6d0671ae4648 | 283 | |
Jacqueline | 0:6d0671ae4648 | 284 | } |
Jacqueline | 0:6d0671ae4648 | 285 | |
Jacqueline | 0:6d0671ae4648 | 286 | } |
Jacqueline | 0:6d0671ae4648 | 287 | |
ahlervin | 4:767fd282dd9c | 288 | |
ahlervin | 4:767fd282dd9c | 289 | //Implementation der Methode Ziel erreicht |
ahlervin | 4:767fd282dd9c | 290 | void Fahren::ziel() { |
ahlervin | 4:767fd282dd9c | 291 | |
ahlervin | 4:767fd282dd9c | 292 | //einlesen des aktuellen Encoder standes |
ahlervin | 4:767fd282dd9c | 293 | initialClicksRight = counterRight.read(); |
ahlervin | 4:767fd282dd9c | 294 | initialClicksLeft = counterLeft.read(); |
Jacqueline | 0:6d0671ae4648 | 295 | |
ahlervin | 4:767fd282dd9c | 296 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 4:767fd282dd9c | 297 | wegRechts = 7050; |
ahlervin | 4:767fd282dd9c | 298 | wegLinks = 7050; |
ahlervin | 4:767fd282dd9c | 299 | |
ahlervin | 4:767fd282dd9c | 300 | //Geschwindigkeit |
ahlervin | 4:767fd282dd9c | 301 | speedRight = 80; |
ahlervin | 4:767fd282dd9c | 302 | speedLeft = 80; |
ahlervin | 4:767fd282dd9c | 303 | |
ahlervin | 4:767fd282dd9c | 304 | //Zustand, dass der Roboter nicht gestoppt hat |
ahlervin | 4:767fd282dd9c | 305 | stopRight = false; |
ahlervin | 4:767fd282dd9c | 306 | stopLeft = false; |
ahlervin | 4:767fd282dd9c | 307 | |
ahlervin | 4:767fd282dd9c | 308 | //Drehrichtung der Motoren |
ahlervin | 4:767fd282dd9c | 309 | controller.setDesiredSpeedRight((speedRight)); |
ahlervin | 4:767fd282dd9c | 310 | controller.setDesiredSpeedLeft((speedLeft)); |
ahlervin | 4:767fd282dd9c | 311 | |
ahlervin | 4:767fd282dd9c | 312 | while(1){ |
ahlervin | 4:767fd282dd9c | 313 | |
ahlervin | 4:767fd282dd9c | 314 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 315 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 316 | |
ahlervin | 4:767fd282dd9c | 317 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 318 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
ahlervin | 4:767fd282dd9c | 319 | controller.setDesiredSpeedRight(0); |
ahlervin | 4:767fd282dd9c | 320 | stopRight = true; |
ahlervin | 4:767fd282dd9c | 321 | } |
ahlervin | 4:767fd282dd9c | 322 | |
ahlervin | 4:767fd282dd9c | 323 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 324 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
ahlervin | 4:767fd282dd9c | 325 | controller.setDesiredSpeedLeft(0); |
ahlervin | 4:767fd282dd9c | 326 | stopLeft = true; |
ahlervin | 4:767fd282dd9c | 327 | } |
ahlervin | 4:767fd282dd9c | 328 | |
ahlervin | 4:767fd282dd9c | 329 | if(stopRight == true && stopLeft == true){ |
ahlervin | 4:767fd282dd9c | 330 | return; |
ahlervin | 4:767fd282dd9c | 331 | } |
ahlervin | 4:767fd282dd9c | 332 | } |
ahlervin | 4:767fd282dd9c | 333 | |
ahlervin | 4:767fd282dd9c | 334 | } |
Jacqueline | 0:6d0671ae4648 | 335 | |
ahlervin | 4:767fd282dd9c | 336 | //Implementation der Methode stopp |
ahlervin | 4:767fd282dd9c | 337 | void Fahren::stopp(){ |
ahlervin | 4:767fd282dd9c | 338 | |
ahlervin | 4:767fd282dd9c | 339 | //einlesen des aktuellen Encoder standes |
ahlervin | 4:767fd282dd9c | 340 | initialClicksRight = counterRight.read(); |
ahlervin | 4:767fd282dd9c | 341 | initialClicksLeft = counterLeft.read(); |
ahlervin | 4:767fd282dd9c | 342 | |
ahlervin | 4:767fd282dd9c | 343 | //Anzahl Clicks die der Encoder zählen soll |
ahlervin | 4:767fd282dd9c | 344 | wegRechts = 0; |
ahlervin | 4:767fd282dd9c | 345 | wegLinks = 0; |
ahlervin | 4:767fd282dd9c | 346 | |
ahlervin | 4:767fd282dd9c | 347 | //Geschwindigkeit |
ahlervin | 4:767fd282dd9c | 348 | speedRight = 0; |
ahlervin | 4:767fd282dd9c | 349 | speedLeft = 0; |
ahlervin | 4:767fd282dd9c | 350 | |
ahlervin | 4:767fd282dd9c | 351 | //Zustand, dass der Roboter nicht gestoppt hat |
ahlervin | 4:767fd282dd9c | 352 | stopRight = false; |
ahlervin | 4:767fd282dd9c | 353 | stopLeft = false; |
ahlervin | 4:767fd282dd9c | 354 | |
ahlervin | 4:767fd282dd9c | 355 | //Drehrichtung der Motoren |
ahlervin | 4:767fd282dd9c | 356 | controller.setDesiredSpeedRight(speedRight); |
ahlervin | 4:767fd282dd9c | 357 | controller.setDesiredSpeedLeft(-(speedLeft)); |
ahlervin | 4:767fd282dd9c | 358 | |
ahlervin | 4:767fd282dd9c | 359 | |
ahlervin | 4:767fd282dd9c | 360 | while(1){ |
ahlervin | 4:767fd282dd9c | 361 | |
ahlervin | 4:767fd282dd9c | 362 | // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 363 | // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!) |
ahlervin | 4:767fd282dd9c | 364 | |
ahlervin | 4:767fd282dd9c | 365 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 366 | if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){ |
ahlervin | 4:767fd282dd9c | 367 | controller.setDesiredSpeedRight(0); |
ahlervin | 4:767fd282dd9c | 368 | stopRight = true; |
ahlervin | 4:767fd282dd9c | 369 | } |
ahlervin | 4:767fd282dd9c | 370 | |
ahlervin | 4:767fd282dd9c | 371 | //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen |
ahlervin | 4:767fd282dd9c | 372 | if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){ |
ahlervin | 4:767fd282dd9c | 373 | controller.setDesiredSpeedLeft(0); |
ahlervin | 4:767fd282dd9c | 374 | stopLeft = true; |
ahlervin | 4:767fd282dd9c | 375 | } |
ahlervin | 4:767fd282dd9c | 376 | |
ahlervin | 4:767fd282dd9c | 377 | if(stopRight == true && stopLeft == true){ |
ahlervin | 4:767fd282dd9c | 378 | return; |
ahlervin | 4:767fd282dd9c | 379 | } |
ahlervin | 4:767fd282dd9c | 380 | |
ahlervin | 4:767fd282dd9c | 381 | } |
ahlervin | 4:767fd282dd9c | 382 | |
ahlervin | 4:767fd282dd9c | 383 | } |