servoding

Dependencies:   mbed Servo

Committer:
tomvaniddekinge
Date:
Fri Oct 23 10:06:36 2015 +0000
Revision:
1:c6e4257722b9
Parent:
0:952a13a3eb5c
Child:
2:9bb7e571b55f
Wat een mooi ding chiel!;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
S1lverEagle 0:952a13a3eb5c 1 #include "mbed.h"
tomvaniddekinge 1:c6e4257722b9 2 #include "math.h"
S1lverEagle 0:952a13a3eb5c 3
S1lverEagle 0:952a13a3eb5c 4 //servo ranges from .6ms to 2.7ms duty cycle in 20ms pwm period
S1lverEagle 0:952a13a3eb5c 5
S1lverEagle 0:952a13a3eb5c 6 PwmOut servoPwm(D5);
S1lverEagle 0:952a13a3eb5c 7
tomvaniddekinge 1:c6e4257722b9 8 double theta1;
tomvaniddekinge 1:c6e4257722b9 9 double theta2;
tomvaniddekinge 1:c6e4257722b9 10 double theta3;
tomvaniddekinge 1:c6e4257722b9 11 double servoPwm.pulsewidth;
tomvaniddekinge 1:c6e4257722b9 12
tomvaniddekinge 1:c6e4257722b9 13 Ticker servo;
tomvaniddekinge 1:c6e4257722b9 14
tomvaniddekinge 1:c6e4257722b9 15 void servo_control()
S1lverEagle 0:952a13a3eb5c 16 {
tomvaniddekinge 1:c6e4257722b9 17 theta3 = 180 - theta1 - theta2;
tomvaniddekinge 1:c6e4257722b9 18 servoPwm.pulsewidth = (0.0021/180)*theta3 + 0.0006;
tomvaniddekinge 1:c6e4257722b9 19 }
tomvaniddekinge 1:c6e4257722b9 20
tomvaniddekinge 1:c6e4257722b9 21 int main()
tomvaniddekinge 1:c6e4257722b9 22 {
tomvaniddekinge 1:c6e4257722b9 23 servoPwm.period(0.020);
tomvaniddekinge 1:c6e4257722b9 24 servo.attach(&servo_control,0,02);
tomvaniddekinge 1:c6e4257722b9 25 while(true){}
S1lverEagle 0:952a13a3eb5c 26 }
tomvaniddekinge 1:c6e4257722b9 27
tomvaniddekinge 1:c6e4257722b9 28
tomvaniddekinge 1:c6e4257722b9 29