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: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of Project_script_union_final by
Revision 7:f32005d13749, committed 2018-10-15
- Comitter:
- MarijkeZondag
- Date:
- Mon Oct 15 12:43:04 2018 +0000
- Parent:
- 6:f4bbb73f3989
- Child:
- 8:895d941a5910
- Commit message:
- Vorige program weggehaald;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Oct 01 11:42:25 2018 +0000
+++ b/main.cpp Mon Oct 15 12:43:04 2018 +0000
@@ -5,6 +5,8 @@
PwmOut pwmpin1(D5);
AnalogIn potmetervalue1(A1);
DigitalIn button2(D9); //klopt dit?
+DigitalIn encoderA(D9);
+DigitalIn encoderB(D8);
DigitalOut directionpin2(D7);
PwmOut pwmpin2(D6);
@@ -29,42 +31,23 @@
float m1 = ((u1*2.0f)-1.0f);
float m2 = ((u2*2.0f)-1.0f);
- // pc.printf("Motor value is %f\n\r",m);
-
- /*if (m <= -0.005)
- {
- directionpin.write(0);
- pwmpin = fabs(m); //pwm duty cycle can only be positive, floating
- pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz
- pc.printf("Motor draait naar A\n\r");
- }
+ int Ea = encoderA;
+ int Eb = encoderB;
+
+ int static Eas = 0;
+ int static Ebs = 0;
+
+
+ pwmpin1 = fabs(m1*0.6f)+0.4f; //pwm duty cycle can only be positive, floating, 0.4f is "inefficiënt", dit tellen we erbij op, en keer 0.6 om te corrigeren voor de helling.
+ directionpin1.write(m1>0); //Indien waar, motor draait rechtsom. Indien niet waar, motor draait linksom.
+ wait(0.01f); //zodat de code niet oneindig doorgaat.
+
+ pwmpin2 = fabs(m2*0.6f)+0.4f;
+ directionpin2.write(m2>0);
+
+ if(A==1 && A>B)
+ {
- else if (m >= 0.005)
- {
- directionpin.write(1);
- pwmpin = fabs(m);
- pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz
- pc.printf("Motor draait naar B\n\r");
-
- }
-
- else if (-0.4 < m && m < 0.)
- {
- //pwmpin = 0.0;
- pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz
- pc.printf("Motor zou moeten stoppen.\n\r");
- }
-
- Met deze code kunnen we serial communication gebruiken. Als we dit niet nodig hebben en alleen de motor willen aansturen, dan gebruiken we de code hieronder.
- */
-
- pwmpin1 = fabs(m1*0.6f)+0.4f; //pwm duty cycle can only be positive, floating, 0.4f is "inefficiënt", dit tellen we erbij op, en keer 0.6 om te corrigeren voor de helling.
- directionpin1.write(m1>0); //Indien waar, motor draait rechtsom. Indien niet waar, motor draait linksom.
- wait(0.001f); //zodat de code niet oneindig doorgaat.
-
- pwmpin2 = fabs(m2*0.6f)+0.4f;
- directionpin2.write(m2>0);
- wait(0.001f);
}
}
