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
Revision 25:1a031add188a, committed 2018-07-19
- Comitter:
- dev_alexander
- Date:
- Thu Jul 19 21:13:19 2018 +0000
- Parent:
- 24:e8d03912f303
- Child:
- 26:69aba05f010f
- Commit message:
- Got messages of different sizes to send to each other. Changed maximum number of bytes per payload to a max value of 255 for more sensor data to be added. Also began debugging the grid eye sensor data acquisition issue.
Changed in this revision
--- a/PinMap.h Wed Jul 18 21:25:17 2018 +0000 +++ b/PinMap.h Thu Jul 19 21:13:19 2018 +0000 @@ -123,9 +123,12 @@ #define LORA_SPI_MISO P5_2 #define LORA_SPI_SCLK P5_0 // This is because the Server uses different pins - #define LORA_CS P5_3 - #define LORA_RESET P5_4 - #define LORA_DIO0 P5_5 // DIO0=TxDone/RXDone/CADDone +// #define LORA_CS P5_3 +// #define LORA_RESET P5_4 +// #define LORA_DIO0 P5_5 // DIO0=TxDone/RXDone/CADDone + #define LORA_CS P3_0 + #define LORA_RESET P3_1 + #define LORA_DIO0 P3_2 // DIO0=TxDone/RXDone/CADDone #define LORA_DIO1 NC // #define LORA_DIO2 NC // #define LORA_DIO3 NC //
--- a/SX1276GenericPingPong/GenericPingPong.cpp Wed Jul 18 21:25:17 2018 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Thu Jul 19 21:13:19 2018 +0000 @@ -87,10 +87,6 @@ */ SX1276Generic *Radio; - -const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING"; -const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG"; - /* determine the appropriate buffer sizes */ #if defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE; @@ -106,7 +102,7 @@ DigitalOut *led3; -int SX1276PingPongSetup(void) +uint8_t * SX1276PingPongSetup(void) { dprintf("TEST" ); #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) @@ -187,6 +183,10 @@ dprintf(" > LORA FHSS Mode <"); if (!LORA_FHSS_ENABLED) dprintf(" > LORA Mode <"); + + + // Without this line, the default max payload length is only 64 bytes + Radio->SetMaxPayloadLength(MODEM_LORA, 255); Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, LORA_CODINGRATE, @@ -224,8 +224,13 @@ Radio->Rx( RX_TIMEOUT_VALUE ); + + return BufferTx; } +/**************************************************************************************************************************************** + * + ****************************************************************************************************************************************/ int SX1276PingPong(void) { uint8_t i; @@ -234,7 +239,7 @@ #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot bool isMaster = false; #endif - + switch( State ) { case RX: @@ -243,17 +248,21 @@ { if( BufferSizeRx > 0 ) { - if( memcmp(BufferRx, PongMsg, sizeof(PongMsg)) == 0 ) + if( memcmp(&BufferRx[rx_idx_signature], PongMsg, sizeof(PongMsg)) == 0 ) { // *led = !*led; dprintf( "...Pong" ); // Send the next PING frame - memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +// memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +/* // We fill the buffer with numbers for the payload for( i = sizeof(PingMsg); i < BufferSizeTx; i++ ) { BufferTx[i] = i - sizeof(PingMsg); } +*/ + /* Construct the payload buffer so data can be transmited. */ + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -289,12 +298,15 @@ // *led = !*led; dprintf( "...Ping" ); // Send the reply to the PING string - memcpy(BufferTx, PongMsg, sizeof(PongMsg)); +// memcpy(BufferTx, PongMsg, sizeof(PongMsg)); +/* // We fill the buffer with numbers for the payload for( i = sizeof(PongMsg); i < BufferSizeTx; i++ ) { BufferTx[i] = i - sizeof(PongMsg); } +*/ + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -324,11 +336,14 @@ if( isMaster == true ) { // Send the next PING frame - memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +// memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +/* for( i = sizeof(PingMsg); i < BufferSizeTx; i++ ) { BufferTx[i] = i - sizeof(PingMsg); } +*/ + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -344,21 +359,27 @@ { // Send the next PING frame memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +/* for( i = 4; i < BufferSizeTx; i++ ) { BufferTx[i] = i - 4; } +*/ + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } else { // Send the next PONG frame - memcpy(BufferTx, PongMsg, sizeof(PongMsg)); +// memcpy(BufferTx, PongMsg, sizeof(PongMsg)); +/* for( i = sizeof(PongMsg); i < BufferSizeTx; i++ ) { BufferTx[i] = i - sizeof(PongMsg); } +*/ + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -380,7 +401,7 @@ void OnTxDone(void *radio, void *userThisPtr, void *userData) { Radio->Sleep( ); - State = TX; + State = TX; if (DEBUG_MESSAGE) dprintf("> OnTxDone"); } @@ -391,6 +412,10 @@ BufferSizeRx = size; memcpy( BufferRx, payload, BufferSizeRx ); State = RX; + + // Call function that deconstructs payload + fillGlobalBufsWithPayload(payload); + if (DEBUG_MESSAGE) dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr); dump("Data:", payload, size);
--- a/SX1276GenericPingPong/GenericPingPong.h Wed Jul 18 21:25:17 2018 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.h Thu Jul 19 21:13:19 2018 +0000 @@ -31,7 +31,14 @@ #endif */ -int SX1276PingPongSetup(void); + + +const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING"; +const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG"; + + + +uint8_t * SX1276PingPongSetup(void); int SX1276PingPong(void);
--- a/global_buffers.cpp Wed Jul 18 21:25:17 2018 +0000 +++ b/global_buffers.cpp Thu Jul 19 21:13:19 2018 +0000 @@ -1,36 +1,44 @@ /* Devin Alexander * July 18, 2018 */ - -#include "mbed.h" + #include "global_buffers.h" - + + /** * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message */ -int fillPayloadWithGlobalBufs(uint8_t * payload_buffer) +void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx) { /* The master and slave devices will have different requirements for creating payload */ #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway - // none yet + memcpy(&payload_buffer_tx[tx_idx_signature], PingMsg, size_signature); + memcpy(&payload_buffer_tx[tx_idx_ble], curr_ble_data_to_slave, size_of_ble); #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot - // none yet + memcpy(&payload_buffer_tx[tx_idx_signature], PongMsg, size_signature); + memcpy(&payload_buffer_tx[tx_idx_grid_eye], curr_raw_frame_data_to_master, size_of_grid_eye); + memcpy(&payload_buffer_tx[tx_idx_gps], curr_gps_data_to_master, size_of_gps); + memcpy(&payload_buffer_tx[tx_idx_MAX17055], curr_MAX17055_to_master, size_of_MAX17055); + memcpy(&payload_buffer_tx[tx_idx_MAX77650], curr_MAX77650_to_master, size_of_MAX77650); #endif - return 0; + return; } /** * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message */ -int fillGlobalBufsWithPayload(uint8_t * payload_buffer) +void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx) { /* The master and slave devices will have different requirements for offloading payload */ #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway - // none yet + memcpy(curr_raw_frame_data_from_slave, &payload_buffer_rx[rx_idx_grid_eye], size_of_grid_eye); + memcpy(curr_gps_data_from_slave, &payload_buffer_rx[rx_idx_gps], size_of_gps); + memcpy(curr_MAX17055_from_slave, &payload_buffer_rx[rx_idx_MAX17055], size_of_MAX17055); + memcpy(curr_MAX77650_from_slave, &payload_buffer_rx[rx_idx_MAX77650], size_of_MAX77650); #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot - // none yet + memcpy(curr_ble_data_from_master, &payload_buffer_rx[rx_idx_ble], size_of_ble); #endif - return 0; + return; }
--- a/global_buffers.h Wed Jul 18 21:25:17 2018 +0000 +++ b/global_buffers.h Thu Jul 19 21:13:19 2018 +0000 @@ -19,76 +19,123 @@ */ #ifndef __GLOBAL_BUFFERS_H__ -#define __GLOBAL_BUFFERS_H__ +#define __GLOBAL_BUFFERS_H__\ + +#include "mbed.h" +#include "GenericPingPong.h" + /*************************************************************************** * Indexes for which byte specific data begins at in the payload buffer **************************************************************************/ +/* size of ID data that defines what the signature of the device is */ +const uint8_t size_signature = 8; /* size of data in bytes that is acquired by the master device */ -const uint8_t size_of_ble = 2; +const uint8_t size_of_ble = 2; + /* size of data in bytes that is acquired by the slave device */ const uint8_t size_of_grid_eye = 128; const uint8_t size_of_gps = 20; const uint8_t size_of_MAX17055 = 5; const uint8_t size_of_MAX77650 = 5; -const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_of_ble; -const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_of_grid_eye + size_of_gps + size_of_MAX17055 + size_of_MAX77650; +/* These are the sizes of each payload in bytes. Since there is different amount + * of data being sent in each direction, we need to declare the total size of + * the payload so we can instatiate the correct buffer sizes to store data that + * is to be delivered and for data that is received. + */ + +const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature + size_of_ble; +const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_signature + size_of_grid_eye + size_of_gps + size_of_MAX17055 + size_of_MAX77650; #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway /* These are indexs used to create the payload buffer to send to Slave */ - const uint8_t tx_idx_ble = 0; // 1st buf in tx payload (begins at byte 0) + const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0) + const uint8_t tx_idx_ble = tx_idx_signature + size_signature; // 2nd buf in tx payload - /* These are indexs used to deconstruct received payload buffer sent by the Slave */ - const uint8_t rx_idx_grid_eye = 0; // 1st buf in rx payload (begins at byte 0) - const uint8_t rx_idx_gps = rx_idx_grid_eye + size_of_grid_eye; // 2nd buf in rx payload - const uint8_t rx_idx_MAX17055 = rx_idx_gps + size_of_gps; // 3rd buf in rx payload - const uint8_t rx_idx_MAX77650 = rx_idx_MAX17055 + size_of_MAX17055; // 4th buf in rx payload + /* These are indexs used to deconstruct received payload buffer sent by the Slave */ + const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0) + const uint8_t rx_idx_grid_eye = rx_idx_signature + size_signature; // 2nd buf in rx payload + const uint8_t rx_idx_gps = rx_idx_grid_eye + size_of_grid_eye; // 3rd buf in rx payload + const uint8_t rx_idx_MAX17055 = rx_idx_gps + size_of_gps; // 4th buf in rx payload + const uint8_t rx_idx_MAX77650 = rx_idx_MAX17055 + size_of_MAX17055; // 5th buf in rx payload #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot - /* These are indexs used to create the payload buffer to send to Master */ - const uint8_t tx_idx_grid_eye = 0; // 1st buf in tx payload (begins at byte 0) - const uint8_t tx_idx_gps = tx_idx_grid_eye + size_of_grid_eye; // 2nd buf in tx payload - const uint8_t tx_idx_MAX17055 = tx_idx_gps + size_of_gps; // 3rd buf in tx payload - const uint8_t tx_idx_MAX77650 = tx_idx_MAX17055 + size_of_MAX17055; // 4th buf in tx payload + const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0) + const uint8_t tx_idx_grid_eye = tx_idx_signature + size_signature; // 2nd buf in tx payload + const uint8_t tx_idx_gps = tx_idx_grid_eye + size_of_grid_eye; // 3rd buf in tx payload + const uint8_t tx_idx_MAX17055 = tx_idx_gps + size_of_gps; // 4th buf in tx payload + const uint8_t tx_idx_MAX77650 = tx_idx_MAX17055 + size_of_MAX17055; // 5th buf in tx payload /* These are indexs used to deconstruct received payload buffer sent by the Master */ - const uint8_t rx_idx_ble = 0; // 1st buf in rx payload (begins at byte 0) + const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0) + const uint8_t rx_idx_ble = rx_idx_signature + size_signature; // 2nd buf in rx payload #endif /*************************************************************************** + * BLE Data Buffers + **************************************************************************/ +#if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway + static char curr_ble_data_to_slave[size_of_ble]; +#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot + static char curr_ble_data_from_master[size_of_ble]; + static char prev_ble_data_from_master[size_of_ble]; +#endif + +/*************************************************************************** * Grid Eye Sensor Data Buffers **************************************************************************/ #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway - static char curr_raw_frame_data_from_slave[payload_grid_eye_size]; - static char prev_raw_frame_data_from_slave[payload_grid_eye_size]; + static char curr_raw_frame_data_from_slave[size_of_grid_eye]; + static char prev_raw_frame_data_from_slave[size_of_grid_eye]; static int16_t conv_frame_data_from_slave[64]; #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot - static char curr_raw_frame_data_to_master[128]; + static char curr_raw_frame_data_to_master[size_of_grid_eye]; + static char prev_raw_frame_data_to_master[size_of_grid_eye]; + static int16_t conv_frame_data_to_master[64]; #endif /*************************************************************************** - * BLE Data Buffers + * GPS Data Buffers + **************************************************************************/ +#if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway + static char curr_gps_data_from_slave[size_of_gps]; + static char prev_gps_data_from_slave[size_of_gps]; +#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot + static char curr_gps_data_to_master[size_of_gps]; +#endif + +/*************************************************************************** + * MAX17055 Data Buffers **************************************************************************/ #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway - static char curr_ble_data_to_slave[2]; + static char curr_MAX17055_from_slave[size_of_MAX17055]; + static char prev_MAX17055_from_slave[size_of_MAX17055]; #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot - static char curr_ble_data_from_master[2]; - static char prev_ble_data_from_master[2]; + static char curr_MAX17055_to_master[size_of_MAX17055]; #endif +/*************************************************************************** + * MAX77650 Data Buffers + **************************************************************************/ +#if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway + static char curr_MAX77650_from_slave[size_of_MAX77650]; + static char prev_MAX77650_from_slave[size_of_MAX77650]; +#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot + static char curr_MAX77650_to_master[size_of_MAX77650]; +#endif /** * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message */ -int fillPayloadWithGlobalBufs(); +void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx); /** * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message */ -int fillGlobalBufsWithPayload(); +void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx); #endif // __GLOBAL_BUFFERS_H__ \ No newline at end of file
--- a/main.cpp Wed Jul 18 21:25:17 2018 +0000 +++ b/main.cpp Thu Jul 19 21:13:19 2018 +0000 @@ -28,6 +28,8 @@ DigitalOut myled(LED); +Serial pc(USBTX, USBRX); + #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway /* No grid eye object needed. The function the master uses to convert the raw @@ -58,6 +60,11 @@ dprintf("Starting a simple LoRa PingPong"); /* Setup begins here: */ + #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway + dprintf("MAX32630FTHR: Master"); + #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot + dprintf("MAX32620FTHR: Slave"); + #endif /*************************************************************************** * Lora Communications @@ -71,6 +78,7 @@ int frame_idx = 0; #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot // none yet + int frame_idx = 0; #endif @@ -103,14 +111,49 @@ // Increment frame counter frame_idx = frame_idx +1; } + + /* Next copy in data received from current data into buffer used for + * comparison next time the memcmp above is called. This prevents the + * program from converting the same raw data aquired by the grid eye + * sensor on the slave device to the floating point array with the + * 0.25 degrees celsius precision level when there is not new data. + */ + memcpy(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave)); + #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot // Aquire raw data about 8x8 frame from the grid eye sensor in this function call gridEye.getRaw8x8FrameData(curr_raw_frame_data_to_master); + wait_ms( 1000 ); + + //if ( memcmp(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)) != 0 ) + //{ + // Convert raw data sent from slave to a 16 bit integer array by calling this + convRaw8x8Data2Point25degC(curr_raw_frame_data_to_master, conv_frame_data_to_master); + + // Next Print off the Converted data + pc.printf("\r\nFrame %d data: \r\n", frame_idx); + uint8_t idx; + float pixel_data; + for (int y = 0; y < 8; y++) { + for (int x = 0; x < 8; x++) { + idx = y*8 + x; + pixel_data = conv_frame_data_to_master[idx]/4.0; + pc.printf("%.2f \t", pixel_data); + } + pc.printf("\r\n\r\n"); + } + pc.printf("\r\n"); + + // Increment frame counter + frame_idx = frame_idx +1; + //} + memcpy(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)); #endif /*************************************************************************** * Lora Communications **************************************************************************/ + wait_ms( 10 ); SX1276PingPong();