123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

Committer:
backman
Date:
Tue Jun 03 15:53:55 2014 +0000
Revision:
1:82bc25a7b68b
Child:
6:b046d6ff3745
cam_algroithm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
backman 1:82bc25a7b68b 1 // 0~180 angle 1~2ms
backman 1:82bc25a7b68b 2 #include "mbed.h"
backman 1:82bc25a7b68b 3 #include "servo_api.h"
backman 1:82bc25a7b68b 4
backman 1:82bc25a7b68b 5
backman 1:82bc25a7b68b 6 #define right_end 0.05 //90
backman 1:82bc25a7b68b 7
backman 1:82bc25a7b68b 8 #define left_end 0.1 //-90
backman 1:82bc25a7b68b 9
backman 1:82bc25a7b68b 10 //memory opt
backman 1:82bc25a7b68b 11 // 5 degree seperate
backman 1:82bc25a7b68b 12
backman 1:82bc25a7b68b 13
backman 1:82bc25a7b68b 14
backman 1:82bc25a7b68b 15 BX_servo::BX_servo(void){
backman 1:82bc25a7b68b 16
backman 1:82bc25a7b68b 17
backman 1:82bc25a7b68b 18 angle = 0;
backman 1:82bc25a7b68b 19
backman 1:82bc25a7b68b 20 servo_in= new PwmOut(PTB0);
backman 1:82bc25a7b68b 21
backman 1:82bc25a7b68b 22 servo_in->period_ms(20);
backman 1:82bc25a7b68b 23
backman 1:82bc25a7b68b 24 for(int i=0;i<37;i++){
backman 1:82bc25a7b68b 25
backman 1:82bc25a7b68b 26 angle_level[i]=i*(0.05/36)+right_end;
backman 1:82bc25a7b68b 27 }
backman 1:82bc25a7b68b 28
backman 1:82bc25a7b68b 29 *servo_in =angle_level[18];
backman 1:82bc25a7b68b 30
backman 1:82bc25a7b68b 31
backman 1:82bc25a7b68b 32 }
backman 1:82bc25a7b68b 33
backman 1:82bc25a7b68b 34
backman 1:82bc25a7b68b 35
backman 1:82bc25a7b68b 36
backman 1:82bc25a7b68b 37
backman 1:82bc25a7b68b 38
backman 1:82bc25a7b68b 39 int BX_servo::set_angle(int a){
backman 1:82bc25a7b68b 40
backman 1:82bc25a7b68b 41
backman 1:82bc25a7b68b 42 angle=a;
backman 1:82bc25a7b68b 43
backman 1:82bc25a7b68b 44 *servo_in=angle_level[18+a/5];
backman 1:82bc25a7b68b 45
backman 1:82bc25a7b68b 46
backman 1:82bc25a7b68b 47
backman 1:82bc25a7b68b 48 return angle;
backman 1:82bc25a7b68b 49
backman 1:82bc25a7b68b 50 }