![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
working example of final project code (in development)
Dependencies: ContinuousServo TCS3472_I2C Tach mbed
Fork of ES202FinalProject by
main.cpp@0:ac6a1723d393, 2018-03-02 (annotated)
- Committer:
- jdonnal
- Date:
- Fri Mar 02 16:55:01 2018 +0000
- Revision:
- 0:ac6a1723d393
- Child:
- 2:f72b9dd19159
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jdonnal | 0:ac6a1723d393 | 1 | #include "mbed.h" |
jdonnal | 0:ac6a1723d393 | 2 | #include "ContinuousServo.h" |
jdonnal | 0:ac6a1723d393 | 3 | #include "Tach.h" |
jdonnal | 0:ac6a1723d393 | 4 | |
jdonnal | 0:ac6a1723d393 | 5 | Serial pc(USBTX,USBRX); |
jdonnal | 0:ac6a1723d393 | 6 | //servos |
jdonnal | 0:ac6a1723d393 | 7 | ContinuousServo left(p23); |
jdonnal | 0:ac6a1723d393 | 8 | ContinuousServo right(p26); |
jdonnal | 0:ac6a1723d393 | 9 | //encoders |
jdonnal | 0:ac6a1723d393 | 10 | Tach tLeft(p17,64); |
jdonnal | 0:ac6a1723d393 | 11 | Tach tRight(p13,64); |
jdonnal | 0:ac6a1723d393 | 12 | |
jdonnal | 0:ac6a1723d393 | 13 | int main() { |
jdonnal | 0:ac6a1723d393 | 14 | //wait for MATLAB command |
jdonnal | 0:ac6a1723d393 | 15 | left.speed(0.0); |
jdonnal | 0:ac6a1723d393 | 16 | right.speed(0.0); |
jdonnal | 0:ac6a1723d393 | 17 | //while(1); |
jdonnal | 0:ac6a1723d393 | 18 | pc.getc(); |
jdonnal | 0:ac6a1723d393 | 19 | //spin servos from -1 to 1 and print speed |
jdonnal | 0:ac6a1723d393 | 20 | for(float i=-1.0;i<=1.0;i+=0.01){ |
jdonnal | 0:ac6a1723d393 | 21 | left.speed(-1.0*i); |
jdonnal | 0:ac6a1723d393 | 22 | right.speed(i); |
jdonnal | 0:ac6a1723d393 | 23 | wait_ms(100); |
jdonnal | 0:ac6a1723d393 | 24 | pc.printf("%f,%f\n", tLeft.getSpeed(),tRight.getSpeed()); |
jdonnal | 0:ac6a1723d393 | 25 | } |
jdonnal | 0:ac6a1723d393 | 26 | left.stop(); |
jdonnal | 0:ac6a1723d393 | 27 | right.stop(); |
jdonnal | 0:ac6a1723d393 | 28 | } |