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_V3 by
Diff: main.cpp
- Revision:
- 6:a4b745625dbe
- Parent:
- 4:767fd282dd9c
- Child:
- 7:b2a16b1cf487
diff -r e715d157ced5 -r a4b745625dbe main.cpp
--- a/main.cpp Thu Apr 26 05:58:07 2018 +0000
+++ b/main.cpp Mon Apr 30 13:22:32 2018 +0000
@@ -5,7 +5,7 @@
#include "Controller.h"
#include "IRSensor.h"
#include "Fahren.h"
-#include "StateMachine.h"
+#include "Regler.h"
DigitalOut myled(LED1);
@@ -22,13 +22,6 @@
DigitalOut bit1(PC_2);
DigitalOut bit2(PC_3);
-/*IRSensor irSensor0(distance, bit0, bit1, bit2, 0);
-IRSensor irSensor1(distance, bit0, bit1, bit2, 1);
-IRSensor irSensor2(distance, bit0, bit1, bit2, 2);
-IRSensor irSensor3(distance, bit0, bit1, bit2, 3);
-IRSensor irSensor4(distance, bit0, bit1, bit2, 4);
-IRSensor irSensor5(distance, bit0, bit1, bit2, 5);*/
-
AnalogIn IrRight(PC_3); //von main Vincent kopiert
AnalogIn IrLeft (PC_5);
AnalogIn IrFront(PC_2);
@@ -47,12 +40,10 @@
bool finish = 0;
bool finishLast = 0;
int ende = 0;
-int temp = 0; //von main Vincent kopiert
-
-IRSensor iRSensor(IrRight, IrLeft, IrFront, dis2R, dis2L, dis2F, LineSensor);
-//IRSensor bottom (IrRight, IrLeft, IrFront, dis2R, dis2L, dis2F, LineSensor); //von main Vincent kopiert
-StateMachine stateMachine(IrR, IrL, IrF); //von main Vincent kopiert
-
+int temp = 0;
+float SpeedR = 0;
+float SpeedL = 0;
+ //von main Vincent kopiert
DigitalOut enableMotorDriver(PB_2);
DigitalIn motorDriverFault(PB_14);
@@ -64,9 +55,13 @@
EncoderCounter counterLeft(PB_6, PB_7);
EncoderCounter counterRight(PA_6, PC_7);
+IRSensor iRSensor(IrRight, IrLeft, IrFront, dis2R, dis2L, dis2F, LineSensor); //von main Vincent kopiert
+
Controller controller(pwmLeft, pwmRight, counterLeft, counterRight);
-Fahren fahren(controller, counterLeft, counterRight); //Reihenfolge!!!!!!!!!!!!!!!!!!! Ultra wichtig
+Regler regler(IrRight, IrLeft);
+
+Fahren fahren(controller, counterLeft, counterRight, SpeedR, SpeedL); //Reihenfolge!!!!!!!!!!!!!!!!!!! Ultra wichtig
int main()
{
@@ -101,8 +96,10 @@
int IrR = iRSensor.codeR(); // min Distanz unterschritten = 1
int IrL = iRSensor.codeL();
int IrF = iRSensor.codeF();
- /*int caseDrive = stateMachine.drive();*/ //entscheidung welcher Drive Case
ende = iRSensor.get_ende();
+ SpeedR = regler.get_SpeedR();
+ SpeedL = regler.get_SpeedL();
+
@@ -111,32 +108,17 @@
printf (" finishLast = %d\n",finishLast);
printf("line = %f\n", line);
- /* printf ("IR Right = %d \n", IrR);
+ printf ("IR Right = %d \n", IrR);
printf("IR Left = %d\n",IrL);
printf("IR Front = %d\n",IrF);*/
- if((IrR==0) && (IrL==0) && (IrF==1) && (ende == 0)){
- caseDrive = 2; // Folge: 90 Grad nach rechts drehen
- } else if ((IrR==0) && (IrL==1) && (IrF==0) && (ende == 0)){
- caseDrive = 2; // Folge: 90 Grad nach rechts drehen
- } else if ((IrR==0) && (IrL==1) && (IrF==1) && (ende == 0)){
- caseDrive = 2; // Folge: 90 Grad nach rechts drehen
- } else if ((IrR==1) && (IrL==0) && (IrF==0) && (ende == 0)){
- caseDrive = 1; // Folge: geradeaus fahren
- } else if ((IrR==1) && (IrL==0) && (IrF==1) && (ende == 0)){
- caseDrive = 3; // Folge: 270 Grad nach rechts drehen
+
+ if ((IrR==1) && (IrL==0) && (IrF==0) && (ende == 0)){
+ caseDrive = 1;
} else if ((IrR==1) && (IrL==1) && (IrF==0) && (ende == 0)){
- caseDrive = 1; // Folge: geradeaus fahren
- } else if ((IrR==1) && (IrL==1) && (IrF==1) && (ende == 0)){
- caseDrive = 4; // Folge: 180 Grad nach rechts drehen
- } else if ((ende == 1) && (temp == 0)){
- caseDrive = 5;
- temp = 1;
- } else {caseDrive = 0;
+ caseDrive = 1;
+ } else{ caseDrive = 0;
}
-
- printf("caseDrive = %d\n",caseDrive);
- printf("ende = %d\n",ende);
wait (0.5);
@@ -144,21 +126,11 @@
if(caseDrive == 1){
- fahren.geradeaus();
- } else if (caseDrive == 2){
- fahren.rechts90();
- fahren.geradeaus();
- } else if (caseDrive == 3){
- fahren.links90();
- fahren.geradeaus();
- } else if (caseDrive == 4){
- fahren.rechts180();
- fahren.geradeaus();
+ fahren.geradeausG();
} else if (caseDrive == 0){
fahren.stopp();
- } else if(caseDrive == 5){
- fahren.ziel();
- fahren.stopp();
+
}
- }
}
+
+}
