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: Encoder HIDScope mbed
Fork of Motor_component_testing by
Revision 3:c6b8499a9021, committed 2014-10-27
- Comitter:
- phgbartels
- Date:
- Mon Oct 27 12:13:24 2014 +0000
- Parent:
- 2:b7d757570748
- Child:
- 4:71ada7709c46
- Commit message:
- Opschonen script + omschrijven tot 2 motoren
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Oct 23 09:47:12 2014 +0000
+++ b/main.cpp Mon Oct 27 12:13:24 2014 +0000
@@ -1,24 +1,65 @@
#include "mbed.h"
#include "encoder.h"
-//#include "HIDScope.h"
+#include "HIDScope.h"
#include "PwmOut.h"
+/*definieren pinnen Motor 1*/
#define M1_PWM PTA5
#define M1_DIR PTA4
+#define M2_PWM PTC8
+#define M2_DIR PTC9
+/*Definieren minimale waarden PWM per motor*/
+#define PWM1_min_30 0.529 /*met koppelstuk!*/
+#define PWM2_min_50 0.519 /*aanpassen! Klopt nog niet met koppelstuk*/
+/*Definieren om de hoeveel seconden er gegevens naar de HID-scope gestuurd worden.*/
+#define TSAMP 0.005
Encoder motor1(PTD3,PTD1);
+Encoder motor2(PTD5, PTD0);
PwmOut pwm_motor1(M1_PWM);
+PwmOut pwm_motor2(M2_PWM);
DigitalOut motordir1(M1_DIR);
+DigitalOut motordir2(M2_DIR);
DigitalOut LED(LED_GREEN);
-float PWM = 0.51; /// (1000/200);
-//HIDScope scope(3);
+volatile bool looptimerflag;
+int PWM1_percentage = 1;
+int PWM2_percentage = 1;
+float PWM1 = ((1-PWM1_min_30)/100)*PWM1_percentage + PWM1_min_30;
+float PWM2 = ((1-PWM2_min_50)/100)*PWM2_percentage + PWM1_min_30;
+
+HIDScope scope(3);
+
+//Ticker tick;
+/*void PWMc()
+{
+ PWM = abs(PWM-0.1);
+ pwm_motor1.write(PWM);
+ scope.set(0, motor1.getPosition());
+ scope.set(1, DigitalIn(PTD3));
+ scope.set(2, DigitalIn(PTD1));
+ scope.send();
+ }*/
+
+void setlooptimerflag(void) //Ticker maakt een constructie die zoveel keer per seconde een functie uitvoerd, met sampingling freq TSAMP
+{
+ looptimerflag = true;
+}
int main() {
+ //tick.attach(&PWMc, 5);
+
pwm_motor1.period_us(100);
- pwm_motor1.write(PWM);
+ pwm_motor2.period_us(100);
+ pwm_motor1.write(PWM1);
+ pwm_motor2.write(PWM2);
LED = 0;
- motordir1 = 0;
- while(true) {
+ motordir1 = 0;
+ motordir2 = 0;
+
+ Ticker looptimer; // looptimer = variabele van het type ticker(niet int of float), Daarmee is looptimer een classe. Omdat een classe is heeft het methods oftewel functies, zoals attach. Setlooptimerflag is een functie
+ looptimer.attach(setlooptimerflag,TSAMP); // attach betekend het koppelen van een functie aan een classe.
+ while(true) {
+
//wait(3);
//pwm_motor1.write(0.4);
LED = 1;
@@ -26,35 +67,16 @@
//PWM = PWM + 0.05;
//pwm_motor1.pulsewidth_us(50);
-
- //scope.set(0, motor1.getPosition());
- //scope.set(1, DigitalIn(PTD3));
- //scope.set(2, DigitalIn(PTD1));
- //scope.send();
- //wait(0.01);
-
- /*
- while (PWM > 0) {
- PWM = PWM - 0.005;
- motordir1 = 0;
- pwm_motor1.write(PWM);
- scope.set(0, motor1.getPosition());
- scope.set(1, DigitalIn(PTD3));
- scope.set(2, DigitalIn(PTD1));
- scope.set(3, pwm_motor1);
- scope.send();
- wait(0.005);
+ while(!looptimerflag) //Hierdoor zeg je eigenlijk tegen je systeem; voer dit script uit na elke TSAMP s.
+ {
+ /*do nothing*/ //Zolang dit waar is, doe je niets.
}
- while (PWM < 1) {
- PWM = PWM + 0.005;
- motordir1 = 0;
- pwm_motor1.write(PWM);
+ looptimerflag = false; //clear flag
+
scope.set(0, motor1.getPosition());
- scope.set(1, DigitalIn(PTD3));
- scope.set(2, DigitalIn(PTD1));
- scope.set(3, pwm_motor1);
+ scope.set(1, motor1.getSpeed());
+ scope.set(2, motor2.getPosition());
+ scope.set(3, motor2.getSpeed());
scope.send();
- wait(0.005);
- }*/
}
}
