kao yi
/
Bov3
wu
Fork of CCC by
servo_api.cpp@9:33b99cb45e99, 2014-06-24 (annotated)
- Committer:
- backman
- Date:
- Tue Jun 24 10:06:54 2014 +0000
- Revision:
- 9:33b99cb45e99
- Parent:
- 1:82bc25a7b68b
- Child:
- 10:03d5aa2511c4
6/24;
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:33b99cb45e99 | 6 | #define right_end 0.06 //90 |
backman | 1:82bc25a7b68b | 7 | |
backman | 9:33b99cb45e99 | 8 | #define left_end 0.11 //-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 | 9:33b99cb45e99 | 24 | |
backman | 1:82bc25a7b68b | 25 | |
backman | 1:82bc25a7b68b | 26 | } |
backman | 1:82bc25a7b68b | 27 | |
backman | 1:82bc25a7b68b | 28 | |
backman | 1:82bc25a7b68b | 29 | |
backman | 1:82bc25a7b68b | 30 | |
backman | 1:82bc25a7b68b | 31 | |
backman | 1:82bc25a7b68b | 32 | |
backman | 9:33b99cb45e99 | 33 | float BX_servo::set_angle(float a){ |
backman | 9:33b99cb45e99 | 34 | |
backman | 9:33b99cb45e99 | 35 | if(a > left_end) |
backman | 9:33b99cb45e99 | 36 | a=0.11; |
backman | 9:33b99cb45e99 | 37 | else if(a< 0.06) |
backman | 9:33b99cb45e99 | 38 | a=0.06; |
backman | 1:82bc25a7b68b | 39 | |
backman | 1:82bc25a7b68b | 40 | |
backman | 1:82bc25a7b68b | 41 | angle=a; |
backman | 1:82bc25a7b68b | 42 | |
backman | 9:33b99cb45e99 | 43 | *servo_in=angle; |
backman | 1:82bc25a7b68b | 44 | |
backman | 1:82bc25a7b68b | 45 | |
backman | 1:82bc25a7b68b | 46 | |
backman | 1:82bc25a7b68b | 47 | return angle; |
backman | 1:82bc25a7b68b | 48 | |
backman | 1:82bc25a7b68b | 49 | } |