Tony Lin
/
BX-car
hello
Fork of BX-car by
servo_api.cpp@11:03d5aa2511c4, 2014-06-26 (annotated)
- Committer:
- backman
- Date:
- Thu Jun 26 09:15:35 2014 +0000
- Revision:
- 11:03d5aa2511c4
- Parent:
- 9:33b99cb45e99
without os
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 | 11:03d5aa2511c4 | 8 | #define left_end 0.101 //-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 | 11:03d5aa2511c4 | 35 | if( a>left_end ) |
backman | 11:03d5aa2511c4 | 36 | a=left_end; |
backman | 11:03d5aa2511c4 | 37 | else if(a< right_end) |
backman | 11:03d5aa2511c4 | 38 | a=right_end; |
backman | 11:03d5aa2511c4 | 39 | |
backman | 11:03d5aa2511c4 | 40 | |
backman | 11:03d5aa2511c4 | 41 | |
backman | 11:03d5aa2511c4 | 42 | |
backman | 11:03d5aa2511c4 | 43 | |
backman | 1:82bc25a7b68b | 44 | |
backman | 1:82bc25a7b68b | 45 | angle=a; |
backman | 1:82bc25a7b68b | 46 | |
backman | 9:33b99cb45e99 | 47 | *servo_in=angle; |
backman | 1:82bc25a7b68b | 48 | |
backman | 1:82bc25a7b68b | 49 | |
backman | 1:82bc25a7b68b | 50 | |
backman | 1:82bc25a7b68b | 51 | return angle; |
backman | 1:82bc25a7b68b | 52 | |
backman | 1:82bc25a7b68b | 53 | } |