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:
Fri Jul 20 21:29:53 2018 +0000
Revision:
27:6b549f838f0a
Parent:
26:69aba05f010f
Child:
28:0ed92c590607
Trying to unify how the buffers were loaded and unloaded seemed to have broke how the buffer on the MAX32630FTHR. It was working much better when the buffers were loaded in the main(). I am probably going to revert to the previous method.

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