Servo

Dependencies:   mbed MODSERIAL Servo FastPWM

Committer:
AnkePost
Date:
Fri Oct 11 11:06:43 2019 +0000
Revision:
5:74962b191242
Parent:
4:8ae0c82c2d60
Child:
6:e6125ef7705e
Child:
9:6e163794b011
Werkende servoaansturing, smooth met sinus

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnkePost 0:60a8a60074a7 1 #include "mbed.h"
AnkePost 5:74962b191242 2 //#include "Servo.h"
AnkePost 5:74962b191242 3 //#include "FastPWM.h"
AnkePost 5:74962b191242 4 #include <math.h>
AnkePost 3:91b8945b659d 5
AnkePost 0:60a8a60074a7 6 Serial pc(USBTX, USBRX);
AnkePost 5:74962b191242 7 PwmOut myservo(D5);
AnkePost 3:91b8945b659d 8
AnkePost 3:91b8945b659d 9 int main()
AnkePost 3:91b8945b659d 10 {
AnkePost 5:74962b191242 11 myservo.period(0.02f);
AnkePost 5:74962b191242 12 float t = 0;
AnkePost 5:74962b191242 13 while (true)
AnkePost 5:74962b191242 14 {
AnkePost 5:74962b191242 15 float ref = sin(t);
AnkePost 5:74962b191242 16 float pwm = 0.05 + 0.03 * ref; // maximale bereik: allebei 0.05
AnkePost 5:74962b191242 17 myservo.write(pwm);
AnkePost 5:74962b191242 18 t+=0.02; // nooit groter dan periode servomotor, zelfde geldt voor regel hieronder
AnkePost 5:74962b191242 19 wait(0.02);
AnkePost 5:74962b191242 20 }
AnkePost 0:60a8a60074a7 21 }