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: mbed QEI biquadFilter
controller_test.cpp@12:8295c02d740f, 2016-11-03 (annotated)
- Committer:
- ronvbree
- Date:
- Thu Nov 03 13:08:44 2016 +0000
- Revision:
- 12:8295c02d740f
- Parent:
- 7:a80cb6b06320
- Child:
- 18:1c9dc6caab9d
update
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ronvbree | 7:a80cb6b06320 | 1 | #include "controller.h" |
| ronvbree | 7:a80cb6b06320 | 2 | |
| ronvbree | 7:a80cb6b06320 | 3 | Serial pc(USBTX, USBRX); |
| ronvbree | 7:a80cb6b06320 | 4 | |
| ronvbree | 7:a80cb6b06320 | 5 | RobotController controller; |
| ronvbree | 7:a80cb6b06320 | 6 | |
| ronvbree | 7:a80cb6b06320 | 7 | AnalogIn upperPotMeter(A0); |
| ronvbree | 7:a80cb6b06320 | 8 | AnalogIn lowerPotMeter(A1); |
| ronvbree | 7:a80cb6b06320 | 9 | |
| ronvbree | 7:a80cb6b06320 | 10 | InterruptIn button(D2); |
| ronvbree | 7:a80cb6b06320 | 11 | InterruptIn killButton(D3); |
| ronvbree | 7:a80cb6b06320 | 12 | |
| ronvbree | 12:8295c02d740f | 13 | bool isInTop = false; |
| ronvbree | 12:8295c02d740f | 14 | |
| ronvbree | 7:a80cb6b06320 | 15 | void readArmLengths(float &upper, float &lower) { |
| ronvbree | 7:a80cb6b06320 | 16 | upper = L_min + (L_max - L_min) * upperPotMeter; |
| ronvbree | 7:a80cb6b06320 | 17 | lower = L_min + (L_max - L_min) * lowerPotMeter; |
| ronvbree | 7:a80cb6b06320 | 18 | } |
| ronvbree | 7:a80cb6b06320 | 19 | |
| ronvbree | 7:a80cb6b06320 | 20 | void onButtonPress() { |
| ronvbree | 12:8295c02d740f | 21 | // float upper; |
| ronvbree | 12:8295c02d740f | 22 | // float lower; |
| ronvbree | 12:8295c02d740f | 23 | // readArmLengths(upper, lower); |
| ronvbree | 12:8295c02d740f | 24 | // |
| ronvbree | 12:8295c02d740f | 25 | // pc.printf("Reference: Lower: %f, Upper: %f\n\r", lower, upper); |
| ronvbree | 12:8295c02d740f | 26 | // pc.printf("Encoder: Lower: %f, Upper: %f\n\r", controller.getLowerArmLength(), controller.getUpperArmLength()); |
| ronvbree | 12:8295c02d740f | 27 | // pc.printf("Robot killed: %s\n\r", controller.isKilled()? "Yes":"No"); |
| ronvbree | 12:8295c02d740f | 28 | // controller.setArmLengths(upper, lower); |
| ronvbree | 7:a80cb6b06320 | 29 | |
| ronvbree | 12:8295c02d740f | 30 | // controller.goToTop(); |
| ronvbree | 7:a80cb6b06320 | 31 | |
| ronvbree | 12:8295c02d740f | 32 | if (!isInTop) { |
| ronvbree | 12:8295c02d740f | 33 | controller.goToTop(); |
| ronvbree | 12:8295c02d740f | 34 | isInTop = true; |
| ronvbree | 12:8295c02d740f | 35 | } else { |
| ronvbree | 12:8295c02d740f | 36 | controller.paintDown(); |
| ronvbree | 12:8295c02d740f | 37 | } |
| ronvbree | 12:8295c02d740f | 38 | |
| ronvbree | 7:a80cb6b06320 | 39 | |
| ronvbree | 7:a80cb6b06320 | 40 | } |
| ronvbree | 7:a80cb6b06320 | 41 | |
| ronvbree | 7:a80cb6b06320 | 42 | |
| ronvbree | 7:a80cb6b06320 | 43 | int main() { |
| ronvbree | 7:a80cb6b06320 | 44 | pc.baud(115200); |
| ronvbree | 7:a80cb6b06320 | 45 | button.fall(&onButtonPress); |
| ronvbree | 7:a80cb6b06320 | 46 | killButton.fall(controller.getRobot(), &Robot::kill); |
| ronvbree | 7:a80cb6b06320 | 47 | pc.printf("Initialized\n\r"); |
| ronvbree | 7:a80cb6b06320 | 48 | while (true); |
| ronvbree | 7:a80cb6b06320 | 49 | |
| ronvbree | 7:a80cb6b06320 | 50 | } |
| ronvbree | 7:a80cb6b06320 | 51 | |
| ronvbree | 7:a80cb6b06320 | 52 |