test
Dependencies: mbed Watchdog stm32-sensor-base2
main.cpp@19:7935ca386e13, 2021-11-05 (annotated)
- Committer:
- ruslanbredun
- Date:
- Fri Nov 05 14:39:08 2021 +0000
- Revision:
- 19:7935ca386e13
- Parent:
- 18:025d9a617769
LastFirmWare05/11/21;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ommpy | 0:d383e2dee0f7 | 1 | #include <global.h> |
ruslanbredun | 12:406f75196a12 | 2 | |
ruslanbredun | 12:406f75196a12 | 3 | Serial RS2(UART2_TX, UART2_RX); |
ruslanbredun | 19:7935ca386e13 | 4 | Serial RS1(UART1_TX, UART1_RX); |
ruslanbredun | 19:7935ca386e13 | 5 | |
ruslanbredun | 19:7935ca386e13 | 6 | DigitalOut Select1(DE_TXD_1); |
ruslanbredun | 19:7935ca386e13 | 7 | DigitalOut Select2(DE_TXD_2); |
ruslanbredun | 19:7935ca386e13 | 8 | |
ruslanbredun | 19:7935ca386e13 | 9 | AS5045 Enc_left(SP1_NSS1); |
ruslanbredun | 19:7935ca386e13 | 10 | AS5045 Enc_right(SP1_NSS2); |
ruslanbredun | 19:7935ca386e13 | 11 | |
ruslanbredun | 19:7935ca386e13 | 12 | E18_D80NK IR_sensor_left (PB_13); |
ruslanbredun | 19:7935ca386e13 | 13 | E18_D80NK IR_sensor_right (PB_12); |
ruslanbredun | 19:7935ca386e13 | 14 | |
ruslanbredun | 19:7935ca386e13 | 15 | DigitalIn Lift1 (PB_0); |
ruslanbredun | 19:7935ca386e13 | 16 | DigitalIn Lift2 (PB_1); |
ruslanbredun | 19:7935ca386e13 | 17 | |
ruslanbredun | 19:7935ca386e13 | 18 | JSN_SR04 US_sensor_left (PB_14, PA_9); |
ruslanbredun | 19:7935ca386e13 | 19 | JSN_SR04 US_sensor_middle (PB_15, PA_9); |
ruslanbredun | 19:7935ca386e13 | 20 | JSN_SR04 US_sensor_right (PA_8, PA_9); |
ruslanbredun | 19:7935ca386e13 | 21 | |
ruslanbredun | 19:7935ca386e13 | 22 | OneWire oneWire(PA_11); // substitute D8 with the actual pin name connected to the 1-wire bus |
ruslanbredun | 12:406f75196a12 | 23 | |
nestedslk | 4:f6e22dd39313 | 24 | Timer timer; |
ruslanbredun | 14:b3530522908e | 25 | Watchdog watchDog; |
ruslanbredun | 14:b3530522908e | 26 | |
ommpy | 6:a760ce6defbe | 27 | typedef uint8_t byte; |
ruslanbredun | 12:406f75196a12 | 28 | |
ruslanbredun | 12:406f75196a12 | 29 | |
ruslanbredun | 19:7935ca386e13 | 30 | char c = '1'; |
ruslanbredun | 19:7935ca386e13 | 31 | int Enc_left_data = 0, Enc_right_data = 0, sensorsFound = 0, US1_data = 0,US2_data = 0, US3_data = 0, Lift_IR1 = 0,Lift_IR2 = 0; |
ruslanbredun | 19:7935ca386e13 | 32 | bool IR1_data = 0,IR2_data = 0, sendFlag = false; |
ruslanbredun | 19:7935ca386e13 | 33 | float temp_one_value = -1, temp_two_value = -1; |
ruslanbredun | 18:025d9a617769 | 34 | |
ruslanbredun | 12:406f75196a12 | 35 | |
ruslanbredun | 18:025d9a617769 | 36 | void Encoders() |
ruslanbredun | 18:025d9a617769 | 37 | { |
ruslanbredun | 18:025d9a617769 | 38 | Enc_left_data = Enc_left.getPosition(); |
ruslanbredun | 18:025d9a617769 | 39 | wait_ms(3); |
ruslanbredun | 18:025d9a617769 | 40 | Enc_right_data = Enc_right.getPosition(); |
ruslanbredun | 18:025d9a617769 | 41 | wait_ms(3); |
ruslanbredun | 12:406f75196a12 | 42 | |
ruslanbredun | 18:025d9a617769 | 43 | Select1 = 1; |
ruslanbredun | 18:025d9a617769 | 44 | RS1.printf ("%d_%d\r\n", Enc_right_data, Enc_left_data); |
ruslanbredun | 18:025d9a617769 | 45 | wait_ms(3); |
ruslanbredun | 18:025d9a617769 | 46 | Select1 = 0; |
ruslanbredun | 18:025d9a617769 | 47 | } |
ruslanbredun | 19:7935ca386e13 | 48 | |
ruslanbredun | 12:406f75196a12 | 49 | void UART2_callback() |
ruslanbredun | 12:406f75196a12 | 50 | { |
ruslanbredun | 12:406f75196a12 | 51 | c = RS2.getc(); |
ruslanbredun | 14:b3530522908e | 52 | if(c == '5') { |
ruslanbredun | 12:406f75196a12 | 53 | sendFlag = true; |
ruslanbredun | 12:406f75196a12 | 54 | } else { |
ruslanbredun | 12:406f75196a12 | 55 | Select2 = 1; |
ruslanbredun | 13:0c732e06d675 | 56 | wait_ms(90); |
ruslanbredun | 12:406f75196a12 | 57 | Select2 = 0; |
ruslanbredun | 12:406f75196a12 | 58 | } |
ruslanbredun | 12:406f75196a12 | 59 | } |
nestedslk | 4:f6e22dd39313 | 60 | int main() |
nestedslk | 4:f6e22dd39313 | 61 | { |
ruslanbredun | 19:7935ca386e13 | 62 | RS1.baud (115200); |
ruslanbredun | 12:406f75196a12 | 63 | RS2.baud (115200); |
ruslanbredun | 19:7935ca386e13 | 64 | RS2.attach(&UART2_callback); |
ruslanbredun | 19:7935ca386e13 | 65 | |
ruslanbredun | 12:406f75196a12 | 66 | Select1 = 0; |
ruslanbredun | 19:7935ca386e13 | 67 | Select2 = 0; |
ruslanbredun | 18:025d9a617769 | 68 | |
ruslanbredun | 14:b3530522908e | 69 | timer.start(); |
ruslanbredun | 12:406f75196a12 | 70 | |
ruslanbredun | 19:7935ca386e13 | 71 | watchDog.Configure(5.0); |
ruslanbredun | 12:406f75196a12 | 72 | |
ruslanbredun | 12:406f75196a12 | 73 | US_sensor_left.setRanges (20, 300); |
ruslanbredun | 12:406f75196a12 | 74 | US_sensor_middle.setRanges (20, 300); |
ruslanbredun | 12:406f75196a12 | 75 | US_sensor_right.setRanges (20, 300); |
ruslanbredun | 12:406f75196a12 | 76 | |
ruslanbredun | 12:406f75196a12 | 77 | for (sensorsFound = 0; sensorsFound < MAX_SENSOSRS; sensorsFound++) { |
ommpy | 10:0b7f23df690a | 78 | ds1820[sensorsFound] = new DS1820(&oneWire); |
ommpy | 10:0b7f23df690a | 79 | if (!ds1820[sensorsFound]->begin()) { |
ommpy | 10:0b7f23df690a | 80 | delete ds1820[sensorsFound]; |
ommpy | 10:0b7f23df690a | 81 | break; |
ommpy | 10:0b7f23df690a | 82 | } |
ommpy | 10:0b7f23df690a | 83 | } |
ruslanbredun | 12:406f75196a12 | 84 | |
ruslanbredun | 12:406f75196a12 | 85 | while (true) { |
ruslanbredun | 14:b3530522908e | 86 | watchDog.Service(); |
ruslanbredun | 19:7935ca386e13 | 87 | |
ruslanbredun | 18:025d9a617769 | 88 | Encoders(); |
ruslanbredun | 19:7935ca386e13 | 89 | |
ruslanbredun | 18:025d9a617769 | 90 | for (int i = 0; i < sensorsFound; i++) { |
ruslanbredun | 18:025d9a617769 | 91 | ds1820[i]->startConversion(); |
ruslanbredun | 18:025d9a617769 | 92 | wait_ms(1); |
ruslanbredun | 18:025d9a617769 | 93 | } |
ruslanbredun | 19:7935ca386e13 | 94 | |
ruslanbredun | 18:025d9a617769 | 95 | Encoders(); |
ruslanbredun | 14:b3530522908e | 96 | |
ruslanbredun | 18:025d9a617769 | 97 | US_sensor_left.startMeasurement (); |
ruslanbredun | 18:025d9a617769 | 98 | US1_data = US_sensor_left.getDistance_cm (); |
ruslanbredun | 18:025d9a617769 | 99 | wait_ms(20); |
ruslanbredun | 19:7935ca386e13 | 100 | |
ruslanbredun | 18:025d9a617769 | 101 | Encoders(); |
ruslanbredun | 12:406f75196a12 | 102 | |
ruslanbredun | 18:025d9a617769 | 103 | US_sensor_middle.startMeasurement (); |
ruslanbredun | 18:025d9a617769 | 104 | US2_data = US_sensor_middle.getDistance_cm (); |
ruslanbredun | 18:025d9a617769 | 105 | wait_ms(20); |
ruslanbredun | 19:7935ca386e13 | 106 | |
ruslanbredun | 18:025d9a617769 | 107 | Encoders(); |
ruslanbredun | 18:025d9a617769 | 108 | |
ruslanbredun | 18:025d9a617769 | 109 | US_sensor_right.startMeasurement (); |
ruslanbredun | 18:025d9a617769 | 110 | US3_data = US_sensor_right.getDistance_cm (); |
ruslanbredun | 18:025d9a617769 | 111 | wait_ms(20); |
ruslanbredun | 19:7935ca386e13 | 112 | |
ruslanbredun | 18:025d9a617769 | 113 | Encoders(); |
ruslanbredun | 18:025d9a617769 | 114 | |
ruslanbredun | 18:025d9a617769 | 115 | IR1_data = IR_sensor_left.checkObstacle (); |
ruslanbredun | 18:025d9a617769 | 116 | IR2_data = IR_sensor_right.checkObstacle (); |
ruslanbredun | 18:025d9a617769 | 117 | |
ruslanbredun | 18:025d9a617769 | 118 | Lift_IR1 = Lift1.read(); |
ruslanbredun | 18:025d9a617769 | 119 | Lift_IR2 = Lift2.read(); |
ruslanbredun | 19:7935ca386e13 | 120 | |
ruslanbredun | 18:025d9a617769 | 121 | Encoders(); |
ruslanbredun | 14:b3530522908e | 122 | |
ruslanbredun | 18:025d9a617769 | 123 | if (ds1820[0]->isPresent() ) { |
ruslanbredun | 18:025d9a617769 | 124 | temp_one_value = ds1820[0]->read(); |
ommpy | 10:0b7f23df690a | 125 | } |
ruslanbredun | 18:025d9a617769 | 126 | if (ds1820[1]->isPresent() ) { |
ruslanbredun | 18:025d9a617769 | 127 | temp_two_value = ds1820[1]->read(); |
ruslanbredun | 18:025d9a617769 | 128 | } |
ruslanbredun | 14:b3530522908e | 129 | |
ruslanbredun | 19:7935ca386e13 | 130 | Encoders(); |
ruslanbredun | 18:025d9a617769 | 131 | |
ruslanbredun | 14:b3530522908e | 132 | if(sendFlag) { |
ruslanbredun | 12:406f75196a12 | 133 | Select2 = 1; |
ruslanbredun | 19:7935ca386e13 | 134 | RS2.printf ("%d_%d_%d_%d_%d_%d_%d_%f_%f\r\n", US1_data, US2_data, US3_data, IR1_data, IR2_data, Lift_IR1, Lift_IR2, temp_one_value, temp_two_value); |
ruslanbredun | 12:406f75196a12 | 135 | wait_ms(5); |
ruslanbredun | 12:406f75196a12 | 136 | sendFlag = false; |
ruslanbredun | 12:406f75196a12 | 137 | Select2 = 0; |
ruslanbredun | 14:b3530522908e | 138 | } |
ruslanbredun | 19:7935ca386e13 | 139 | |
ruslanbredun | 18:025d9a617769 | 140 | Encoders(); |
ruslanbredun | 12:406f75196a12 | 141 | } |
ruslanbredun | 9:859bcb293e46 | 142 | } |