Robot team project
Dependencies: QEI Motordriver ros_lib_melodic
main.cpp@4:cb50c6fa340b, 2019-10-22 (annotated)
- Committer:
- florine_van
- Date:
- Tue Oct 22 11:52:32 2019 +0000
- Revision:
- 4:cb50c6fa340b
- Parent:
- 3:a3144a45f44c
- Child:
- 5:8ef79eebbc97
Use float instead of integer for sensor readings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
florine_van | 0:57855aafa907 | 1 | #include "mbed.h" |
florine_van | 0:57855aafa907 | 2 | #include "Sensor.h" |
florine_van | 0:57855aafa907 | 3 | |
florine_van | 0:57855aafa907 | 4 | // Set up serial to pc |
florine_van | 0:57855aafa907 | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
florine_van | 0:57855aafa907 | 6 | |
florine_van | 0:57855aafa907 | 7 | // Set up I²C on the STM32 NUCLEO-401RE |
florine_van | 0:57855aafa907 | 8 | #define addr1 (0x29) |
florine_van | 0:57855aafa907 | 9 | #define addr2 (0x2A) |
florine_van | 0:57855aafa907 | 10 | #define addr3 (0x2B) |
florine_van | 0:57855aafa907 | 11 | #define addr4 (0x2C) |
florine_van | 0:57855aafa907 | 12 | |
florine_van | 0:57855aafa907 | 13 | int main() { |
florine_van | 0:57855aafa907 | 14 | int range1; |
florine_van | 1:d5adc483bce0 | 15 | int range2; |
florine_van | 2:c537f1ebad7b | 16 | int range3; |
florine_van | 2:c537f1ebad7b | 17 | int range4; |
florine_van | 0:57855aafa907 | 18 | |
florine_van | 2:c537f1ebad7b | 19 | // Create sensors |
florine_van | 1:d5adc483bce0 | 20 | Sensor sensor1(I2C_SDA, I2C_SCL, PC_9); |
florine_van | 1:d5adc483bce0 | 21 | Sensor sensor2(I2C_SDA, I2C_SCL, PC_11); |
florine_van | 2:c537f1ebad7b | 22 | Sensor sensor3(I2C_SDA, I2C_SCL, PD_2); |
florine_van | 2:c537f1ebad7b | 23 | Sensor sensor4(I2C_SDA, I2C_SCL, PG_3); |
florine_van | 3:a3144a45f44c | 24 | |
florine_van | 3:a3144a45f44c | 25 | // load settings onto VL6180X sensors |
florine_van | 1:d5adc483bce0 | 26 | sensor2.init(); |
florine_van | 3:a3144a45f44c | 27 | // change default address of sensor 2 |
florine_van | 2:c537f1ebad7b | 28 | sensor2.changeAddress(addr2); |
florine_van | 2:c537f1ebad7b | 29 | |
florine_van | 1:d5adc483bce0 | 30 | sensor3.init(); |
florine_van | 3:a3144a45f44c | 31 | // change default address of sensor 3 |
florine_van | 2:c537f1ebad7b | 32 | sensor3.changeAddress(addr3); |
florine_van | 2:c537f1ebad7b | 33 | |
florine_van | 1:d5adc483bce0 | 34 | sensor4.init(); |
florine_van | 3:a3144a45f44c | 35 | // change default address of sensor 4 |
florine_van | 2:c537f1ebad7b | 36 | sensor4.changeAddress(addr4); |
florine_van | 2:c537f1ebad7b | 37 | |
florine_van | 1:d5adc483bce0 | 38 | sensor1.init(); |
florine_van | 0:57855aafa907 | 39 | |
florine_van | 0:57855aafa907 | 40 | while (1) |
florine_van | 0:57855aafa907 | 41 | { |
florine_van | 0:57855aafa907 | 42 | range1 = sensor1.read(); |
florine_van | 0:57855aafa907 | 43 | range2 = sensor2.read(); |
florine_van | 2:c537f1ebad7b | 44 | range3 = sensor3.read(); |
florine_van | 2:c537f1ebad7b | 45 | range4 = sensor4.read(); |
florine_van | 0:57855aafa907 | 46 | |
florine_van | 0:57855aafa907 | 47 | pc.printf("Range one = %d | range two = %d | range three = %d | range four = %d\r\n",range1, range2, range3, range4); |
florine_van | 4:cb50c6fa340b | 48 | wait_ms(10); |
florine_van | 0:57855aafa907 | 49 | } |
florine_van | 0:57855aafa907 | 50 | } |
florine_van | 0:57855aafa907 | 51 |