Helvijs Kiselis
/
MicromousePES2
main.cpp: Sensoren einlesen und Motoren ansteuern
Diff: main.cpp
- Revision:
- 4:e74c06e43485
- Parent:
- 3:c0f40a94fffa
- Child:
- 5:47262622a9bf
--- a/main.cpp Tue Apr 10 14:31:50 2018 +0000 +++ b/main.cpp Wed Apr 11 15:26:03 2018 +0000 @@ -5,6 +5,7 @@ #include "IRSensor.h" #include "Motion.h" + Serial pc (SERIAL_TX, SERIAL_RX); //User Button DigitalIn button(PC_13); @@ -28,27 +29,34 @@ DigitalIn motorDriverWarning(PB_15); PwmOut pwmLeft(PA_8); - PwmOut pwmRight(PA_9); + PwmOut pwmRight(PA_10); EncoderCounter counterLeft(PB_6, PB_7); - EncoderCounter counterRight(PA_6, PC_7); + EncoderCounter counterRight(PA_1, PA_0); Controller controller(pwmLeft, pwmRight, counterLeft, counterRight); Motion motion(controller, counterLeft, counterRight, irSensorL, irSensorC, irSensorR); + + int start = 0; + short countsLeft = 0; + short countsRight = 0; + +//------------------------------------------------------------------------------ int main() { -/** Micromouse Test - - für den jeweiligen Test 0 im while Argument auf 1 setzen +/** + Micromouse Test */ + //den jeweiligen Test auf 1 setzen + int testSensor = 0; + int testMotion = 0; + int testRotation = 0; + int testCounts = 0; + //User Button einlesen: start Signal - int start; - short countsLeft = 0; - short countsRight = 0; - if (button.read() && start != 1) start = 1; else if(button.read() && start == 1) start = 0; @@ -56,12 +64,13 @@ /* Sensoren Test */ - while(start && 1) { + while(1) { + float distanceL = irSensorL.read(); float distanceC = irSensorC.read(); float distanceR = irSensorR.read(); - printf("Rechts: %f Mitte: %f Links: %f\n", distanceL, distanceC, distanceR); + pc.printf("Rechts: %f Mitte: %f Links: %f\n", distanceL, distanceC, distanceR); wait(0.5f); } @@ -69,10 +78,10 @@ /* Motoren Test: Gerade Bewegung */ - while(start && 0) { + while(0) { controller.setDesiredSpeedLeft(50.0f); //Drehzahl in [rpm] - controller.setDesiredSpeedRight(50.0f); + controller.setDesiredSpeedRight(-50.0f); enableMotorDriver = 1; //Schaltet den Leistungstreiber ein while(1) { @@ -89,7 +98,7 @@ Motoren Test: 180° Rotation */ - while(start && 0) { + while(start && testRotation) { while(countsLeft < 200 || countsRight > -200) { @@ -103,6 +112,7 @@ controller.setDesiredSpeedLeft(0.0f); controller.setDesiredSpeedRight(0.0f); + enableMotorDriver = 0; } @@ -118,20 +128,21 @@ Counts = Rd/mm pro Count => Counts pro Drehung rausfinden */ - while(start && 0) { + while(start && testCounts) { while(countsLeft < 100 || countsRight < 100) { countsLeft = counterLeft.read(); countsRight = counterRight.read(); - controller.setDesiredSpeedLeft(50.0f); - controller.setDesiredSpeedRight(50.0f); + controller.setDesiredSpeedLeft(20.0f); + controller.setDesiredSpeedRight(20.0f); enableMotorDriver = 1; } controller.setDesiredSpeedLeft(0.0f); controller.setDesiredSpeedRight(0.0f); + enableMotorDriver = 0; } }