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: FastPWM HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 4:c73ced5d5754
- Parent:
- 3:7421e53bf9bd
- Child:
- 5:9827fabbc692
diff -r 7421e53bf9bd -r c73ced5d5754 main.cpp
--- a/main.cpp Tue Sep 25 12:26:08 2018 +0000
+++ b/main.cpp Tue Sep 25 14:02:15 2018 +0000
@@ -21,15 +21,15 @@
// Voor het laten zien van de data op de pc.
HIDScope scope(2); // Aantal kanalen wat doorgegeven wordt aan de hidscope
Ticker AInTicker;
+float U1;
+float U2;
float potwaarde1;
float potwaarde2;
void ReadAnalogIn()
{
- potwaarde1 = potwaarde1*2 -1; // Scale van -1 tot 1 ipv. 0 tot 1
- potwaarde2 = potwaarde2*2 -1;
- scope.set(0,potwaarde1); // Zet de potwaarde in de eerste plot bij de HID scope. Deze wordt automatisch tegen de tijd geplot
- scope.set(1,potwaarde2);
+ scope.set(0,U1); // Zet de potwaarde in de eerste plot bij de HID scope. Deze wordt automatisch tegen de tijd geplot
+ scope.set(1,U2);
scope.send(); // Zendt de waardes naar de pc
}
@@ -39,9 +39,21 @@
AInTicker.attach(&ReadAnalogIn,0.01f); //Elke 0.01 sec. Lees de analoge waarde
while(true){
- potwaarde1 = potmeter1.read(); // Lees de potwaardes uit
+ potwaarde1 = potmeter1.read(); // Lees de potwaardes uit. Tussen 0 en 1
potwaarde2 = potmeter2.read();
-
+
+ U1 = potwaarde1*2 -1; // Scale van -1 tot 1 ipv. 0 tot 1
+ U2 = potwaarde2*2 -1;
+
+ // Gebruik de absolute waarde van de scaled U waardes als input voor de motor.
+ // Negatieve waardes kunnen niet naar de motor gestuurd worden.
+ motor1_pwm.write(fabs(U1));
+ motor2_pwm.write(fabs(U2));
+
+ directionM1 = U1 > 0.0f; //either true or false
+ directionM2 = U2 > 0.0f;
+
+ wait(0.002f);
}
}
\ No newline at end of file