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 TestRegler by
Diff: Fahren.cpp
- Revision:
- 6:a4b745625dbe
- Parent:
- 4:767fd282dd9c
- Child:
- 7:b2a16b1cf487
--- a/Fahren.cpp Thu Apr 26 05:58:07 2018 +0000
+++ b/Fahren.cpp Mon Apr 30 13:22:32 2018 +0000
@@ -3,8 +3,8 @@
//Konstruktor
-Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight):
- controller(controller), counterLeft(counterLeft), counterRight(counterRight)
+Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, float SpeedR, float SpeedL):
+ controller(controller), counterLeft(counterLeft), counterRight(counterRight), SpeedR(SpeedR), SpeedL(SpeedL)
{}
//Dekonstruktor
@@ -12,8 +12,8 @@
-//Implementation der Methode geradeaus fahren
-void Fahren::geradeaus(){
+//Implementation der Methode geradeaus fahren ungeregelt
+void Fahren::geradeausU(){
//einlesen des aktuellen Encoder standes
initialClicksRight = counterRight.read();
@@ -61,7 +61,55 @@
}
+//Implementation der Methode geradeaus fahren geregelt
+void Fahren::geradeausG(){
+ //einlesen des aktuellen Encoder standes
+ initialClicksRight = counterRight.read();
+ initialClicksLeft = counterLeft.read();
+
+ //Anzahl Clicks die der Encoder zählen soll
+ wegRechts = 1767;
+ wegLinks = 1767;
+
+ //Geschwindigkeit
+ speedRight = SpeedR; // SpeedR
+ speedLeft = SpeedL; // SpeedL
+
+ //Zustand, dass der Roboter nicht gestoppt hat
+ stopRight = false;
+ stopLeft = false;
+
+ //Drehrichtung der Motoren
+ controller.setDesiredSpeedRight(speedRight);
+ controller.setDesiredSpeedLeft(-(speedLeft));
+
+
+ while(1){
+
+ // printf("Encoderrechts %d \n\r", counterRight.read()); //Debugging Zweck (Putty benutzen!)
+ // printf("Encoderlinks %d \n\r", counterLeft.read()); //Debugging Zweck (Putty benutzen!)
+
+ //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen
+ if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){
+ controller.setDesiredSpeedRight(0);
+ stopRight = true;
+ }
+
+ //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen
+ if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks ){
+ controller.setDesiredSpeedLeft(0);
+ stopLeft = true;
+ }
+
+ if(stopRight == true && stopLeft == true){
+ return;
+ }
+
+ }
+
+ }
+
//Implementation der Methode 90 Grad Rechtsdrehen
void Fahren::rechts90() {
