Init
Dependencies: Break Motor Communication Steering mbed Controller
main.cpp@1:2538cbbea1f8, 2017-07-13 (annotated)
- Committer:
- skrickl
- Date:
- Thu Jul 13 13:45:55 2017 +0000
- Revision:
- 1:2538cbbea1f8
- Parent:
- 0:226470cfa428
bla
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skrickl | 0:226470cfa428 | 1 | #include "mbed.h" |
skrickl | 1:2538cbbea1f8 | 2 | #include "SerialController.h" |
skrickl | 1:2538cbbea1f8 | 3 | #include "MbedToPC.h" |
skrickl | 1:2538cbbea1f8 | 4 | #include "MotorController.h" |
skrickl | 1:2538cbbea1f8 | 5 | #include <string> |
skrickl | 0:226470cfa428 | 6 | |
skrickl | 1:2538cbbea1f8 | 7 | DigitalOut led1(LED1); |
skrickl | 1:2538cbbea1f8 | 8 | DigitalOut led2(LED2); |
skrickl | 1:2538cbbea1f8 | 9 | //DigitalOut led3(LED3); |
skrickl | 1:2538cbbea1f8 | 10 | //DigitalOut led4(LED4); |
skrickl | 1:2538cbbea1f8 | 11 | |
skrickl | 1:2538cbbea1f8 | 12 | DigitalOut pin1(p21); |
skrickl | 1:2538cbbea1f8 | 13 | DigitalOut pin2(p22); |
skrickl | 1:2538cbbea1f8 | 14 | |
skrickl | 1:2538cbbea1f8 | 15 | |
skrickl | 1:2538cbbea1f8 | 16 | DigitalOut pin_forward(p29); |
skrickl | 1:2538cbbea1f8 | 17 | DigitalOut pin_backward(p30); |
skrickl | 1:2538cbbea1f8 | 18 | AnalogOut pin_analog_out_throttle(p18); |
skrickl | 1:2538cbbea1f8 | 19 | |
skrickl | 1:2538cbbea1f8 | 20 | Serial pc(USBTX, USBRX, 115200); |
skrickl | 0:226470cfa428 | 21 | |
skrickl | 0:226470cfa428 | 22 | int main() |
skrickl | 1:2538cbbea1f8 | 23 | { |
skrickl | 1:2538cbbea1f8 | 24 | pin1 = 0; |
skrickl | 1:2538cbbea1f8 | 25 | pin2 = 0; |
skrickl | 1:2538cbbea1f8 | 26 | |
skrickl | 1:2538cbbea1f8 | 27 | SerialController controller(p9, p10, p28, p27, 115200); |
skrickl | 1:2538cbbea1f8 | 28 | |
skrickl | 1:2538cbbea1f8 | 29 | float speed = 0.0; |
skrickl | 1:2538cbbea1f8 | 30 | int status = 0; |
skrickl | 1:2538cbbea1f8 | 31 | int uno = 1; |
skrickl | 1:2538cbbea1f8 | 32 | int zero = 0; |
skrickl | 1:2538cbbea1f8 | 33 | |
skrickl | 1:2538cbbea1f8 | 34 | led1 = uno; |
skrickl | 1:2538cbbea1f8 | 35 | wait(1); |
skrickl | 1:2538cbbea1f8 | 36 | led1 = zero; |
skrickl | 1:2538cbbea1f8 | 37 | |
skrickl | 1:2538cbbea1f8 | 38 | while (1) |
skrickl | 0:226470cfa428 | 39 | { |
skrickl | 1:2538cbbea1f8 | 40 | /*led1 = !led1; |
skrickl | 1:2538cbbea1f8 | 41 | wait(0.5);*/ |
skrickl | 1:2538cbbea1f8 | 42 | |
skrickl | 1:2538cbbea1f8 | 43 | status = controller.getStatus(); |
skrickl | 1:2538cbbea1f8 | 44 | |
skrickl | 1:2538cbbea1f8 | 45 | led1 = status; |
skrickl | 1:2538cbbea1f8 | 46 | led2 = status; |
skrickl | 1:2538cbbea1f8 | 47 | |
skrickl | 1:2538cbbea1f8 | 48 | pc.printf("Status: %i \r\n",status); |
skrickl | 1:2538cbbea1f8 | 49 | |
skrickl | 1:2538cbbea1f8 | 50 | /*if (status == MbedToPC::STATUS_START) |
skrickl | 1:2538cbbea1f8 | 51 | { |
skrickl | 1:2538cbbea1f8 | 52 | speed = controller.getVelTarget(); |
skrickl | 1:2538cbbea1f8 | 53 | led1 = 0; |
skrickl | 1:2538cbbea1f8 | 54 | } |
skrickl | 1:2538cbbea1f8 | 55 | else |
skrickl | 1:2538cbbea1f8 | 56 | { |
skrickl | 1:2538cbbea1f8 | 57 | speed = 0; |
skrickl | 1:2538cbbea1f8 | 58 | led1 = 1; |
skrickl | 1:2538cbbea1f8 | 59 | } |
skrickl | 1:2538cbbea1f8 | 60 | |
skrickl | 1:2538cbbea1f8 | 61 | if (speed == 0) |
skrickl | 1:2538cbbea1f8 | 62 | { |
skrickl | 1:2538cbbea1f8 | 63 | pin_analog_out_throttle = 0; |
skrickl | 1:2538cbbea1f8 | 64 | pin_forward = 0; |
skrickl | 1:2538cbbea1f8 | 65 | pin_backward = 0; |
skrickl | 1:2538cbbea1f8 | 66 | } |
skrickl | 1:2538cbbea1f8 | 67 | else if (speed < 0) |
skrickl | 1:2538cbbea1f8 | 68 | { |
skrickl | 1:2538cbbea1f8 | 69 | pin_analog_out_throttle = 0; |
skrickl | 1:2538cbbea1f8 | 70 | pin_forward = 0; |
skrickl | 1:2538cbbea1f8 | 71 | pin_backward = 1; |
skrickl | 1:2538cbbea1f8 | 72 | wait_ms(100); |
skrickl | 1:2538cbbea1f8 | 73 | pin_analog_out_throttle = 0.6; |
skrickl | 1:2538cbbea1f8 | 74 | } |
skrickl | 1:2538cbbea1f8 | 75 | else if (speed > 0) |
skrickl | 1:2538cbbea1f8 | 76 | { |
skrickl | 1:2538cbbea1f8 | 77 | pin_analog_out_throttle = 0; |
skrickl | 1:2538cbbea1f8 | 78 | pin_backward = 0; |
skrickl | 1:2538cbbea1f8 | 79 | pin_forward = 1; |
skrickl | 1:2538cbbea1f8 | 80 | wait_ms(100); |
skrickl | 1:2538cbbea1f8 | 81 | pin_analog_out_throttle = 0.6; |
skrickl | 1:2538cbbea1f8 | 82 | }*/ |
skrickl | 0:226470cfa428 | 83 | } |
skrickl | 1:2538cbbea1f8 | 84 | } |