Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MODSERIAL mbed-rtos mbed
Fork of Master by
control.cpp@0:4f07ba929908, 2014-09-11 (annotated)
- Committer:
- 9uS7
- Date:
- Thu Sep 11 10:15:34 2014 +0000
- Revision:
- 0:4f07ba929908
- Child:
- 1:e1cfb5850088
main_program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
9uS7 | 0:4f07ba929908 | 1 | #include "mbed.h" |
9uS7 | 0:4f07ba929908 | 2 | #include "control.h" |
9uS7 | 0:4f07ba929908 | 3 | |
9uS7 | 0:4f07ba929908 | 4 | void pull(float buf){ |
9uS7 | 0:4f07ba929908 | 5 | Sig1 = 0; |
9uS7 | 0:4f07ba929908 | 6 | Sig2 = 1; |
9uS7 | 0:4f07ba929908 | 7 | Pwm = zeroPWM+buf/3; |
9uS7 | 0:4f07ba929908 | 8 | } |
9uS7 | 0:4f07ba929908 | 9 | |
9uS7 | 0:4f07ba929908 | 10 | void loose(float buf){ |
9uS7 | 0:4f07ba929908 | 11 | Sig1 = 1; |
9uS7 | 0:4f07ba929908 | 12 | Sig2 = 0; |
9uS7 | 0:4f07ba929908 | 13 | Pwm = zeroPWM+buf/3; |
9uS7 | 0:4f07ba929908 | 14 | } |
9uS7 | 0:4f07ba929908 | 15 | |
9uS7 | 0:4f07ba929908 | 16 | void brake(void){ |
9uS7 | 0:4f07ba929908 | 17 | Sig1 = 0; |
9uS7 | 0:4f07ba929908 | 18 | Sig2 = 0; |
9uS7 | 0:4f07ba929908 | 19 | Pwm = 1; |
9uS7 | 0:4f07ba929908 | 20 | } |
9uS7 | 0:4f07ba929908 | 21 | |
9uS7 | 0:4f07ba929908 | 22 | void open(void){ |
9uS7 | 0:4f07ba929908 | 23 | Sig1 = 0; |
9uS7 | 0:4f07ba929908 | 24 | Sig2 = 0; |
9uS7 | 0:4f07ba929908 | 25 | Pwm = 0; |
9uS7 | 0:4f07ba929908 | 26 | } |
9uS7 | 0:4f07ba929908 | 27 | |
9uS7 | 0:4f07ba929908 | 28 | void ResetPos(){ |
9uS7 | 0:4f07ba929908 | 29 | int pos_flag=0; |
9uS7 | 0:4f07ba929908 | 30 | while(1){ |
9uS7 | 0:4f07ba929908 | 31 | if(Red1>center_pos){ |
9uS7 | 0:4f07ba929908 | 32 | pull(0.3); |
9uS7 | 0:4f07ba929908 | 33 | }else if(Red1<center_pos){ |
9uS7 | 0:4f07ba929908 | 34 | loose(0.3); |
9uS7 | 0:4f07ba929908 | 35 | } |
9uS7 | 0:4f07ba929908 | 36 | if(abs(Red1-center_pos)<0.1){ |
9uS7 | 0:4f07ba929908 | 37 | Open1(); |
9uS7 | 0:4f07ba929908 | 38 | pos1_flag=1; |
9uS7 | 0:4f07ba929908 | 39 | } |
9uS7 | 0:4f07ba929908 | 40 | |
9uS7 | 0:4f07ba929908 | 41 | if(Red2>center_pos){ |
9uS7 | 0:4f07ba929908 | 42 | Back2(); |
9uS7 | 0:4f07ba929908 | 43 | }else if(Red2<center_pos){ |
9uS7 | 0:4f07ba929908 | 44 | Forward2(); |
9uS7 | 0:4f07ba929908 | 45 | } |
9uS7 | 0:4f07ba929908 | 46 | if(abs(Red2-center_pos)<0.1){ |
9uS7 | 0:4f07ba929908 | 47 | Open2(); |
9uS7 | 0:4f07ba929908 | 48 | pos2_flag=1; |
9uS7 | 0:4f07ba929908 | 49 | } |
9uS7 | 0:4f07ba929908 | 50 | |
9uS7 | 0:4f07ba929908 | 51 | if(pos1_flag == 1 && pos2_flag ==1) break; |
9uS7 | 0:4f07ba929908 | 52 | } |
9uS7 | 0:4f07ba929908 | 53 | } |