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
Fahren.cpp
- Committer:
- ahlervin
- Date:
- 2018-04-24
- Revision:
- 4:767fd282dd9c
- Parent:
- 3:e4264cb5b9a9
- Child:
- 6:7bbcdd07bc2d
File content as of revision 4:767fd282dd9c:
#include "Fahren.h"
#include <mbed.h>
//Konstruktor
Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight):
controller(controller), counterLeft(counterLeft), counterRight(counterRight)
{}
//Dekonstruktor
Fahren::~Fahren() {}
//Implementation der Methode geradeaus fahren
void Fahren::geradeaus(){
//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 = 25;
speedLeft = 25;
//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() {
//einlesen des aktuellen Encoder standes
initialClicksRight = counterRight.read();
initialClicksLeft = counterLeft.read();
//Anzahl Clicks die der Encoder zählen soll
wegRechts = 878;
wegLinks = 878;
//Geschwindigkeit
speedRight = 50;
speedLeft = 50;
//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 180 Grad Rechtsdrehen
void Fahren::rechts180() {
//einlesen des aktuellen Encoder standes
initialClicksRight = counterRight.read();
initialClicksLeft = counterLeft.read();
//Anzahl Clicks die der Encoder zählen soll
wegRechts = 1755;
wegLinks = 1755;
//Geschwindigkeit
speedRight = 50;
speedLeft = 50;
//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 Linksdrehen
void Fahren::links90() {
//einlesen des aktuellen Encoder standes
initialClicksRight = counterRight.read();
initialClicksLeft = counterLeft.read();
//Anzahl Clicks die der Encoder zählen soll
wegRechts = 878;
wegLinks = 878;
//Geschwindigkeit
speedRight = 50;
speedLeft = 50;
//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 Ziel erreicht
void Fahren::ziel() {
//einlesen des aktuellen Encoder standes
initialClicksRight = counterRight.read();
initialClicksLeft = counterLeft.read();
//Anzahl Clicks die der Encoder zählen soll
wegRechts = 7050;
wegLinks = 7050;
//Geschwindigkeit
speedRight = 80;
speedLeft = 80;
//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 stopp
void Fahren::stopp(){
//einlesen des aktuellen Encoder standes
initialClicksRight = counterRight.read();
initialClicksLeft = counterLeft.read();
//Anzahl Clicks die der Encoder zählen soll
wegRechts = 0;
wegLinks = 0;
//Geschwindigkeit
speedRight = 0;
speedLeft = 0;
//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;
}
}
}
