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

Committer:
dev_alexander
Date:
Tue Jul 24 00:38:18 2018 +0000
Revision:
29:f7a0e49b826b
Parent:
28:0ed92c590607
Child:
30:66f9750cc44c
Changed the pins that the MAX32630FTHR uses in order to communicate with the LoRa Shield. This makes the UART pins available for the BLE now.

Who changed what in which revision?

UserRevisionLine numberNew 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 29:f7a0e49b826b 24 #if defined(TARGET_MAX32630FTHR) // using the RFM95 board
dev_alexander 29:f7a0e49b826b 25 //#include "UARTService_custom.h"
dev_alexander 29:f7a0e49b826b 26 //#include "ble/BLE.h"
dev_alexander 29:f7a0e49b826b 27 //#include "ble/Gap.h"
dev_alexander 29:f7a0e49b826b 28 #include "max32630fthr.h"
dev_alexander 19:9f035b9e65ec 29 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
dev_alexander 29:f7a0e49b826b 30 #endif
Helmut64 0:c43b6919ae15 31
Helmut64 17:98f2528e8399 32 DigitalOut myled(LED);
Helmut64 0:c43b6919ae15 33
dev_alexander 28:0ed92c590607 34 Serial pc(USBTX, USBRX);
dev_alexander 25:1a031add188a 35
Helmut64 0:c43b6919ae15 36
dev_alexander 23:f74a50977593 37 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 23:f74a50977593 38 /* No grid eye object needed. The function the master uses to convert the raw
dev_alexander 23:f74a50977593 39 * data that is sent over from the slave deevice that contains the data from the
dev_alexander 23:f74a50977593 40 * actual grid eye sensor is actually a function that is not part of the grid eye
dev_alexander 23:f74a50977593 41 * class. this is due to the fact that the grid eye class requires n i2c bus to
dev_alexander 23:f74a50977593 42 * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye
dev_alexander 23:f74a50977593 43 * sensor has a support functin that is used to convert data that is aquired from
dev_alexander 23:f74a50977593 44 * the grid eye sensor. So it is not supposed to be a class specific function.
dev_alexander 23:f74a50977593 45 */
dev_alexander 23:f74a50977593 46 #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot
dev_alexander 23:f74a50977593 47 //Init I2C communications in default I2C bus I2C #1
dev_alexander 23:f74a50977593 48 I2C i2cGridEye(P3_4,P3_5);
dev_alexander 23:f74a50977593 49 GridEye gridEye(i2cGridEye);
dev_alexander 23:f74a50977593 50 #endif
dev_alexander 19:9f035b9e65ec 51
dev_alexander 23:f74a50977593 52 int main()
dev_alexander 23:f74a50977593 53 {
Helmut64 17:98f2528e8399 54 /*
Helmut64 17:98f2528e8399 55 * inits the Serial or USBSerial when available (230400 baud).
Helmut64 17:98f2528e8399 56 * If the serial uart is not is not connected it swiches to USB Serial
Helmut64 17:98f2528e8399 57 * blinking LED means USBSerial detected, waiting for a connect.
Helmut64 17:98f2528e8399 58 * It waits up to 30 seconds for a USB terminal connections
Helmut64 17:98f2528e8399 59 */
Helmut64 17:98f2528e8399 60 InitSerial(30*1000, &myled);
Helmut64 17:98f2528e8399 61 dprintf("Welcome to the SX1276GenericLib");
Helmut64 18:d5527ce82e6b 62
Helmut64 17:98f2528e8399 63 dprintf("Starting a simple LoRa PingPong");
dev_alexander 23:f74a50977593 64
dev_alexander 23:f74a50977593 65 /* Setup begins here: */
dev_alexander 25:1a031add188a 66 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 25:1a031add188a 67 dprintf("MAX32630FTHR: Master");
dev_alexander 25:1a031add188a 68 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 25:1a031add188a 69 dprintf("MAX32620FTHR: Slave");
dev_alexander 25:1a031add188a 70 #endif
dev_alexander 26:69aba05f010f 71
dev_alexander 23:f74a50977593 72
dev_alexander 23:f74a50977593 73 /***************************************************************************
dev_alexander 23:f74a50977593 74 * Grid Eye Sensor: Non-Buffer Program Variables
dev_alexander 23:f74a50977593 75 **************************************************************************/
dev_alexander 23:f74a50977593 76 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 23:f74a50977593 77 int frame_idx = 0;
dev_alexander 24:e8d03912f303 78 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 23:f74a50977593 79 // none yet
dev_alexander 25:1a031add188a 80 int frame_idx = 0;
dev_alexander 23:f74a50977593 81 #endif
dev_alexander 23:f74a50977593 82
dev_alexander 23:f74a50977593 83
dev_alexander 28:0ed92c590607 84 /***************************************************************************
dev_alexander 28:0ed92c590607 85 * Combined Payload Buffers for LoRa Communications
dev_alexander 28:0ed92c590607 86 **************************************************************************/
dev_alexander 28:0ed92c590607 87 uint8_t BufferTx[BufferSizeTx];
dev_alexander 28:0ed92c590607 88 uint8_t BufferRx[BufferSizeRx];
dev_alexander 28:0ed92c590607 89
dev_alexander 28:0ed92c590607 90 /***************************************************************************
dev_alexander 28:0ed92c590607 91 * BLE Data Buffers
dev_alexander 28:0ed92c590607 92 **************************************************************************/
dev_alexander 28:0ed92c590607 93 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 94 uint8_t curr_ble_to_slave[size_of_ble];
dev_alexander 28:0ed92c590607 95 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 96 uint8_t curr_ble_from_master[size_of_ble];
dev_alexander 28:0ed92c590607 97 uint8_t prev_ble_from_master[size_of_ble];
dev_alexander 28:0ed92c590607 98 #endif
dev_alexander 28:0ed92c590607 99
dev_alexander 28:0ed92c590607 100 /***************************************************************************
dev_alexander 28:0ed92c590607 101 * Grid Eye Sensor Data Buffers
dev_alexander 28:0ed92c590607 102 **************************************************************************/
dev_alexander 28:0ed92c590607 103 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 104 char curr_raw_frame_from_slave[size_of_grid_eye];
dev_alexander 28:0ed92c590607 105 char prev_raw_frame_from_slave[size_of_grid_eye];
dev_alexander 28:0ed92c590607 106 int16_t conv_frame_from_slave[64];
dev_alexander 28:0ed92c590607 107 #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 108 char curr_raw_frame_to_master[size_of_grid_eye];
dev_alexander 28:0ed92c590607 109 char prev_raw_frame_to_master[size_of_grid_eye];
dev_alexander 28:0ed92c590607 110 int16_t conv_frame_to_master[64];
dev_alexander 28:0ed92c590607 111 #endif
dev_alexander 28:0ed92c590607 112
dev_alexander 28:0ed92c590607 113 /***************************************************************************
dev_alexander 28:0ed92c590607 114 * GPS Data Buffers
dev_alexander 28:0ed92c590607 115 **************************************************************************/
dev_alexander 28:0ed92c590607 116 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 117 uint8_t curr_gps_from_slave[size_of_gps];
dev_alexander 28:0ed92c590607 118 uint8_t prev_gps_from_slave[size_of_gps];
dev_alexander 28:0ed92c590607 119 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 120 uint8_t curr_gps_to_master[size_of_gps];
dev_alexander 28:0ed92c590607 121 #endif
dev_alexander 28:0ed92c590607 122
dev_alexander 28:0ed92c590607 123 /***************************************************************************
dev_alexander 28:0ed92c590607 124 * MAX17055 Data Buffers
dev_alexander 28:0ed92c590607 125 **************************************************************************/
dev_alexander 28:0ed92c590607 126 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 127 uint8_t curr_MAX17055_from_slave[size_of_MAX17055];
dev_alexander 28:0ed92c590607 128 uint8_t prev_MAX17055_from_slave[size_of_MAX17055];
dev_alexander 28:0ed92c590607 129 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 130 uint8_t curr_MAX17055_to_master[size_of_MAX17055];
dev_alexander 28:0ed92c590607 131 #endif
dev_alexander 28:0ed92c590607 132
dev_alexander 28:0ed92c590607 133 /***************************************************************************
dev_alexander 28:0ed92c590607 134 * MAX77650 Data Buffers
dev_alexander 28:0ed92c590607 135 **************************************************************************/
dev_alexander 28:0ed92c590607 136 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 137 uint8_t curr_MAX77650_from_slave[size_of_MAX77650];
dev_alexander 28:0ed92c590607 138 uint8_t prev_MAX77650_from_slave[size_of_MAX77650];
dev_alexander 28:0ed92c590607 139 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 140 uint8_t curr_MAX77650_to_master[size_of_MAX77650];
dev_alexander 28:0ed92c590607 141 #endif
dev_alexander 28:0ed92c590607 142
dev_alexander 28:0ed92c590607 143 /***************************************************************************
dev_alexander 28:0ed92c590607 144 * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send
dev_alexander 28:0ed92c590607 145 **************************************************************************/
dev_alexander 28:0ed92c590607 146 SX1276PingPongSetup(BufferTx, BufferRx);
dev_alexander 28:0ed92c590607 147
dev_alexander 22:abca9d17d13d 148 while(1)
dev_alexander 28:0ed92c590607 149 {
dev_alexander 23:f74a50977593 150 /***************************************************************************
dev_alexander 23:f74a50977593 151 * Grid Eye Sensor
dev_alexander 23:f74a50977593 152 **************************************************************************/
dev_alexander 23:f74a50977593 153 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 154 // Check to see if the contents of the previous scan are the same. If they are different then continue with converting
dev_alexander 28:0ed92c590607 155 if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 )
dev_alexander 27:6b549f838f0a 156 {
dev_alexander 23:f74a50977593 157 // Convert raw data sent from slave to a 16 bit integer array by calling this
dev_alexander 28:0ed92c590607 158 convRaw8x8Data2Point25degC(curr_raw_frame_from_slave, conv_frame_from_slave);
dev_alexander 26:69aba05f010f 159
dev_alexander 23:f74a50977593 160 // Next Print off the Converted data
dev_alexander 26:69aba05f010f 161 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
dev_alexander 23:f74a50977593 162 uint8_t idx;
dev_alexander 23:f74a50977593 163 float pixel_data;
dev_alexander 23:f74a50977593 164 for (int y = 0; y < 8; y++) {
dev_alexander 23:f74a50977593 165 for (int x = 0; x < 8; x++) {
dev_alexander 23:f74a50977593 166 idx = y*8 + x;
dev_alexander 28:0ed92c590607 167 pixel_data = ((float)conv_frame_from_slave[idx])/4.0;
dev_alexander 26:69aba05f010f 168 pc.printf("%.2f \t", pixel_data);
dev_alexander 23:f74a50977593 169 }
dev_alexander 26:69aba05f010f 170 pc.printf("\r\n\r\n");
dev_alexander 23:f74a50977593 171 }
dev_alexander 26:69aba05f010f 172 pc.printf("\r\n");
dev_alexander 23:f74a50977593 173
dev_alexander 23:f74a50977593 174 // Increment frame counter
dev_alexander 23:f74a50977593 175 frame_idx = frame_idx +1;
dev_alexander 27:6b549f838f0a 176 }
dev_alexander 28:0ed92c590607 177
dev_alexander 25:1a031add188a 178 /* Next copy in data received from current data into buffer used for
dev_alexander 25:1a031add188a 179 * comparison next time the memcmp above is called. This prevents the
dev_alexander 25:1a031add188a 180 * program from converting the same raw data aquired by the grid eye
dev_alexander 25:1a031add188a 181 * sensor on the slave device to the floating point array with the
dev_alexander 25:1a031add188a 182 * 0.25 degrees celsius precision level when there is not new data.
dev_alexander 25:1a031add188a 183 */
dev_alexander 28:0ed92c590607 184 memcpy(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave));
dev_alexander 25:1a031add188a 185
dev_alexander 24:e8d03912f303 186 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 23:f74a50977593 187 // Aquire raw data about 8x8 frame from the grid eye sensor in this function call
dev_alexander 28:0ed92c590607 188 gridEye.getRaw8x8FrameData(curr_raw_frame_to_master);
dev_alexander 28:0ed92c590607 189 wait_ms( 10 );
dev_alexander 28:0ed92c590607 190 /*
dev_alexander 28:0ed92c590607 191 //if ( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 )
dev_alexander 28:0ed92c590607 192 //{
dev_alexander 25:1a031add188a 193 // Convert raw data sent from slave to a 16 bit integer array by calling this
dev_alexander 28:0ed92c590607 194 convRaw8x8Data2Point25degC(curr_raw_frame_to_master, conv_frame_to_master);
dev_alexander 25:1a031add188a 195
dev_alexander 25:1a031add188a 196 // Next Print off the Converted data
dev_alexander 25:1a031add188a 197 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
dev_alexander 25:1a031add188a 198 uint8_t idx;
dev_alexander 25:1a031add188a 199 float pixel_data;
dev_alexander 25:1a031add188a 200 for (int y = 0; y < 8; y++) {
dev_alexander 25:1a031add188a 201 for (int x = 0; x < 8; x++) {
dev_alexander 25:1a031add188a 202 idx = y*8 + x;
dev_alexander 28:0ed92c590607 203 pixel_data = conv_frame_to_master[idx]/4.0;
dev_alexander 25:1a031add188a 204 pc.printf("%.2f \t", pixel_data);
dev_alexander 25:1a031add188a 205 }
dev_alexander 25:1a031add188a 206 pc.printf("\r\n\r\n");
dev_alexander 25:1a031add188a 207 }
dev_alexander 25:1a031add188a 208 pc.printf("\r\n");
dev_alexander 25:1a031add188a 209
dev_alexander 25:1a031add188a 210 // Increment frame counter
dev_alexander 25:1a031add188a 211 frame_idx = frame_idx +1;
dev_alexander 28:0ed92c590607 212 //}
dev_alexander 28:0ed92c590607 213 */
dev_alexander 28:0ed92c590607 214 memcpy(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master));
dev_alexander 23:f74a50977593 215 #endif
dev_alexander 28:0ed92c590607 216
dev_alexander 28:0ed92c590607 217
dev_alexander 23:f74a50977593 218 /***************************************************************************
dev_alexander 28:0ed92c590607 219 * Fill Payload Buffer With Data From Sensors for LoRa Transmition
dev_alexander 28:0ed92c590607 220 **************************************************************************/
dev_alexander 28:0ed92c590607 221 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 222 memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature);
dev_alexander 28:0ed92c590607 223 memcpy(&BufferTx[tx_idx_ble], curr_ble_to_slave, size_of_ble);
dev_alexander 28:0ed92c590607 224 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 225 memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature);
dev_alexander 28:0ed92c590607 226 memcpy(&BufferTx[tx_idx_grid_eye], curr_raw_frame_to_master, size_of_grid_eye);
dev_alexander 28:0ed92c590607 227 memcpy(&BufferTx[tx_idx_gps], curr_gps_to_master, size_of_gps);
dev_alexander 28:0ed92c590607 228 memcpy(&BufferTx[tx_idx_MAX17055], curr_MAX17055_to_master, size_of_MAX17055);
dev_alexander 28:0ed92c590607 229 memcpy(&BufferTx[tx_idx_MAX77650], curr_MAX77650_to_master, size_of_MAX77650);
dev_alexander 28:0ed92c590607 230 #endif
dev_alexander 28:0ed92c590607 231
dev_alexander 28:0ed92c590607 232
dev_alexander 28:0ed92c590607 233
dev_alexander 28:0ed92c590607 234 /***************************************************************************
dev_alexander 28:0ed92c590607 235 * Lora Communications
dev_alexander 28:0ed92c590607 236 **************************************************************************/
dev_alexander 25:1a031add188a 237 wait_ms( 10 );
dev_alexander 22:abca9d17d13d 238 SX1276PingPong();
dev_alexander 28:0ed92c590607 239
dev_alexander 28:0ed92c590607 240 /***************************************************************************
dev_alexander 28:0ed92c590607 241 * Fill Global Buffers With Data From Received Payload Buffer
dev_alexander 28:0ed92c590607 242 **************************************************************************/
dev_alexander 28:0ed92c590607 243 /* The master and slave devices will have different requirements for offloading payload */
dev_alexander 28:0ed92c590607 244 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 245 memcpy(curr_raw_frame_from_slave, &BufferRx[rx_idx_grid_eye], size_of_grid_eye);
dev_alexander 28:0ed92c590607 246 memcpy(curr_gps_from_slave, &BufferRx[rx_idx_gps], size_of_gps);
dev_alexander 28:0ed92c590607 247 memcpy(curr_MAX17055_from_slave, &BufferRx[rx_idx_MAX17055], size_of_MAX17055);
dev_alexander 28:0ed92c590607 248 memcpy(curr_MAX77650_from_slave, &BufferRx[rx_idx_MAX77650], size_of_MAX77650);
dev_alexander 28:0ed92c590607 249 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 250 memcpy(curr_ble_from_master, &BufferRx[rx_idx_ble], size_of_ble);
dev_alexander 28:0ed92c590607 251 #endif
dev_alexander 23:f74a50977593 252
dev_alexander 23:f74a50977593 253
dev_alexander 23:f74a50977593 254
dev_alexander 23:f74a50977593 255
dev_alexander 23:f74a50977593 256
dev_alexander 22:abca9d17d13d 257 }
dev_alexander 22:abca9d17d13d 258
Helmut64 0:c43b6919ae15 259 }