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 ROME2_P1_Fertig by
Diff: main.cpp
- Revision:
- 2:ff4efefe7a1f
- Parent:
- 1:b87369992345
- Child:
- 3:86f7471eaa79
--- a/main.cpp Fri Feb 23 14:07:21 2018 +0000
+++ b/main.cpp Fri Feb 23 14:52:13 2018 +0000
@@ -1,5 +1,6 @@
#include "mbed.h"
#include "IRSensor.h"
+#include "Controller.h"
// LEDs
DigitalOut myled(LED1);
@@ -24,6 +25,10 @@
PwmOut pwmLeft(PA_8);
PwmOut pwmRight(PA_9);
+// Motoren Drehzahlgeber
+EncoderCounter counterLeft(PB_6, PB_7);
+EncoderCounter counterRight(PA_6, PC_7);
+
float d = 0;
IRSensor irSensor0(distance, bit0, bit1, bit2, 0); // Objekte kreieren
@@ -33,11 +38,23 @@
IRSensor irSensor4(distance, bit0, bit1, bit2, 4);
IRSensor irSensor5(distance, bit0, bit1, bit2, 5);
+Controller controller(pwmLeft, pwmRight, counterLeft, counterRight);
+
int main()
{
enable = 1; // schaltet die Sensoren ein
+
+ // MOTOR
+
+ pwmLeft.period(0.00005); // Setzt die Periode auf 50 μs
+ pwmRight.period(0.00005);
+ pwmLeft = 0.5; // Setzt die Duty-Cycle auf 50%
+ pwmRight = 0.5;
+ enableMotorDriver = 1; // Schaltet den Leistungstreiber ein
+
+
/*
bit0 = 0; // Wahl des Sensors mit dem Multiplexer (Sensor vorne)
bit1 = 0;
@@ -81,6 +98,17 @@
d = -0.58f*sqrt(distance)+0.58f; // Lesen der Distanz in [m]
printf("Mein Wert: %f\n",d);
*/
+
+ // Motoren drehen primitiv
+ //pwmLeft = 0.55; // Duty-Cycle von 55%
+ //pwmRight = 0.55;
+
+ // Motoren per Drehzahlregler
+ controller.setDesiredSpeedLeft(50.0f); // Drehzahl in [rpm]
+ controller.setDesiredSpeedRight(-50.0f);
+
+ // Ausgabe für Putty
+ printf("Speed aktuell links: %f, rechts: %f \r\n",controller.getSpeedLeft(),controller.getSpeedRight());
float distance0 = irSensor0.read(); // gibt die Distanz in [m] zurueck
@@ -89,19 +117,19 @@
float distance3 = irSensor3.read();
float distance4 = irSensor4.read();
float distance5 = irSensor5.read();
-
+
led0 = 0;
led1 = 0;
led2 = 0;
led3 = 0;
led4 = 0;
led5 = 0;
-
-
+
+
if(distance0 < 0.2f) {
led0 = 1;
- }
+ }
if(distance1 < 0.2f) {
led1 = 1;
}
@@ -117,7 +145,7 @@
if(distance5 < 0.2f) {
led5 = 1;
}
-
+
}
}
