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 MODSERIAL mbed-dsp mbed
Fork of BMT-M9_motorcontrol_groep3 by
Revision 15:979011e26ca3, committed 2014-10-17
- Comitter:
- Hooglugt
- Date:
- Fri Oct 17 10:51:38 2014 +0000
- Parent:
- 14:98925c1ed440
- Child:
- 16:1869377fbb73
- Commit message:
- FUNCTIONEREND script, correcte pins, roteert elke 2 seconde motor linksom en vervolgens rechtsom
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 17 09:39:49 2014 +0000
+++ b/main.cpp Fri Oct 17 10:51:38 2014 +0000
@@ -7,7 +7,7 @@
void clamp(float * in, float min, float max);
volatile bool looptimerflag;
HIDScope scope(2);
-float new_pwm = 0;
+float new_pwm = 2;
void setlooptimerflag(void)
{
@@ -21,24 +21,32 @@
void looper()
{
- if (new_pwm==0) {
- new_pwm = 1;
+ if (new_pwm==2) {
+ new_pwm = -2;
} else {
- new_pwm = 0;
+ new_pwm = 2;
}
}
int main()
{
- Encoder motor1(PTD2,PTD0);
- PwmOut pwm_motor(PTC8);
- pwm_motor.period_us(100); //10kHz PWM frequency
- DigitalOut motordir(PTC9);
+ //motor 1, 25D
+ Encoder motor1(PTD3, PTD5);
+ DigitalOut motor1dir(PTC9);
+ PwmOut pwm_motor1(PTC8);
+ pwm_motor.period_us(100); //10kHz PWM frequency
+
+ //motor 2, 25D
+ Encoder motor2(PTD2,PTD0);
+ DigitalOut motor2dir(PTA4);
+ PwmOut pwm_motor2(PTA5);
+
+ pwm_motor.period_us(100); //10kHz PWM frequency
Ticker looptimer;
looptimer.attach(setlooptimerflag,TSAMP);
Ticker flip_switch;
- flip_switch.attach(looper, 5);
+ flip_switch.attach(looper, 2);
while(1) {
while(!looptimerflag);
@@ -47,14 +55,14 @@
clamp(&new_pwm, -1,1);
scope.set(0, new_pwm);
- scope.set(1, motor1.getPosition());
+ scope.set(1, motor2.getPosition());
scope.send();
if(new_pwm > 0)
- motordir = 0;
+ motor2dir = 0;
else
- motordir = 1;
+ motor2dir = 1;
- pwm_motor.write(abs(new_pwm));
+ pwm_motor2.write(abs(new_pwm));
}
}
\ No newline at end of file
