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
Diff: Fahren.cpp
- Revision:
- 6:7bbcdd07bc2d
- Parent:
- 4:767fd282dd9c
- Child:
- 7:862d80e0ea2d
--- a/Fahren.cpp Thu Apr 26 05:58:07 2018 +0000 +++ b/Fahren.cpp Thu May 03 19:36:16 2018 +0000 @@ -1,31 +1,56 @@ +/*Roboshark V4 +Fahren.cpp +Erstellt: J. Blunschi +geändert: V.Ahlers +V.5.18 +*/ + #include "Fahren.h" #include <mbed.h> +#include "Regler.h" +using namespace std; + +const float Fahren :: PERIOD = 0.2f; + //Konstruktor -Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight): - controller(controller), counterLeft(counterLeft), counterRight(counterRight) +Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler): + controller(controller), counterLeft(counterLeft), counterRight(counterRight), regler(regler){ -{} + SpeedR = 50; + SpeedL = 50; + ticker.attach(callback(this, &Fahren::getSpeed), PERIOD); +} + //Dekonstruktor -Fahren::~Fahren() {} - +Fahren::~Fahren() { + ticker.detach(); + } +//Korrigierte Geschwindigkeit aus der Klasse Regler aufrufen +void Fahren::getSpeed(){ + SpeedR = regler.get_SpeedR(); + SpeedL = regler.get_SpeedL(); + + //printf("SpeedR in F = %f\n",SpeedR); + //printf("SpeedL in F = %f\n",SpeedL); +} - -//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(); initialClicksLeft = counterLeft.read(); //Anzahl Clicks die der Encoder zählen soll - wegRechts = 1767; - wegLinks = 1767; + wegRechts = 1773; + wegLinks = 1773; //Geschwindigkeit - speedRight = 25; - speedLeft = 25; + speedRight = 50; + speedLeft = 50; //Zustand, dass der Roboter nicht gestoppt hat stopRight = false; @@ -61,8 +86,58 @@ } +//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 = 1773; + wegLinks = 1773; + + //Geschwindigkeit + //speedRight = 50;//SpeedR + //speedLeft = 50;//SpeedL + + //printf("SpeedR in F2= %f\n",SpeedR); + //printf("SpeedL in F2= %f\n",SpeedL); + + //Zustand, dass der Roboter nicht gestoppt hat + stopRight = false; + stopLeft = false; + + //Drehrichtung der Motoren + controller.setDesiredSpeedRight(SpeedR); + controller.setDesiredSpeedLeft(-(SpeedL)); + 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() { @@ -71,8 +146,8 @@ initialClicksLeft = counterLeft.read(); //Anzahl Clicks die der Encoder zählen soll - wegRechts = 878; - wegLinks = 878; + wegRechts = 872; + wegLinks = 872; //Geschwindigkeit speedRight = 50;