LP Long Distance IR Vision Robot
Dependencies: max77650_charger_sample BufferedSerial SX1276GenericLib Adafruit-MotorShield NEO-6m-GPS MAX17055_EZconfig Adafruit_GFX USBDeviceHT Adafruit-PWM-Servo-Driver
main.cpp@23:f74a50977593, 2018-07-18 (annotated)
- Committer:
- dev_alexander
- Date:
- Wed Jul 18 18:52:30 2018 +0000
- Revision:
- 23:f74a50977593
- Parent:
- 22:abca9d17d13d
- Child:
- 24:e8d03912f303
I added file global_buffers.h and also reworked a portion of the main.cpp to adjust to the new method of using global buffers defined in a different file.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:c43b6919ae15 | 1 | /* |
Helmut64 | 17:98f2528e8399 | 2 | * Copyright (c) 2018 HELIOS Software GmbH |
Helmut64 | 0:c43b6919ae15 | 3 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 0:c43b6919ae15 | 4 | * Licensed under the Apache License, Version 2.0); |
Helmut64 | 0:c43b6919ae15 | 5 | */ |
dev_alexander | 21:1b92cabe8a3b | 6 | |
dev_alexander | 21:1b92cabe8a3b | 7 | /* |
dev_alexander | 21:1b92cabe8a3b | 8 | * For Wiring Instructions, please visit the link below: |
dev_alexander | 21:1b92cabe8a3b | 9 | * https://www.hackster.io/DevinAlex64/getting-started-with-the-max32620fthr-and-lora-f9d8dd\ |
dev_alexander | 21:1b92cabe8a3b | 10 | */ |
dev_alexander | 21:1b92cabe8a3b | 11 | |
Helmut64 | 0:c43b6919ae15 | 12 | #include "main.h" |
dev_alexander | 23:f74a50977593 | 13 | #include "global_buffers.h" |
dev_alexander | 23:f74a50977593 | 14 | #include "GridEye.h" |
Helmut64 | 0:c43b6919ae15 | 15 | |
dev_alexander | 23:f74a50977593 | 16 | |
dev_alexander | 23:f74a50977593 | 17 | /* If the board that is compiled is the master device (BLE enabled MAX32630FTHR), |
dev_alexander | 23:f74a50977593 | 18 | * then it needs this library and needs to be configed in order for the device to |
dev_alexander | 23:f74a50977593 | 19 | * work with a 3.3volt output instead of a 1.8 volt output. |
dev_alexander | 23:f74a50977593 | 20 | * |
dev_alexander | 23:f74a50977593 | 21 | * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this |
dev_alexander | 23:f74a50977593 | 22 | * additional setup in the main program. |
dev_alexander | 23:f74a50977593 | 23 | */ |
dev_alexander | 19:9f035b9e65ec | 24 | #if defined(TARGET_MAX32630FTHR) // using the RFM95 board |
dev_alexander | 19:9f035b9e65ec | 25 | #include "max32630fthr.h" |
dev_alexander | 19:9f035b9e65ec | 26 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
dev_alexander | 19:9f035b9e65ec | 27 | #endif |
Helmut64 | 0:c43b6919ae15 | 28 | |
Helmut64 | 17:98f2528e8399 | 29 | DigitalOut myled(LED); |
Helmut64 | 0:c43b6919ae15 | 30 | |
Helmut64 | 0:c43b6919ae15 | 31 | |
dev_alexander | 23:f74a50977593 | 32 | #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 33 | /* No grid eye object needed. The function the master uses to convert the raw |
dev_alexander | 23:f74a50977593 | 34 | * data that is sent over from the slave deevice that contains the data from the |
dev_alexander | 23:f74a50977593 | 35 | * actual grid eye sensor is actually a function that is not part of the grid eye |
dev_alexander | 23:f74a50977593 | 36 | * class. this is due to the fact that the grid eye class requires n i2c bus to |
dev_alexander | 23:f74a50977593 | 37 | * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye |
dev_alexander | 23:f74a50977593 | 38 | * sensor has a support functin that is used to convert data that is aquired from |
dev_alexander | 23:f74a50977593 | 39 | * the grid eye sensor. So it is not supposed to be a class specific function. |
dev_alexander | 23:f74a50977593 | 40 | */ |
dev_alexander | 23:f74a50977593 | 41 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot |
dev_alexander | 23:f74a50977593 | 42 | //Init I2C communications in default I2C bus I2C #1 |
dev_alexander | 23:f74a50977593 | 43 | I2C i2cGridEye(P3_4,P3_5); |
dev_alexander | 23:f74a50977593 | 44 | GridEye gridEye(i2cGridEye); |
dev_alexander | 23:f74a50977593 | 45 | #endif |
dev_alexander | 19:9f035b9e65ec | 46 | |
dev_alexander | 23:f74a50977593 | 47 | int main() |
dev_alexander | 23:f74a50977593 | 48 | { |
Helmut64 | 17:98f2528e8399 | 49 | /* |
Helmut64 | 17:98f2528e8399 | 50 | * inits the Serial or USBSerial when available (230400 baud). |
Helmut64 | 17:98f2528e8399 | 51 | * If the serial uart is not is not connected it swiches to USB Serial |
Helmut64 | 17:98f2528e8399 | 52 | * blinking LED means USBSerial detected, waiting for a connect. |
Helmut64 | 17:98f2528e8399 | 53 | * It waits up to 30 seconds for a USB terminal connections |
Helmut64 | 17:98f2528e8399 | 54 | */ |
Helmut64 | 17:98f2528e8399 | 55 | InitSerial(30*1000, &myled); |
Helmut64 | 17:98f2528e8399 | 56 | dprintf("Welcome to the SX1276GenericLib"); |
Helmut64 | 18:d5527ce82e6b | 57 | |
Helmut64 | 17:98f2528e8399 | 58 | dprintf("Starting a simple LoRa PingPong"); |
dev_alexander | 23:f74a50977593 | 59 | |
dev_alexander | 23:f74a50977593 | 60 | /* Setup begins here: */ |
dev_alexander | 23:f74a50977593 | 61 | |
dev_alexander | 23:f74a50977593 | 62 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 63 | * Lora Communications |
dev_alexander | 23:f74a50977593 | 64 | **************************************************************************/ |
dev_alexander | 22:abca9d17d13d | 65 | SX1276PingPongSetup(); |
dev_alexander | 23:f74a50977593 | 66 | |
dev_alexander | 23:f74a50977593 | 67 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 68 | * Grid Eye Sensor: Non-Buffer Program Variables |
dev_alexander | 23:f74a50977593 | 69 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 70 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 71 | int frame_idx = 0; |
dev_alexander | 23:f74a50977593 | 72 | #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 73 | // none yet |
dev_alexander | 23:f74a50977593 | 74 | #endif |
dev_alexander | 23:f74a50977593 | 75 | |
dev_alexander | 23:f74a50977593 | 76 | |
dev_alexander | 22:abca9d17d13d | 77 | while(1) |
dev_alexander | 23:f74a50977593 | 78 | { |
dev_alexander | 23:f74a50977593 | 79 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 80 | * Grid Eye Sensor |
dev_alexander | 23:f74a50977593 | 81 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 82 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 83 | |
dev_alexander | 23:f74a50977593 | 84 | // Check to see if the contents of the previous scan are the same. If they are different then continue with converting |
dev_alexander | 23:f74a50977593 | 85 | if( memcmp(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave)) != 0 ) |
dev_alexander | 23:f74a50977593 | 86 | { |
dev_alexander | 23:f74a50977593 | 87 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 23:f74a50977593 | 88 | convRaw8x8Data2Point25degC(curr_raw_frame_data_from_slave, conv_frame_data_from_slave); |
dev_alexander | 23:f74a50977593 | 89 | |
dev_alexander | 23:f74a50977593 | 90 | // Next Print off the Converted data |
dev_alexander | 23:f74a50977593 | 91 | dprintf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 23:f74a50977593 | 92 | uint8_t idx; |
dev_alexander | 23:f74a50977593 | 93 | float pixel_data; |
dev_alexander | 23:f74a50977593 | 94 | for (int y = 0; y < 8; y++) { |
dev_alexander | 23:f74a50977593 | 95 | for (int x = 0; x < 8; x++) { |
dev_alexander | 23:f74a50977593 | 96 | idx = y*8 + x; |
dev_alexander | 23:f74a50977593 | 97 | pixel_data = conv_frame_data_from_slave[idx]/4.0; |
dev_alexander | 23:f74a50977593 | 98 | dprintf("%.2f \t", pixel_data); |
dev_alexander | 23:f74a50977593 | 99 | } |
dev_alexander | 23:f74a50977593 | 100 | dprintf("\r\n\r\n"); |
dev_alexander | 23:f74a50977593 | 101 | } |
dev_alexander | 23:f74a50977593 | 102 | dprintf("\r\n"); |
dev_alexander | 23:f74a50977593 | 103 | |
dev_alexander | 23:f74a50977593 | 104 | // Increment frame counter |
dev_alexander | 23:f74a50977593 | 105 | frame_idx = frame_idx +1; |
dev_alexander | 23:f74a50977593 | 106 | } |
dev_alexander | 23:f74a50977593 | 107 | |
dev_alexander | 23:f74a50977593 | 108 | #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 109 | // Aquire raw data about 8x8 frame from the grid eye sensor in this function call |
dev_alexander | 23:f74a50977593 | 110 | gridEye.getRaw8x8FrameData(curr_raw_frame_data_to_master); |
dev_alexander | 23:f74a50977593 | 111 | |
dev_alexander | 23:f74a50977593 | 112 | #endif |
dev_alexander | 23:f74a50977593 | 113 | |
dev_alexander | 23:f74a50977593 | 114 | |
dev_alexander | 23:f74a50977593 | 115 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 116 | * Lora Communications |
dev_alexander | 23:f74a50977593 | 117 | **************************************************************************/ |
dev_alexander | 22:abca9d17d13d | 118 | SX1276PingPong(); |
dev_alexander | 23:f74a50977593 | 119 | |
dev_alexander | 23:f74a50977593 | 120 | |
dev_alexander | 23:f74a50977593 | 121 | |
dev_alexander | 23:f74a50977593 | 122 | |
dev_alexander | 23:f74a50977593 | 123 | |
dev_alexander | 22:abca9d17d13d | 124 | } |
dev_alexander | 22:abca9d17d13d | 125 | |
Helmut64 | 0:c43b6919ae15 | 126 | } |