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_V7 by
Diff: Fahren.cpp
- Revision:
- 9:feabe0b7cea4
- Parent:
- 8:d0a27278c108
- Child:
- 10:fb2195d0de0f
--- a/Fahren.cpp Mon May 07 14:11:06 2018 +0000
+++ b/Fahren.cpp Mon May 07 15:41:52 2018 +0000
@@ -1,4 +1,4 @@
-/*Roboshark V6
+/*Roboshark V7
Fahren.cpp
Erstellt: J. Blunschi
geändert: V.Ahlers
@@ -7,94 +7,25 @@
#include "Fahren.h"
#include <mbed.h>
-#include "Regler.h"
+#include "IRSensor.h"
using namespace std;
-const float Fahren :: PERIOD = 0.2f;
-
-//Konstruktor
-Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler, int reglerEin, IRSensor& iRSensor):
- controller(controller), counterLeft(counterLeft), counterRight(counterRight), regler(regler), reglerEin(reglerEin), iRSensor (iRSensor){
-
- SpeedR = 80;
- SpeedL = 80;
- disF = 0;
- ticker.attach(callback(this, &Fahren::getSpeed), PERIOD);
-}
-
-//Dekonstruktor
-Fahren::~Fahren() {
- ticker.detach();
- }
-
-
-//Korrigierte Geschwindigkeit aus der Klasse Regler aufrufen
-void Fahren::getSpeed(){
- //if((reglerEinR == 1) && (reglerEinL == 1)){
- //SpeedR = regler.getSpeedR();
- //SpeedL = regler.getSpeedL();
- SpeedR = 80;
- SpeedL = 80;
-
- //disF = iRSensor.readF();
-
- //printf("SpeedR in F = %f\n",SpeedR);
- //printf("SpeedL in F = %f\n",SpeedL);
-}
-//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 = 1773;
- wegLinks = 1773;
-
- //Geschwindigkeit
- //speedRight = 50;
- //speedLeft = 50;
-
- //Zustand, dass der Roboter nicht gestoppt hat
- stopRight = false;
- stopLeft = false;
-
-
- //Drehrichtung der Motoren
- controller.setDesiredSpeedRight(SpeedR);
- controller.setDesiredSpeedLeft(-(SpeedL));
-
+//Konstruktor
+Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, IRSensor& iRSensor):
+ controller(controller), counterLeft(counterLeft), counterRight(counterRight), iRSensor (iRSensor){
+SpeedR = 80.0f;
+SpeedL = 80.0f;
+disF = 0.0f;
+}
+//Dekonstruktor
+Fahren::~Fahren() {}
- 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 geradeaus fahren geregelt
void Fahren::geradeausG(){
@@ -105,11 +36,6 @@
//Anzahl Clicks die der Encoder zählen soll
wegRechts = 1776;
wegLinks = 1776;
-
- //Geschwindigkeit
- //speedRight = 50;//SpeedR
- //speedLeft = 50;//SpeedL
-
//Zustand, dass der Roboter nicht gestoppt hat
@@ -118,14 +44,9 @@
reglerEinR = 1;
reglerEinL = 1;
- //Drehrichtung der Motoren
-
- //printf("SpeedR in F2= %f\n",SpeedR);
- //printf("SpeedL in F2= %f\n",SpeedL);
-
while(1){
- float diff = (iRSensor.readR() - iRSensor.readL())*0.9f;
- if(diff > 7.0f) diff = 0;
+ float diff = (iRSensor.readR() - iRSensor.readL())*0.9f; //Regler
+ if((diff < 1.5f) ||(diff > -1.5f)) diff = 0;
if(iRSensor.readR()>60.0f) diff=0;
if(iRSensor.readL()>60.0f) diff=0;
//printf("diff =%f \n",diff);
@@ -170,10 +91,6 @@
wegRechts = 868;
wegLinks = 868;
- //Geschwindigkeit
- //speedRight = 50;
- //speedLeft = 50;
-
//Zustand, dass der Roboter nicht gestoppt hat
stopRight = false;
stopLeft = false;
@@ -221,10 +138,6 @@
wegRechts = 1752;
wegLinks = 1752;
- //Geschwindigkeit
- //speedRight = 50;
- //speedLeft = 50;
-
//Zustand, dass der Roboter nicht gestoppt hat
stopRight = false;
stopLeft = false;
@@ -270,10 +183,6 @@
wegRechts = 868;
wegLinks = 868;
- //Geschwindigkeit
- //speedRight = 50;
- //speedLeft = 50;
-
//Zustand, dass der Roboter nicht gestoppt hat
stopRight = false;
stopLeft = false;
@@ -319,10 +228,6 @@
wegRechts = 7050;
wegLinks = 7050;
- //Geschwindigkeit
- //speedRight = 80;
- //speedLeft = 80;
-
//Zustand, dass der Roboter nicht gestoppt hat
stopRight = false;
stopLeft = false;
