Yi Lin Chen
/
Boboobooo
shared
Fork of Boboobooo by
servo_api.cpp@8:089b778962c4, 2014-10-31 (annotated)
- Committer:
- Kruskal
- Date:
- Fri Oct 31 10:54:51 2014 +0000
- Revision:
- 8:089b778962c4
- Parent:
- 1:82bc25a7b68b
:D
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" |
Kruskal | 8:089b778962c4 | 4 | |
Kruskal | 8:089b778962c4 | 5 | |
Kruskal | 8:089b778962c4 | 6 | #define right_end 0.088 // 0.088 |
Kruskal | 8:089b778962c4 | 7 | //MID 0.073 |
Kruskal | 8:089b778962c4 | 8 | #define left_end 0.058 // 0.058 |
Kruskal | 8:089b778962c4 | 9 | |
backman | 1:82bc25a7b68b | 10 | //memory opt |
backman | 1:82bc25a7b68b | 11 | // 5 degree seperate |
Kruskal | 8:089b778962c4 | 12 | |
Kruskal | 8:089b778962c4 | 13 | |
Kruskal | 8:089b778962c4 | 14 | |
backman | 1:82bc25a7b68b | 15 | BX_servo::BX_servo(void){ |
backman | 1:82bc25a7b68b | 16 | |
backman | 1:82bc25a7b68b | 17 | |
backman | 1:82bc25a7b68b | 18 | angle = 0; |
Kruskal | 8:089b778962c4 | 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 | |
Kruskal | 8:089b778962c4 | 24 | |
backman | 1:82bc25a7b68b | 25 | |
backman | 1:82bc25a7b68b | 26 | } |
Kruskal | 8:089b778962c4 | 27 | |
Kruskal | 8:089b778962c4 | 28 | |
Kruskal | 8:089b778962c4 | 29 | |
Kruskal | 8:089b778962c4 | 30 | |
Kruskal | 8:089b778962c4 | 31 | |
Kruskal | 8:089b778962c4 | 32 | |
Kruskal | 8:089b778962c4 | 33 | float BX_servo::set_angle(float a){ |
Kruskal | 8:089b778962c4 | 34 | |
Kruskal | 8:089b778962c4 | 35 | if( a<left_end ) |
Kruskal | 8:089b778962c4 | 36 | a=left_end; |
Kruskal | 8:089b778962c4 | 37 | else if(a> right_end) |
Kruskal | 8:089b778962c4 | 38 | a=right_end; |
backman | 1:82bc25a7b68b | 39 | |
Kruskal | 8:089b778962c4 | 40 | angle=a; |
Kruskal | 8:089b778962c4 | 41 | |
Kruskal | 8:089b778962c4 | 42 | *servo_in=angle; |
backman | 1:82bc25a7b68b | 43 | |
backman | 1:82bc25a7b68b | 44 | |
backman | 1:82bc25a7b68b | 45 | |
backman | 1:82bc25a7b68b | 46 | return angle; |
backman | 1:82bc25a7b68b | 47 | |
backman | 1:82bc25a7b68b | 48 | } |