![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Tachinit
Dependencies: mbed Tach ContinuousServo
main.cpp@0:9acdbbfa4eb2, 2019-04-17 (annotated)
- Committer:
- m215910
- Date:
- Wed Apr 17 14:45:09 2019 +0000
- Revision:
- 0:9acdbbfa4eb2
- Child:
- 1:66d0178e8f40
Tachinit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m215910 | 0:9acdbbfa4eb2 | 1 | //Satre Gagnon, Ewing, Batten |
m215910 | 0:9acdbbfa4eb2 | 2 | //Tach Initial |
m215910 | 0:9acdbbfa4eb2 | 3 | |
m215910 | 0:9acdbbfa4eb2 | 4 | #include "mbed.h" |
m215910 | 0:9acdbbfa4eb2 | 5 | #include "ContinuousServo.h" |
m215910 | 0:9acdbbfa4eb2 | 6 | #include "Tach.h" |
m215910 | 0:9acdbbfa4eb2 | 7 | |
m215910 | 0:9acdbbfa4eb2 | 8 | |
m215910 | 0:9acdbbfa4eb2 | 9 | Serial pc(USBTX,USBRX); //Establish serial connection |
m215910 | 0:9acdbbfa4eb2 | 10 | |
m215910 | 0:9acdbbfa4eb2 | 11 | //speed |
m215910 | 0:9acdbbfa4eb2 | 12 | float wL, wR; |
m215910 | 0:9acdbbfa4eb2 | 13 | |
m215910 | 0:9acdbbfa4eb2 | 14 | ContinuousServo left(p23); |
m215910 | 0:9acdbbfa4eb2 | 15 | ContinuousServo right(p26); |
m215910 | 0:9acdbbfa4eb2 | 16 | |
m215910 | 0:9acdbbfa4eb2 | 17 | //encoders |
m215910 | 0:9acdbbfa4eb2 | 18 | Tach tleft(p17,64); |
m215910 | 0:9acdbbfa4eb2 | 19 | Tach tright(p13,64); |
m215910 | 0:9acdbbfa4eb2 | 20 | |
m215910 | 0:9acdbbfa4eb2 | 21 | int main() |
m215910 | 0:9acdbbfa4eb2 | 22 | { |
m215910 | 0:9acdbbfa4eb2 | 23 | |
m215910 | 0:9acdbbfa4eb2 | 24 | pc.baud(9600); //set baud rate |
m215910 | 0:9acdbbfa4eb2 | 25 | |
m215910 | 0:9acdbbfa4eb2 | 26 | while(1) { |
m215910 | 0:9acdbbfa4eb2 | 27 | |
m215910 | 0:9acdbbfa4eb2 | 28 | left.speed(0.5); |
m215910 | 0:9acdbbfa4eb2 | 29 | right.speed(-0.5); //right negative to go forward |
m215910 | 0:9acdbbfa4eb2 | 30 | |
m215910 | 0:9acdbbfa4eb2 | 31 | wL = tleft.getSpeed(); //speed of left wheel (rev/sec) |
m215910 | 0:9acdbbfa4eb2 | 32 | wR = tright.getSpeed(); //speed of right wheel (rev/sec) |
m215910 | 0:9acdbbfa4eb2 | 33 | |
m215910 | 0:9acdbbfa4eb2 | 34 | pc.printf("%f, %f\n", wL, wR); |
m215910 | 0:9acdbbfa4eb2 | 35 | wait(1); |
m215910 | 0:9acdbbfa4eb2 | 36 | |
m215910 | 0:9acdbbfa4eb2 | 37 | } //while |
m215910 | 0:9acdbbfa4eb2 | 38 | } //main |