From b5a6338293d285b9ae92a5e7b30b986313f8becf Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:11:31 -0500 Subject: [PATCH 01/41] added storage of V, I max and min --- afsk/main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index 5f33428d..54567601 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -135,6 +135,7 @@ char pythonStr[100], pythonConfigStr[100], busStr[10]; int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; char src_addr[5] = ""; char dest_addr[5] = "CQ"; +float voltage_min[9], current_min[9], voltage_max[9], current_max[9]; int main(int argc, char *argv[]) { @@ -491,6 +492,10 @@ printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max: fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); } +memset(voltage_min), 0, sizeof(voltage_min)); +memset(current_min, 0, sizeof(current_min)); +memset(voltage_max, 0, sizeof(voltage_max)); +memset(current_max, 0, sizeof(current_max)); while (loop-- != 0) { @@ -1227,6 +1232,21 @@ if (sim_mode) // end of simulated telemetry } + for (count1 = 0; count1 < 8; count1++) + { + if (voltage[count1] < voltage_min[count1] + voltage_min[count1] = voltage[count]; + if (current[count1] < current_min[count1] + voltage_min[count1] = current[count]; + + if (voltage[count1] > voltage_max[count1] + voltage_max[count1] = voltage[count]; + if (current[count1] > current_max[count1] + voltage_max[count1] = current[count]; + + printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); + } + memset(rs_frame,0,sizeof(rs_frame)); memset(parities,0,sizeof(parities)); From 898a01e965085246aafbbedc49747c3496edf0e7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:14:19 -0500 Subject: [PATCH 02/41] typos --- afsk/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 54567601..2c6c4c6e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -492,7 +492,7 @@ printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max: fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); } -memset(voltage_min), 0, sizeof(voltage_min)); +memset(voltage_min, 0, sizeof(voltage_min)); memset(current_min, 0, sizeof(current_min)); memset(voltage_max, 0, sizeof(voltage_max)); memset(current_max, 0, sizeof(current_max)); @@ -1234,14 +1234,14 @@ if (sim_mode) for (count1 = 0; count1 < 8; count1++) { - if (voltage[count1] < voltage_min[count1] + if (voltage[count1] < voltage_min[count1]) voltage_min[count1] = voltage[count]; - if (current[count1] < current_min[count1] + if (current[count1] < current_min[count1]) voltage_min[count1] = current[count]; - if (voltage[count1] > voltage_max[count1] + if (voltage[count1] > voltage_max[count1]) voltage_max[count1] = voltage[count]; - if (current[count1] > current_max[count1] + if (current[count1] > current_max[count1]) voltage_max[count1] = current[count]; printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); From db71caa8f7b261f8fb887ec9b3e3ee378a17bb4c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:15:42 -0500 Subject: [PATCH 03/41] typos --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 2c6c4c6e..d856c75d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1235,14 +1235,14 @@ if (sim_mode) for (count1 = 0; count1 < 8; count1++) { if (voltage[count1] < voltage_min[count1]) - voltage_min[count1] = voltage[count]; + voltage_min[count1] = voltage[count1]; if (current[count1] < current_min[count1]) - voltage_min[count1] = current[count]; + voltage_min[count1] = current[count1]; if (voltage[count1] > voltage_max[count1]) - voltage_max[count1] = voltage[count]; + voltage_max[count1] = voltage[count]1; if (current[count1] > current_max[count1]) - voltage_max[count1] = current[count]; + voltage_max[count1] = current[count1]; printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); } From af3d08657c35e12d42df2e4863a773ab4517365e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:16:40 -0500 Subject: [PATCH 04/41] typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index d856c75d..d0ff64f3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1240,7 +1240,7 @@ if (sim_mode) voltage_min[count1] = current[count1]; if (voltage[count1] > voltage_max[count1]) - voltage_max[count1] = voltage[count]1; + voltage_max[count1] = voltage[count1]; if (current[count1] > current_max[count1]) voltage_max[count1] = current[count1]; From d5e9303b491402ddc63b8f2b4c42e861917389a2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:23:53 -0500 Subject: [PATCH 05/41] typos --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d0ff64f3..708adb63 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1237,12 +1237,12 @@ if (sim_mode) if (voltage[count1] < voltage_min[count1]) voltage_min[count1] = voltage[count1]; if (current[count1] < current_min[count1]) - voltage_min[count1] = current[count1]; + current_min[count1] = current[count1]; if (voltage[count1] > voltage_max[count1]) voltage_max[count1] = voltage[count1]; if (current[count1] > current_max[count1]) - voltage_max[count1] = current[count1]; + current_max[count1] = current[count1]; printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); } From 8b0d8f9fbba8eb633a9d46c49121fde76f111b1b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:29:48 -0500 Subject: [PATCH 06/41] initialized max and min so that first value sets it --- afsk/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 708adb63..737e06fa 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -492,10 +492,18 @@ printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max: fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); } -memset(voltage_min, 0, sizeof(voltage_min)); -memset(current_min, 0, sizeof(current_min)); -memset(voltage_max, 0, sizeof(voltage_max)); -memset(current_max, 0, sizeof(current_max)); +//memset(voltage_min, 0, sizeof(voltage_min)); +//memset(current_min, 0, sizeof(current_min)); +//memset(voltage_max, 0, sizeof(voltage_max)); +//memset(current_max, 0, sizeof(current_max)); + +for(i=0; i < 9; i++) +{ + voltage_min[i] = 1000.0; + current_min[i] = 1000.0; + voltage_max[i] = -1000.0; + current_max[i] = -1000.0; +} while (loop-- != 0) { From 421235ef43b6be0be71fc5f746f2c23af6d5a4e0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 11:30:42 -0500 Subject: [PATCH 07/41] typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 737e06fa..74720d88 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -497,7 +497,7 @@ printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max: //memset(voltage_max, 0, sizeof(voltage_max)); //memset(current_max, 0, sizeof(current_max)); -for(i=0; i < 9; i++) +for(int i=0; i < 9; i++) { voltage_min[i] = 1000.0; current_min[i] = 1000.0; From 06c29b1558843d73526c544a28867435ff383a26 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:11:03 -0500 Subject: [PATCH 08/41] added sensor max and min and other max and min --- afsk/main.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 74720d88..aa6fbbf8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -135,7 +135,7 @@ char pythonStr[100], pythonConfigStr[100], busStr[10]; int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; char src_addr[5] = ""; char dest_addr[5] = "CQ"; -float voltage_min[9], current_min[9], voltage_max[9], current_max[9]; +float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[14], sensor_min[14], other_max[3], other_min[3]; int main(int argc, char *argv[]) { @@ -492,11 +492,6 @@ printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max: fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); } -//memset(voltage_min, 0, sizeof(voltage_min)); -//memset(current_min, 0, sizeof(current_min)); -//memset(voltage_max, 0, sizeof(voltage_max)); -//memset(current_max, 0, sizeof(current_max)); - for(int i=0; i < 9; i++) { voltage_min[i] = 1000.0; @@ -504,6 +499,16 @@ for(int i=0; i < 9; i++) voltage_max[i] = -1000.0; current_max[i] = -1000.0; } +for(i=0; i < 14; i++) +{ + sensor_min[i] = 1000.0; + sensor_max[i] = -1000.0; +} +for(i=0; i < 3; i++) +{ + other_min[i] = 1000.0; + other_max[i] = -1000.0; +} while (loop-- != 0) { @@ -1113,9 +1118,11 @@ if (firstTime != ON) const char space[2] = " "; token = strtok(cmdbuffer, space); - float voltage[9], current[9]; + float voltage[9], current[9], sensor[20], other[3]; memset(voltage, 0, sizeof(voltage)); memset(current, 0, sizeof(current)); + memset(sensor, 0, sizeof(sensor)); + memset(other, 0, sizeof(other)); for (count1 = 0; count1 < 8; count1++) { @@ -1377,7 +1384,8 @@ if (payload == ON) } printf("RXTemperature: %d \n", RXTemperature); */ - +/* + count1 = 0; if (token != NULL) { token = strtok(NULL, space); // OK token @@ -1471,6 +1479,24 @@ if (payload == ON) XSsensor3 = atof(token); printf("Sensor3 %f \n", XSsensor3); } +*/ + + for (count1 = 0; count1 < 20; count1++) + { + if (token != NULL) + { + sensor[count1] = atof(token); + if (sensor[count1] < sensor_min[count1]) + sensor_min[count1] = sensor[count1]; + if (sensor[count1] > sensor_max[count1]) + sensor_max[count1] = sensor[count1]; +// #ifdef DEBUG_LOGGING + printf("sensor: %f ", sensor[count1]); +// #endif + token = strtok(NULL, space); + } + } + printf("\n"); xAngularVelocity = (int)(gyroX + 0.5) + 2048; yAngularVelocity = (int)(gyroY + 0.5) + 2048; From b162d1b1a8b994173cc6ae79b82e9ba58c29c5e1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:12:24 -0500 Subject: [PATCH 09/41] typo --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index aa6fbbf8..2f659089 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -499,12 +499,12 @@ for(int i=0; i < 9; i++) voltage_max[i] = -1000.0; current_max[i] = -1000.0; } -for(i=0; i < 14; i++) +for(int i=0; i < 14; i++) { sensor_min[i] = 1000.0; sensor_max[i] = -1000.0; } -for(i=0; i < 3; i++) +for(int i=0; i < 3; i++) { other_min[i] = 1000.0; other_max[i] = -1000.0; From b2fe6e2084e9ed459018060c8be3d26085cc2be7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:24:18 -0500 Subject: [PATCH 10/41] added GYRO_X, Y, and Z, ACCEL_X, Y, Z --- afsk/main.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 2f659089..26b52c6d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -57,6 +57,13 @@ #define PLUS_Z 6 #define MINUS_Z 7 +#define GYRO_X 7 +#define GYRO_Y 8 +#define GYRO_Z 9 +#define ACCEL_X 10 +#define ACCEL_Y 11 +#define ACCEL_Z 12 + #define OFF -1 #define ON 1 @@ -135,7 +142,7 @@ char pythonStr[100], pythonConfigStr[100], busStr[10]; int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; char src_addr[5] = ""; char dest_addr[5] = "CQ"; -float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[14], sensor_min[14], other_max[3], other_min[3]; +float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[14], sensor_min[14], other_max[3], other_min[3]; int main(int argc, char *argv[]) { @@ -1486,17 +1493,23 @@ if (payload == ON) if (token != NULL) { sensor[count1] = atof(token); - if (sensor[count1] < sensor_min[count1]) - sensor_min[count1] = sensor[count1]; - if (sensor[count1] > sensor_max[count1]) - sensor_max[count1] = sensor[count1]; -// #ifdef DEBUG_LOGGING + #ifdef DEBUG_LOGGING printf("sensor: %f ", sensor[count1]); -// #endif + #endif token = strtok(NULL, space); } } printf("\n"); + + for (count1 = 0; count1 < 20; count1++) + { + if (sensor[count1] < sensor_min[count1]) + sensor_min[count1] = sensor[count1]; + if (sensor[count1] > sensor_max[count1]) + sensor_max[count1] = sensor[count1]; + + printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); + } xAngularVelocity = (int)(gyroX + 0.5) + 2048; yAngularVelocity = (int)(gyroY + 0.5) + 2048; @@ -1561,9 +1574,15 @@ if (payload == ON) encodeA(b, 39 + head_offset, IHUcpuTemp); - encodeB(b, 40 + head_offset, xAngularVelocity); - encodeA(b, 42 + head_offset, yAngularVelocity); - encodeB(b, 43 + head_offset, zAngularVelocity); +// encodeB(b, 40 + head_offset, xAngularVelocity); +// encodeA(b, 42 + head_offset, yAngularVelocity); +// encodeB(b, 43 + head_offset, zAngularVelocity); + + encodeB(b, 40 + head_offset, (int)(sensor[GYRO_X] + 0.5) + 2048); + encodeA(b, 42 + head_offset, (int)(sensor[GYRO_Y] + 0.5) + 2048); + encodeB(b, 43 + head_offset, (int)(sensor[GYRO_Z] + 0.5) + 2048); + + encodeA(b, 45 + head_offset, (int)(BME280humidity + 0.5)); // in place of sensor1 encodeB(b, 46 + head_offset,PSUCurrent); From 941d71090cf4ab025d677b6f2e6bf69e5306ab03 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:33:57 -0500 Subject: [PATCH 11/41] changed 20 to 14, encoded accel --- afsk/main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 26b52c6d..0da8a1e2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1125,7 +1125,7 @@ if (firstTime != ON) const char space[2] = " "; token = strtok(cmdbuffer, space); - float voltage[9], current[9], sensor[20], other[3]; + float voltage[9], current[9], sensor[14], other[3]; memset(voltage, 0, sizeof(voltage)); memset(current, 0, sizeof(current)); memset(sensor, 0, sizeof(sensor)); @@ -1488,7 +1488,7 @@ if (payload == ON) } */ - for (count1 = 0; count1 < 20; count1++) + for (count1 = 0; count1 < 14; count1++) { if (token != NULL) { @@ -1501,7 +1501,7 @@ if (payload == ON) } printf("\n"); - for (count1 = 0; count1 < 20; count1++) + for (count1 = 0; count1 < 14; count1++) { if (sensor[count1] < sensor_min[count1]) sensor_min[count1] = sensor[count1]; @@ -1520,11 +1520,13 @@ if (payload == ON) encodeB(b, 1 + head_offset, batt_b_v); encodeA(b, 3 + head_offset, batt_c_v); - encodeB(b, 4 + head_offset, (int)(xAccel * 100 + 0.5) + 2048); // Xaccel - encodeA(b, 6 + head_offset, (int)(yAccel * 100 + 0.5) + 2048); // Yaccel - encodeB(b, 7 + head_offset, (int)(zAccel * 100 + 0.5) + 2048); // Zaccel -// encodeA(b, 6 + head_offset,yAccel); //Yaccel -// encodeB(b, 7 + head_offset,zAccel); //Zaccel +// encodeB(b, 4 + head_offset, (int)(xAccel * 100 + 0.5) + 2048); // Xaccel +// encodeA(b, 6 + head_offset, (int)(yAccel * 100 + 0.5) + 2048); // Yaccel +// encodeB(b, 7 + head_offset, (int)(zAccel * 100 + 0.5) + 2048); // Zaccel + + encodeB(b, 4 + head_offset, (int)(sensor[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel + encodeA(b, 6 + head_offset, (int)(sensor[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel + encodeB(b, 7 + head_offset, (int)(sensor[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel encodeA(b, 9 + head_offset, battCurr); From 8b7b1de256a0afd602b8429d8c563c7654dcbf71 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:43:18 -0500 Subject: [PATCH 12/41] added HUMI, etc XS1 to 3 --- afsk/main.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 0da8a1e2..f8872906 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -57,12 +57,20 @@ #define PLUS_Z 6 #define MINUS_Z 7 +PRES, ALT, TEMP +#define TEMP 2 +#define PRES 3 +#define ALT 4 +#define HUMI 5 #define GYRO_X 7 #define GYRO_Y 8 #define GYRO_Z 9 #define ACCEL_X 10 #define ACCEL_Y 11 #define ACCEL_Z 12 +#define XS1 14 +#define XS2 15 +#define XS3 16 #define OFF -1 #define ON 1 @@ -1125,7 +1133,7 @@ if (firstTime != ON) const char space[2] = " "; token = strtok(cmdbuffer, space); - float voltage[9], current[9], sensor[14], other[3]; + float voltage[9], current[9], sensor[17], other[3]; memset(voltage, 0, sizeof(voltage)); memset(current, 0, sizeof(current)); memset(sensor, 0, sizeof(sensor)); @@ -1488,7 +1496,7 @@ if (payload == ON) } */ - for (count1 = 0; count1 < 14; count1++) + for (count1 = 0; count1 < 17; count1++) { if (token != NULL) { @@ -1501,7 +1509,7 @@ if (payload == ON) } printf("\n"); - for (count1 = 0; count1 < 14; count1++) + for (count1 = 0; count1 < 17; count1++) { if (sensor[count1] < sensor_min[count1]) sensor_min[count1] = sensor[count1]; @@ -1530,7 +1538,8 @@ if (payload == ON) encodeA(b, 9 + head_offset, battCurr); - encodeB(b, 10 + head_offset,(int)(BME280temperature * 10 + 0.5)); // Temp +// encodeB(b, 10 + head_offset,(int)(BME280temperature * 10 + 0.5)); // Temp + encodeB(b, 10 + head_offset,(int)(sensor[TEMP] * 10 + 0.5)); // Temp if (mode == FSK) { @@ -1568,8 +1577,11 @@ if (payload == ON) encodeA(b, 30 + head_offset,PSUVoltage); encodeB(b, 31 + head_offset,(spin * 10) + 2048); - encodeA(b, 33 + head_offset,(int)(BME280pressure + 0.5)); // Pressure - encodeB(b, 34 + head_offset,(int)(BME280altitude + 0.5)); // Altitude +// encodeA(b, 33 + head_offset,(int)(BME280pressure + 0.5)); // Pressure +// encodeB(b, 34 + head_offset,(int)(BME280altitude + 0.5)); // Altitude + + encodeA(b, 33 + head_offset,(int)(sensor[PRES] + 0.5)); // Pressure + encodeB(b, 34 + head_offset,(int)(sensor[ALT] + 0.5)); // Altitude encodeA(b, 36 + head_offset, Resets); encodeB(b, 37 + head_offset, Rssi); @@ -1586,10 +1598,15 @@ if (payload == ON) - encodeA(b, 45 + head_offset, (int)(BME280humidity + 0.5)); // in place of sensor1 +// encodeA(b, 45 + head_offset, (int)(BME280humidity + 0.5)); // in place of sensor1 + encodeA(b, 45 + head_offset, (int)(sensor[HUMI] + 0.5)); // in place of sensor1 + encodeB(b, 46 + head_offset,PSUCurrent); - encodeA(b, 48 + head_offset, (int)(XSsensor2) + 2048); - encodeB(b, 49 + head_offset, (int)(XSsensor3 * 100 + 0.5) + 2048); +// encodeA(b, 48 + head_offset, (int)(XSsensor2) + 2048); +// encodeB(b, 49 + head_offset, (int)(XSsensor3 * 100 + 0.5) + 2048); + + encodeA(b, 48 + head_offset, (int)(sensor[XS2]) + 2048); + encodeB(b, 49 + head_offset, (int)(sensor[XS3] * 100 + 0.5) + 2048); // camera = ON; From f11811f484a1fa576a0e62d1e55e40d1d2897d02 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:44:29 -0500 Subject: [PATCH 13/41] typo --- afsk/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f8872906..78b04676 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -57,7 +57,6 @@ #define PLUS_Z 6 #define MINUS_Z 7 -PRES, ALT, TEMP #define TEMP 2 #define PRES 3 #define ALT 4 From 9e3fbf5894d5b0b0d3d6e7e52efc915d9b972371 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:48:00 -0500 Subject: [PATCH 14/41] typo in sensor min and max --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 78b04676..17ef1886 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -149,7 +149,7 @@ char pythonStr[100], pythonConfigStr[100], busStr[10]; int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; char src_addr[5] = ""; char dest_addr[5] = "CQ"; -float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[14], sensor_min[14], other_max[3], other_min[3]; +float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[17], sensor_min[17], other_max[3], other_min[3]; int main(int argc, char *argv[]) { @@ -513,7 +513,7 @@ for(int i=0; i < 9; i++) voltage_max[i] = -1000.0; current_max[i] = -1000.0; } -for(int i=0; i < 14; i++) +for(int i=0; i < 17; i++) { sensor_min[i] = 1000.0; sensor_max[i] = -1000.0; From 6f7bbbc2de56e91373e0e7863ac2cd42158333af Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:53:07 -0500 Subject: [PATCH 15/41] debug sensor_min --- afsk/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 17ef1886..582975d4 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1508,14 +1508,18 @@ if (payload == ON) } printf("\n"); + + for (count1 = 0; count1 < 17; count1++) { + printf("Sensor min %f Sensor max %f \n", sensor_min[count1], sensor_max[count1]); + if (sensor[count1] < sensor_min[count1]) sensor_min[count1] = sensor[count1]; if (sensor[count1] > sensor_max[count1]) sensor_max[count1] = sensor[count1]; - printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); + printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); } xAngularVelocity = (int)(gyroX + 0.5) + 2048; From 92366d93513914ab2e32fbea6032fea6b5c253e7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 12:55:21 -0500 Subject: [PATCH 16/41] testing sensor_min and max --- afsk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/main.c b/afsk/main.c index 582975d4..9e63b5bf 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -517,6 +517,7 @@ for(int i=0; i < 17; i++) { sensor_min[i] = 1000.0; sensor_max[i] = -1000.0; + printf("Sensor min and max initialized!"); } for(int i=0; i < 3; i++) { From 7bf38384d487e1fe73ffc92f59b1b55e4339f901 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 13:01:45 -0500 Subject: [PATCH 17/41] only process payload string if valid (begins with "OK") --- afsk/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 9e63b5bf..65f72c7b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1375,7 +1375,9 @@ if (payload == ON) // sensor_payload[i++] = '\n'; sensor_payload[i] = '\0'; printf("Payload string: %s \n", sensor_payload); - + + if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) // only process if valid payload response + { int count1; char *token; // char cmdbuffer[1000]; @@ -1523,6 +1525,7 @@ if (payload == ON) printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); } +} xAngularVelocity = (int)(gyroX + 0.5) + 2048; yAngularVelocity = (int)(gyroY + 0.5) + 2048; zAngularVelocity = (int)(gyroZ + 0.5) + 2048; From 9867c9cb36d4d3b21910b374bab3c273c4ff0812 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 13:03:09 -0500 Subject: [PATCH 18/41] typo --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 65f72c7b..e8a51e71 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1390,7 +1390,7 @@ if (payload == ON) const char space[2] = " "; token = strtok(sensor_payload, space); - float gyroX, gyroY, gyroZ; +// float gyroX, gyroY, gyroZ; /* for (count1 = 0; count1 < 7; count1++) // skipping over BME280 data { @@ -1526,9 +1526,9 @@ if (payload == ON) } } - xAngularVelocity = (int)(gyroX + 0.5) + 2048; - yAngularVelocity = (int)(gyroY + 0.5) + 2048; - zAngularVelocity = (int)(gyroZ + 0.5) + 2048; +// xAngularVelocity = (int)(gyroX + 0.5) + 2048; +// yAngularVelocity = (int)(gyroY + 0.5) + 2048; +// zAngularVelocity = (int)(gyroZ + 0.5) + 2048; } encodeA(b, 0 + head_offset, batt_a_v); From b0fcc5ed5da6fd4b98f60373c908c82f28722c6b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 14:51:39 -0500 Subject: [PATCH 19/41] added other for IHUtemp --- afsk/main.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e8a51e71..a0657460 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -71,6 +71,10 @@ #define XS2 15 #define XS3 16 +#define RSSI 0 +#define IHU_TEMP 2 +#define SPIN 1 + #define OFF -1 #define ON 1 @@ -1183,7 +1187,9 @@ if (firstTime != ON) printf("CPU Temp Read: %6.1f\n", cpuTemp); #endif - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); + other[IHUtemp] = cpuTemp; + +// IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); } fclose(cpuTempSensor); @@ -1232,7 +1238,9 @@ if (sim_mode) // printf("temp: %f Time: %f Eclipse: %d : %f %f | %f %f | %f %f\n",tempS, time, eclipse, voltage[map[PLUS_X]], voltage[map[MINUS_X]], voltage[map[PLUS_Y]], voltage[map[MINUS_Y]], current[map[PLUS_Z]], current[map[MINUS_Z]]); tempS += (eclipse > 0) ? ((temp_max - tempS)/50.0): ((temp_min - tempS)/50.0); - IHUcpuTemp = (int)((tempS + rnd_float(-1.0, 1.0)) * 10 + 0.5); + tempS += + rnd_float(-1.0, 1.0); +// IHUcpuTemp = (int)((tempS + rnd_float(-1.0, 1.0)) * 10 + 0.5); + other[IHU_TEMP] = tempS; voltage[map[BUS]] = rnd_float(5.0, 5.005); current[map[BUS]] = rnd_float(158, 171); @@ -1514,16 +1522,24 @@ if (payload == ON) for (count1 = 0; count1 < 17; count1++) - { - printf("Sensor min %f Sensor max %f \n", sensor_min[count1], sensor_max[count1]); - + { if (sensor[count1] < sensor_min[count1]) sensor_min[count1] = sensor[count1]; if (sensor[count1] > sensor_max[count1]) sensor_max[count1] = sensor[count1]; printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); - } + } + + for (count1 = 0; count1 < 3; count1++) + { + if (other[count1] < oter_min[count1]) + other_min[count1] = other[count1]; + if (other[count1] > otjer_max[count1]) + other_max[count1] = other[count1]; + + printf("Other min %f max %f \n", other_min[count1], other_max[count1]); + } } // xAngularVelocity = (int)(gyroX + 0.5) + 2048; @@ -1582,7 +1598,8 @@ if (payload == ON) } encodeA(b, 30 + head_offset,PSUVoltage); - encodeB(b, 31 + head_offset,(spin * 10) + 2048); +// encodeB(b, 31 + head_offset,(spin * 10) + 2048); + encodeB(b, 31 + head_offset,(other[SPIN] * 10) + 2048); // encodeA(b, 33 + head_offset,(int)(BME280pressure + 0.5)); // Pressure // encodeB(b, 34 + head_offset,(int)(BME280altitude + 0.5)); // Altitude @@ -1591,9 +1608,11 @@ if (payload == ON) encodeB(b, 34 + head_offset,(int)(sensor[ALT] + 0.5)); // Altitude encodeA(b, 36 + head_offset, Resets); - encodeB(b, 37 + head_offset, Rssi); +// encodeB(b, 37 + head_offset, Rssi); + encodeB(b, 37 + head_offset, other[RSSI]); - encodeA(b, 39 + head_offset, IHUcpuTemp); +// encodeA(b, 39 + head_offset, IHUcpuTemp); + encodeA(b, 39 + head_offset, (int)(other[IHU_TEMP] * 10 + 0.5)); // encodeB(b, 40 + head_offset, xAngularVelocity); // encodeA(b, 42 + head_offset, yAngularVelocity); From 86958b5a285b33fab6210cff528154b6967336a4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 14:52:47 -0500 Subject: [PATCH 20/41] typos --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index a0657460..a3d76660 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1533,9 +1533,9 @@ if (payload == ON) for (count1 = 0; count1 < 3; count1++) { - if (other[count1] < oter_min[count1]) + if (other[count1] < other_min[count1]) other_min[count1] = other[count1]; - if (other[count1] > otjer_max[count1]) + if (other[count1] > other_max[count1]) other_max[count1] = other[count1]; printf("Other min %f max %f \n", other_min[count1], other_max[count1]); From 3afcdb77bac4a1ead12647bf120ef3f267428102 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 14:54:51 -0500 Subject: [PATCH 21/41] typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index a3d76660..6e6821ca 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1187,7 +1187,7 @@ if (firstTime != ON) printf("CPU Temp Read: %6.1f\n", cpuTemp); #endif - other[IHUtemp] = cpuTemp; + other[IHU_TEMP] = cpuTemp; // IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); } From 32c8accacede86599ee9a83ae8beecb6d7ff6ba1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 14:59:44 -0500 Subject: [PATCH 22/41] fixed RSSI --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6e6821ca..beccb9d1 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1609,7 +1609,7 @@ if (payload == ON) encodeA(b, 36 + head_offset, Resets); // encodeB(b, 37 + head_offset, Rssi); - encodeB(b, 37 + head_offset, other[RSSI]); + encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5)); // encodeA(b, 39 + head_offset, IHUcpuTemp); encodeA(b, 39 + head_offset, (int)(other[IHU_TEMP] * 10 + 0.5)); From 6994a433c124c74e617089623979f9f43a266264 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 15:11:01 -0500 Subject: [PATCH 23/41] added MIN frame every 1/4 --- afsk/main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index beccb9d1..7e168362 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1285,6 +1285,22 @@ if (sim_mode) printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); } + if (loop % 4 == 0) + { + printf("Sending MIN frame \n"); + frm_type = 0x02; + for (count1 = 0; count1 < 17; count1++) + { + if (count1 < 3) + other[count1] = other_min[count1]; + if (count1 < 8) + { + voltage[count1] = voltage_min[count1]; + current[count1] = current_min[count1]; + } + sensor[count1] = sensor_min[count1]; + } + memset(rs_frame,0,sizeof(rs_frame)); memset(parities,0,sizeof(parities)); From 3a6397db6645846935270c48518669bf77769f63 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 15:14:05 -0500 Subject: [PATCH 24/41] typo --- afsk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/main.c b/afsk/main.c index 7e168362..8ba6bf9b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1299,6 +1299,7 @@ if (sim_mode) current[count1] = current_min[count1]; } sensor[count1] = sensor_min[count1]; + } } memset(rs_frame,0,sizeof(rs_frame)); From 68eb69776e85766ad2614e23c945533ad42ec61a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 15:21:19 -0500 Subject: [PATCH 25/41] fixed RSSI and rearranged payload read order --- afsk/main.c | 301 +++++++++++++++++----------------------------------- 1 file changed, 96 insertions(+), 205 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 8ba6bf9b..050efca2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1192,6 +1192,101 @@ if (firstTime != ON) // IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); } fclose(cpuTempSensor); + +char sensor_payload[500]; + +if (payload == ON) +{ + STEMBoardFailure = 0; + + char c; + int charss = serialDataAvail (uart_fd); + if (charss != 0) + printf("Clearing buffer of %d chars \n", charss); + while ((charss-- > 0)) + c = serialGetchar (uart_fd); // clear buffer + + unsigned int waitTime; + int i = 0; + serialPutchar (uart_fd, '?'); + printf("Querying payload with ?\n"); + waitTime = millis() + 500; + int end = FALSE; +// int retry = FALSE; + while ((millis() < waitTime) && !end) + { + int chars = serialDataAvail (uart_fd); + while ((chars-- > 0) && !end) + { + c = serialGetchar (uart_fd); +// printf ("%c", c); +// fflush(stdout); + if (c != '\n') + { + sensor_payload[i++] = c; + } + else + { + end = TRUE; + } + } + } + sensor_payload[i++] = ' '; +// sensor_payload[i++] = '\n'; + sensor_payload[i] = '\0'; + printf("Payload string: %s \n", sensor_payload); + + if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) // only process if valid payload response + { + int count1; + char *token; +// char cmdbuffer[1000]; + +// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); +// fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); +// pclose(file); + + const char space[2] = " "; + token = strtok(sensor_payload, space); + for (count1 = 0; count1 < 17; count1++) + { + if (token != NULL) + { + sensor[count1] = atof(token); + #ifdef DEBUG_LOGGING + printf("sensor: %f ", sensor[count1]); + #endif + token = strtok(NULL, space); + } + } + printf("\n"); + + + + for (count1 = 0; count1 < 17; count1++) + { + if (sensor[count1] < sensor_min[count1]) + sensor_min[count1] = sensor[count1]; + if (sensor[count1] > sensor_max[count1]) + sensor_max[count1] = sensor[count1]; + + printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); + } + + for (count1 = 0; count1 < 3; count1++) + { + if (other[count1] < other_min[count1]) + other_min[count1] = other[count1]; + if (other[count1] > other_max[count1]) + other_max[count1] = other[count1]; + + printf("Other min %f max %f \n", other_min[count1], other_max[count1]); + } + +} + +} if (sim_mode) { @@ -1358,211 +1453,7 @@ if (sim_mode) // read payload sensor if available -char sensor_payload[500]; - -if (payload == ON) -{ - STEMBoardFailure = 0; - - char c; - int charss = serialDataAvail (uart_fd); - if (charss != 0) - printf("Clearing buffer of %d chars \n", charss); - while ((charss-- > 0)) - c = serialGetchar (uart_fd); // clear buffer - - unsigned int waitTime; - int i = 0; - serialPutchar (uart_fd, '?'); - printf("Querying payload with ?\n"); - waitTime = millis() + 500; - int end = FALSE; -// int retry = FALSE; - while ((millis() < waitTime) && !end) - { - int chars = serialDataAvail (uart_fd); - while ((chars-- > 0) && !end) - { - c = serialGetchar (uart_fd); -// printf ("%c", c); -// fflush(stdout); - if (c != '\n') - { - sensor_payload[i++] = c; - } - else - { - end = TRUE; - } - } - } - sensor_payload[i++] = ' '; -// sensor_payload[i++] = '\n'; - sensor_payload[i] = '\0'; - printf("Payload string: %s \n", sensor_payload); - - if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) // only process if valid payload response - { - int count1; - char *token; -// char cmdbuffer[1000]; - -// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); -// fgets(cmdbuffer, 1000, file); -// printf("result: %s\n", cmdbuffer); -// pclose(file); - - const char space[2] = " "; - token = strtok(sensor_payload, space); -// float gyroX, gyroY, gyroZ; -/* - for (count1 = 0; count1 < 7; count1++) // skipping over BME280 data - { - if (token != NULL) - if (count1 == 2) - RXTemperature = (int)((atof(token) * 10.0) + 0.5); - token = strtok(NULL, space); - } - printf("RXTemperature: %d \n", RXTemperature); -*/ -/* - count1 = 0; - if (token != NULL) - { - token = strtok(NULL, space); // OK token - } - if (token != NULL) - { - token = strtok(NULL, space); // BME280 token - } - if (token != NULL) - { - BME280temperature = atof(token); - printf("temperature %f ", BME280temperature); - token = strtok(NULL, space); // get next token - } - if (token != NULL) - { - BME280pressure = atof(token); - printf("pressure %f ",BME280pressure); - token = strtok(NULL, space); // get next token - } - if (token != NULL) - { - BME280altitude = atof(token); - printf("altitude %f ",BME280altitude); - token = strtok(NULL, space); // get next token - } - if (token != NULL) - { - BME280humidity = atof(token); - printf("humidity %f ",BME280humidity); - token = strtok(NULL, space); // get next token - } - if (token != NULL) - { - token = strtok(NULL, space); // start of MPU6050 data - } - if (token != NULL) - { - gyroX = atof(token); - printf("gyroX %f ", gyroX); - token = strtok(NULL, space); - } - if (token != NULL) - { - gyroY = atof(token); - printf("gyroY %f ", gyroY); - token = strtok(NULL, space); - } - if (token != NULL) - { - gyroZ = atof(token); - printf("gyroZ %f \n", gyroZ); - token = strtok(NULL, space); - } - if (token != NULL) - { - xAccel = atof(token); - printf("accelX %f ", xAccel); - token = strtok(NULL, space); - } - if (token != NULL) - { - yAccel = atof(token); - printf("accelY %f ", yAccel); - token = strtok(NULL, space); - } - if (token != NULL) - { - zAccel = atof(token); - printf("accelZ %f ", zAccel); - token = strtok(NULL, space); - } - if (token != NULL) - { - token = strtok(NULL, space); // start of XS extra sensor data - } - if (token != NULL) - { - XSsensor1 = atof(token); - printf("Sensor1%f ", XSsensor1); - token = strtok(NULL, space); - } - if (token != NULL) - { - XSsensor2 = atof(token); - printf("Sensor2 %f ", XSsensor2); - token = strtok(NULL, space); - } - if (token != NULL) - { - XSsensor3 = atof(token); - printf("Sensor3 %f \n", XSsensor3); - } -*/ - - for (count1 = 0; count1 < 17; count1++) - { - if (token != NULL) - { - sensor[count1] = atof(token); - #ifdef DEBUG_LOGGING - printf("sensor: %f ", sensor[count1]); - #endif - token = strtok(NULL, space); - } - } - printf("\n"); - - - - for (count1 = 0; count1 < 17; count1++) - { - if (sensor[count1] < sensor_min[count1]) - sensor_min[count1] = sensor[count1]; - if (sensor[count1] > sensor_max[count1]) - sensor_max[count1] = sensor[count1]; - - printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); - } - - for (count1 = 0; count1 < 3; count1++) - { - if (other[count1] < other_min[count1]) - other_min[count1] = other[count1]; - if (other[count1] > other_max[count1]) - other_max[count1] = other[count1]; - - printf("Other min %f max %f \n", other_min[count1], other_max[count1]); - } - -} -// xAngularVelocity = (int)(gyroX + 0.5) + 2048; -// yAngularVelocity = (int)(gyroY + 0.5) + 2048; -// zAngularVelocity = (int)(gyroZ + 0.5) + 2048; - } encodeA(b, 0 + head_offset, batt_a_v); encodeB(b, 1 + head_offset, batt_b_v); @@ -1626,7 +1517,7 @@ if (payload == ON) encodeA(b, 36 + head_offset, Resets); // encodeB(b, 37 + head_offset, Rssi); - encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5)); + encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5) + 2048); // encodeA(b, 39 + head_offset, IHUcpuTemp); encodeA(b, 39 + head_offset, (int)(other[IHU_TEMP] * 10 + 0.5)); From 2b0e96c256822c1820cd618a8cc17d794815da6a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 15:23:22 -0500 Subject: [PATCH 26/41] added MAX and MIN --- afsk/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 050efca2..7afa9532 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1380,10 +1380,10 @@ if (sim_mode) printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); } - if (loop % 4 == 0) + if (loop % 8 == 0) { printf("Sending MIN frame \n"); - frm_type = 0x02; + frm_type = 0x03; for (count1 = 0; count1 < 17; count1++) { if (count1 < 3) @@ -1396,6 +1396,22 @@ if (sim_mode) sensor[count1] = sensor_min[count1]; } } + if ((loop + 4) % 8 == 0) + { + printf("Sending MAX frame \n"); + frm_type = 0x02; + for (count1 = 0; count1 < 17; count1++) + { + if (count1 < 3) + other[count1] = other_max[count1]; + if (count1 < 8) + { + voltage[count1] = voltage_max[count1]; + current[count1] = current_max[count1]; + } + sensor[count1] = sensor_max[count1]; + } + } memset(rs_frame,0,sizeof(rs_frame)); memset(parities,0,sizeof(parities)); From 30c8a0f7ac2d757742257360d41777e8526f0ad2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 17:02:45 -0500 Subject: [PATCH 27/41] moved min max after sim --- afsk/main.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7afa9532..6ab5333a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1260,31 +1260,9 @@ if (payload == ON) token = strtok(NULL, space); } } - printf("\n"); - - - - for (count1 = 0; count1 < 17; count1++) - { - if (sensor[count1] < sensor_min[count1]) - sensor_min[count1] = sensor[count1]; - if (sensor[count1] > sensor_max[count1]) - sensor_max[count1] = sensor[count1]; - - printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); - } - - for (count1 = 0; count1 < 3; count1++) - { - if (other[count1] < other_min[count1]) - other_min[count1] = other[count1]; - if (other[count1] > other_max[count1]) - other_max[count1] = other[count1]; - - printf("Other min %f max %f \n", other_min[count1], other_max[count1]); - } + printf("\n"); -} + } } @@ -1379,6 +1357,26 @@ if (sim_mode) printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); } + + for (count1 = 0; count1 < 17; count1++) + { + if (sensor[count1] < sensor_min[count1]) + sensor_min[count1] = sensor[count1]; + if (sensor[count1] > sensor_max[count1]) + sensor_max[count1] = sensor[count1]; + + printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); + } + + for (count1 = 0; count1 < 3; count1++) + { + if (other[count1] < other_min[count1]) + other_min[count1] = other[count1]; + if (other[count1] > other_max[count1]) + other_max[count1] = other[count1]; + + printf("Other min %f max %f \n", other_min[count1], other_max[count1]); + } if (loop % 8 == 0) { @@ -1529,7 +1527,7 @@ if (sim_mode) // encodeB(b, 34 + head_offset,(int)(BME280altitude + 0.5)); // Altitude encodeA(b, 33 + head_offset,(int)(sensor[PRES] + 0.5)); // Pressure - encodeB(b, 34 + head_offset,(int)(sensor[ALT] + 0.5)); // Altitude + encodeB(b, 34 + head_offset,(int)(sensor[ALT] * 10.0 + 0.5)); // Altitude encodeA(b, 36 + head_offset, Resets); // encodeB(b, 37 + head_offset, Rssi); From 26f8a15cb373992b6a50d4bb524c4a824cad4ed0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 17:20:05 -0500 Subject: [PATCH 28/41] only update max and min if valid sensor data --- afsk/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 6ab5333a..0d8357fc 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1357,7 +1357,9 @@ if (sim_mode) printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]); } - + + if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) + { for (count1 = 0; count1 < 17; count1++) { if (sensor[count1] < sensor_min[count1]) @@ -1366,7 +1368,8 @@ if (sim_mode) sensor_max[count1] = sensor[count1]; printf("Smin %f Smax %f \n", sensor_min[count1], sensor_max[count1]); - } + } + } for (count1 = 0; count1 < 3; count1++) { From 75db343fd22eefc5b69d836e6ea5568990ee23a9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 17:36:10 -0500 Subject: [PATCH 29/41] check for valid values in sensor max and min before writing --- afsk/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 0d8357fc..8c00fbe4 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1394,7 +1394,8 @@ if (sim_mode) voltage[count1] = voltage_min[count1]; current[count1] = current_min[count1]; } - sensor[count1] = sensor_min[count1]; + if (sensor_min[count1] != 1000.0; // make sure values are valid + sensor[count1] = sensor_min[count1]; } } if ((loop + 4) % 8 == 0) @@ -1410,7 +1411,8 @@ if (sim_mode) voltage[count1] = voltage_max[count1]; current[count1] = current_max[count1]; } - sensor[count1] = sensor_max[count1]; + if (sensor_max[count1] != -1000.0; // make sure values are valid + sensor[count1] = sensor_max[count1]; } } From 5a325532980937f918b41e060f4009c4b82c0e52 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 17:37:15 -0500 Subject: [PATCH 30/41] typo --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 8c00fbe4..75cbd3f5 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1394,7 +1394,7 @@ if (sim_mode) voltage[count1] = voltage_min[count1]; current[count1] = current_min[count1]; } - if (sensor_min[count1] != 1000.0; // make sure values are valid + if (sensor_min[count1] != 1000.0) // make sure values are valid sensor[count1] = sensor_min[count1]; } } @@ -1411,7 +1411,7 @@ if (sim_mode) voltage[count1] = voltage_max[count1]; current[count1] = current_max[count1]; } - if (sensor_max[count1] != -1000.0; // make sure values are valid + if (sensor_max[count1] != -1000.0) // make sure values are valid sensor[count1] = sensor_max[count1]; } } From a532f3724faaca39e19da91d065e7726bfe4d14c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 18:01:43 -0500 Subject: [PATCH 31/41] turned payload OFF if sim mode --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 75cbd3f5..61e94f03 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -445,10 +445,10 @@ printf("INFO: I2C bus status 0: %d 1: %d 3: %d camera: %d\n",i2c_bus0, i2c_bus1, #endif if ((i2c_bus1 == OFF) && (i2c_bus3 == OFF)) - sim_mode = TRUE; - -if (sim_mode) -{ +{ + +sim_mode = TRUE; +payload == OFF: printf("Simulated telemetry mode!\n"); From 92813858d0a0c08b491285ac76233701d67c8d13 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 18:03:18 -0500 Subject: [PATCH 32/41] typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 61e94f03..598a10fc 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -448,7 +448,7 @@ if ((i2c_bus1 == OFF) && (i2c_bus3 == OFF)) { sim_mode = TRUE; -payload == OFF: +payload == OFF; printf("Simulated telemetry mode!\n"); From 8ea31a748aee0ab2f9425ad95d54240e5a3108df Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 12 Dec 2020 18:08:07 -0500 Subject: [PATCH 33/41] fixed typo - payload is not off in sim_mode --- afsk/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 598a10fc..5349390a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -448,7 +448,6 @@ if ((i2c_bus1 == OFF) && (i2c_bus3 == OFF)) { sim_mode = TRUE; -payload == OFF; printf("Simulated telemetry mode!\n"); From dc7a81fe88f3246e6f98f2332ddc23edae3c55e1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 13 Dec 2020 16:09:36 -0500 Subject: [PATCH 34/41] added EEPROM storage of x, y, and z gyro offsets --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index 5544aa72..ac7b71f0 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -2,6 +2,7 @@ #include #include #include +#include #define SEALEVELPRESSURE_HPA (1013.25) @@ -19,6 +20,8 @@ int blueLED = 8; int Sensor1 = 0; int Sensor2 = 0; float Sensor3 = 0; +void eeprom_word_write(int addr, int val); +int eeprom_word_read(int addr); void setup() { @@ -42,8 +45,41 @@ void setup() { } mpu6050.begin(); + + if (eeprom_word_read(0) == 0xA07) + { + + Serial.println("Reading gyro offsets from EEPROM\n"); + + float xOffset = ((float)eeprom_word_read(1))/100.0; + float yOffset = ((float)eeprom_word_read(2))/100.0; + float zOffset = ((float)eeprom_word_read(3))/100.0; + + Serial.println(xOffset, DEC); + Serial.println(yOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + } + else + { + + Serial.println("Calculating gyro offsets and storing in EEPROM\n"); + mpu6050.calcGyroOffsets(true); + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1))/100.0, DEC); + Serial.println(((float)eeprom_word_read(2))/100.0, DEC); + Serial.println(((float)eeprom_word_read(3))/100.0, DEC); + + } + pinMode(greenLED, OUTPUT); pinMode(blueLED, OUTPUT); @@ -204,3 +240,17 @@ void loop() { delay(100); } + +void eeprom_word_write(int addr, int val) +{ + + EEPROM.write(addr * 2, lowByte(val)); + EEPROM.write(addr * 2 + 1, highByte(val)); + +} + +int eeprom_word_read(int addr) +{ + return((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); +} + From 89581ccb45f26cece984d4e163a6bc23050f888b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 13 Dec 2020 16:24:55 -0500 Subject: [PATCH 35/41] added EEPROM storage of x, y, and z gyro offsets --- arduino/Payload_BME280_MPU6050_STM32.ino | 82 +++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino index 45d9783a..80871d87 100644 --- a/arduino/Payload_BME280_MPU6050_STM32.ino +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -2,6 +2,7 @@ #include #include #include +#include #define SEALEVELPRESSURE_HPA (1013.25) @@ -13,6 +14,11 @@ MPU6050 mpu6050(Wire); int counter = 0; long timer = 0; int bmePresent; +int Sensor1 = 0; +int Sensor2 = 0; +float Sensor3 = 0; +void eeprom_word_write(int addr, int val); +int eeprom_word_read(int addr); void setup() { @@ -35,6 +41,40 @@ void setup() { } mpu6050.begin(); + + if (eeprom_word_read(0) == 0xA07) + { + + Serial.println("Reading gyro offsets from EEPROM\n"); + + float xOffset = ((float)eeprom_word_read(1))/100.0; + float yOffset = ((float)eeprom_word_read(2))/100.0; + float zOffset = ((float)eeprom_word_read(3))/100.0; + + Serial.println(xOffset, DEC); + Serial.println(yOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1))/100.0, DEC); + Serial.println(((float)eeprom_word_read(2))/100.0, DEC); + Serial.println(((float)eeprom_word_read(3))/100.0, DEC); + + } + + } + else + { + + Serial.println("Calculating gyro offsets and storing in EEPROM\n"); + mpu6050.calcGyroOffsets(true); } @@ -53,6 +93,10 @@ void loop() { delay(500); setup(); } + + if (result == '?') + { + if (bmePresent) { Serial.print("OK BME280 "); Serial.print(bme.readTemperature()); @@ -73,10 +117,18 @@ void loop() { Serial.print(" "); Serial.print(mpu6050.getGyroY()); Serial.print(" "); - Serial.println(mpu6050.getGyroZ()); + Serial.printl(mpu6050.getGyroZ()); + + Serial.print(" XS "); + Serial.print(Sensor1); + Serial.print(" "); + Serial.print(Sensor2); + Serial.print(" "); + Serial.println(Sensor3); // Serial1.println(counter++); } + } #else if (Serial1.available() > 0) { digitalWrite(PC13, LOW); // turn the LED on @@ -90,6 +142,10 @@ void loop() { delay(500); setup(); } + + if (result == '?') + { + if (bmePresent) { Serial1.print("OK BME280 "); Serial1.print(bme.readTemperature()); @@ -110,11 +166,33 @@ void loop() { Serial1.print(" "); Serial1.print(mpu6050.getGyroY()); Serial1.print(" "); - Serial1.println(mpu6050.getGyroZ()); + Serial1.print(mpu6050.getGyroZ()); + + Serial1.print(" XS "); + Serial1.print(Sensor1); + Serial1.print(" "); + Serial1.print(Sensor2); + Serial1.print(" "); + Serial1.println(Sensor3); // Serial1.println(counter++); } + } #endif delay(100); } + + +void eeprom_word_write(int addr, int val) +{ + + EEPROM.write(addr * 2, lowByte(val)); + EEPROM.write(addr * 2 + 1, highByte(val)); + +} + +int eeprom_word_read(int addr) +{ + return((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); +} From 361dd893f472db98973f080ab28901aafe88fa35 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 13 Dec 2020 16:48:28 -0500 Subject: [PATCH 36/41] fixed typos --- arduino/Payload_BME280_MPU6050_STM32.ino | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino index 80871d87..40d33a11 100644 --- a/arduino/Payload_BME280_MPU6050_STM32.ino +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -6,7 +6,7 @@ #define SEALEVELPRESSURE_HPA (1013.25) -//#define TESTING // Define to test on Serial Monitor +#define TESTING // Define to test on Serial Monitor Adafruit_BME280 bme; MPU6050 mpu6050(Wire); @@ -57,6 +57,14 @@ void setup() { mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); + } + else + { + + Serial.println("Calculating gyro offsets and storing in EEPROM\n"); + + mpu6050.calcGyroOffsets(true); + eeprom_word_write(0, 0xA07); eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); @@ -68,14 +76,6 @@ void setup() { Serial.println(((float)eeprom_word_read(3))/100.0, DEC); } - - } - else - { - - Serial.println("Calculating gyro offsets and storing in EEPROM\n"); - - mpu6050.calcGyroOffsets(true); } void loop() { @@ -117,7 +117,7 @@ void loop() { Serial.print(" "); Serial.print(mpu6050.getGyroY()); Serial.print(" "); - Serial.printl(mpu6050.getGyroZ()); + Serial.print(mpu6050.getGyroZ()); Serial.print(" XS "); Serial.print(Sensor1); From 7d5908bac1b9e4fc51578b27aefaeb4241341148 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 13 Dec 2020 16:50:22 -0500 Subject: [PATCH 37/41] turn off testing mode --- arduino/Payload_BME280_MPU6050_STM32.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino index 40d33a11..beda623d 100644 --- a/arduino/Payload_BME280_MPU6050_STM32.ino +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -6,7 +6,7 @@ #define SEALEVELPRESSURE_HPA (1013.25) -#define TESTING // Define to test on Serial Monitor +//#define TESTING // Define to test on Serial Monitor Adafruit_BME280 bme; MPU6050 mpu6050(Wire); From 669bc26f2580dfb4be33d9a1c6609a028140174d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 14 Dec 2020 10:26:40 -0500 Subject: [PATCH 38/41] changed read from int to short --- arduino/Payload_BME280_MPU6050_STM32.ino | 178 +++++++++++------------ 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino index beda623d..91e76789 100644 --- a/arduino/Payload_BME280_MPU6050_STM32.ino +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -18,7 +18,7 @@ int Sensor1 = 0; int Sensor2 = 0; float Sensor3 = 0; void eeprom_word_write(int addr, int val); -int eeprom_word_read(int addr); +short eeprom_word_read(int addr); void setup() { @@ -29,9 +29,9 @@ void setup() { Serial.println("Starting!"); pinMode(PC13, OUTPUT); - digitalWrite(PC13, LOW); // turn the LED on - delay(50); // wait for a second - digitalWrite(PC13, HIGH); // turn the LED off + digitalWrite(PC13, LOW); // turn the LED on + delay(50); // wait for a second + digitalWrite(PC13, HIGH); // turn the LED off if (bme.begin(0x76)) { bmePresent = 1; @@ -39,7 +39,7 @@ void setup() { Serial.println("Could not find a valid BME280 sensor, check wiring!"); bmePresent = 0; } - + mpu6050.begin(); if (eeprom_word_read(0) == 0xA07) @@ -47,33 +47,33 @@ void setup() { Serial.println("Reading gyro offsets from EEPROM\n"); - float xOffset = ((float)eeprom_word_read(1))/100.0; - float yOffset = ((float)eeprom_word_read(2))/100.0; - float zOffset = ((float)eeprom_word_read(3))/100.0; + float xOffset = ((float)eeprom_word_read(1)) / 100.0; + float yOffset = ((float)eeprom_word_read(2)) / 100.0; + float zOffset = ((float)eeprom_word_read(3)) / 100.0; Serial.println(xOffset, DEC); Serial.println(yOffset, DEC); - Serial.println(zOffset, DEC); + Serial.println(zOffset, DEC); + + mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); - mpu6050.setGyroOffsets(xOffset, yOffset, zOffset); - } else { - Serial.println("Calculating gyro offsets and storing in EEPROM\n"); - - mpu6050.calcGyroOffsets(true); + Serial.println("Calculating gyro offsets and storing in EEPROM\n"); + + mpu6050.calcGyroOffsets(true); - eeprom_word_write(0, 0xA07); - eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); - eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); - eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); + eeprom_word_write(0, 0xA07); + eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5); + eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5); + eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5); - Serial.println(eeprom_word_read(0), HEX); - Serial.println(((float)eeprom_word_read(1))/100.0, DEC); - Serial.println(((float)eeprom_word_read(2))/100.0, DEC); - Serial.println(((float)eeprom_word_read(3))/100.0, DEC); + Serial.println(eeprom_word_read(0), HEX); + Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC); + Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC); } } @@ -86,100 +86,100 @@ void loop() { delay(50); // wait for a second digitalWrite(PC13, HIGH); // turn the LED off char result = Serial.read(); - // Serial.println(result); - + // Serial.println(result); + if (result == 'R') { Serial.println("OK"); delay(500); - setup(); + setup(); } - + if (result == '?') { - - if (bmePresent) { - Serial.print("OK BME280 "); - Serial.print(bme.readTemperature()); + + if (bmePresent) { + Serial.print("OK BME280 "); + Serial.print(bme.readTemperature()); + Serial.print(" "); + Serial.print(bme.readPressure() / 100.0F); + Serial.print(" "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(" "); + Serial.print(bme.readHumidity()); + } else + { + Serial.print("OK BME280 0.0 0.0 0.0 0.0"); + } + mpu6050.update(); + + Serial.print(" MPU6050 "); + Serial.print(mpu6050.getGyroX()); Serial.print(" "); - Serial.print(bme.readPressure() / 100.0F); + Serial.print(mpu6050.getGyroY()); Serial.print(" "); - Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.print(mpu6050.getGyroZ()); + + Serial.print(" XS "); + Serial.print(Sensor1); Serial.print(" "); - Serial.print(bme.readHumidity()); - } else - { - Serial.print("OK BME280 0.0 0.0 0.0 0.0"); + Serial.print(Sensor2); + Serial.print(" "); + Serial.println(Sensor3); + + // Serial1.println(counter++); } - mpu6050.update(); - - Serial.print(" MPU6050 "); - Serial.print(mpu6050.getGyroX()); - Serial.print(" "); - Serial.print(mpu6050.getGyroY()); - Serial.print(" "); - Serial.print(mpu6050.getGyroZ()); - - Serial.print(" XS "); - Serial.print(Sensor1); - Serial.print(" "); - Serial.print(Sensor2); - Serial.print(" "); - Serial.println(Sensor3); - - // Serial1.println(counter++); } - } #else if (Serial1.available() > 0) { digitalWrite(PC13, LOW); // turn the LED on delay(50); // wait for a second digitalWrite(PC13, HIGH); // turn the LED off char result = Serial1.read(); -// Serial1.println(result); + // Serial1.println(result); if (result == 'R') { Serial1.println("OK"); delay(500); - setup(); - } - + setup(); + } + if (result == '?') { - - if (bmePresent) { - Serial1.print("OK BME280 "); - Serial1.print(bme.readTemperature()); + + if (bmePresent) { + Serial1.print("OK BME280 "); + Serial1.print(bme.readTemperature()); + Serial1.print(" "); + Serial1.print(bme.readPressure() / 100.0F); + Serial1.print(" "); + Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial1.print(" "); + Serial1.print(bme.readHumidity()); + } else + { + Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); + } + mpu6050.update(); + + Serial1.print(" MPU6050 "); + Serial1.print(mpu6050.getGyroX()); Serial1.print(" "); - Serial1.print(bme.readPressure() / 100.0F); + Serial1.print(mpu6050.getGyroY()); Serial1.print(" "); - Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial1.print(mpu6050.getGyroZ()); + + Serial1.print(" XS "); + Serial1.print(Sensor1); Serial1.print(" "); - Serial1.print(bme.readHumidity()); - } else - { - Serial1.print("OK BME280 0.0 0.0 0.0 0.0"); + Serial1.print(Sensor2); + Serial1.print(" "); + Serial1.println(Sensor3); + + // Serial1.println(counter++); } - mpu6050.update(); - - Serial1.print(" MPU6050 "); - Serial1.print(mpu6050.getGyroX()); - Serial1.print(" "); - Serial1.print(mpu6050.getGyroY()); - Serial1.print(" "); - Serial1.print(mpu6050.getGyroZ()); - - Serial1.print(" XS "); - Serial1.print(Sensor1); - Serial1.print(" "); - Serial1.print(Sensor2); - Serial1.print(" "); - Serial1.println(Sensor3); - -// Serial1.println(counter++); } - } #endif - + delay(100); } @@ -192,7 +192,7 @@ void eeprom_word_write(int addr, int val) } -int eeprom_word_read(int addr) +short eeprom_word_read(int addr) { - return((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); + return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); } From f543f19e9bf67791510272db381c9033d2c3f63b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 14 Dec 2020 10:30:15 -0500 Subject: [PATCH 39/41] changed read from int to short --- arduino/Payload_BME280_MPU6050_Pro_Micro.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino index ac7b71f0..98d22d9b 100644 --- a/arduino/Payload_BME280_MPU6050_Pro_Micro.ino +++ b/arduino/Payload_BME280_MPU6050_Pro_Micro.ino @@ -21,7 +21,7 @@ int Sensor1 = 0; int Sensor2 = 0; float Sensor3 = 0; void eeprom_word_write(int addr, int val); -int eeprom_word_read(int addr); +short eeprom_word_read(int addr); void setup() { @@ -249,7 +249,7 @@ void eeprom_word_write(int addr, int val) } -int eeprom_word_read(int addr) +short eeprom_word_read(int addr) { return((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2)); } From 278af129ecfbf11a4065ef6f917de908b1449b6f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 14 Dec 2020 10:37:35 -0500 Subject: [PATCH 40/41] Used to test EEPROM and also reset stored values --- arduino/eeprom_read_write_reset.ino | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 arduino/eeprom_read_write_reset.ino diff --git a/arduino/eeprom_read_write_reset.ino b/arduino/eeprom_read_write_reset.ino new file mode 100644 index 00000000..602aa756 --- /dev/null +++ b/arduino/eeprom_read_write_reset.ino @@ -0,0 +1,70 @@ +/* + * EEPROM Write + * + * Stores values into the EEPROM. + * These values will stay in the EEPROM when the board is + * turned off and may be retrieved later by another sketch. + * + * Writes 8 values. + * + */ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int addr = 0; + +void setup() { + // initialize serial + Serial.begin(9600); +} + +void loop() { + /*** + Need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + + // int val = analogRead(0) / 4; + + /*** + Write the value to the appropriate byte of the EEPROM. + these values will remain there when the board is + turned off. + ***/ + + Serial.println("\nEEPROM Write/Read test and Reset\n\n"); + for (int i=0; i < 9; i++) + { + EEPROM.write(i,i); + delay(500); + Serial.println(EEPROM.read(i)); + } + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ +// addr = addr + 1; +// if (addr == EEPROM.length()) { +// addr = 0; +// } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++addr &= EEPROM.length() - 1; + ***/ + + +// delay(100); +} From 060545125818f5f8af902308ea2afb6fff83bba0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 14 Dec 2020 10:59:06 -0500 Subject: [PATCH 41/41] added in x, y, z accel and blue and green LED --- arduino/Payload_BME280_MPU6050_STM32.ino | 72 ++++++++++++++++++++---- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/arduino/Payload_BME280_MPU6050_STM32.ino b/arduino/Payload_BME280_MPU6050_STM32.ino index 91e76789..030be237 100644 --- a/arduino/Payload_BME280_MPU6050_STM32.ino +++ b/arduino/Payload_BME280_MPU6050_STM32.ino @@ -14,6 +14,8 @@ MPU6050 mpu6050(Wire); int counter = 0; long timer = 0; int bmePresent; +int greenLED = 9; +int blueLED = 8; int Sensor1 = 0; int Sensor2 = 0; float Sensor3 = 0; @@ -119,12 +121,35 @@ void loop() { Serial.print(" "); Serial.print(mpu6050.getGyroZ()); - Serial.print(" XS "); - Serial.print(Sensor1); - Serial.print(" "); - Serial.print(Sensor2); - Serial.print(" "); - Serial.println(Sensor3); + Serial.print(" "); + Serial.print(mpu6050.getAccX()); + Serial.print(" "); + Serial.print(mpu6050.getAccY()); + Serial.print(" "); + Serial.print(mpu6050.getAccZ()); + + Serial.print(" XS "); + Serial.print(Sensor1); + Serial.print(" "); + Serial.print(Sensor2); + Serial.print(" "); + Serial.println(Sensor3); + + float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()* mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); +// Serial.print(rotation); +// Serial.print(" "); +// Serial.println(acceleration); + + if (acceleration > 1.2) + digitalWrite(greenLED, HIGH); + else + digitalWrite(greenLED, LOW); + + if (rotation > 5) + digitalWrite(blueLED, HIGH); + else + digitalWrite(blueLED, LOW); // Serial1.println(counter++); } @@ -168,12 +193,35 @@ void loop() { Serial1.print(" "); Serial1.print(mpu6050.getGyroZ()); - Serial1.print(" XS "); - Serial1.print(Sensor1); - Serial1.print(" "); - Serial1.print(Sensor2); - Serial1.print(" "); - Serial1.println(Sensor3); + Serial1.print(" "); + Serial1.print(mpu6050.getAccX()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccY()); + Serial1.print(" "); + Serial1.print(mpu6050.getAccZ()); + + Serial1.print(" XS "); + Serial1.print(Sensor1); + Serial1.print(" "); + Serial1.print(Sensor2); + Serial1.print(" "); + Serial1.println(Sensor3); + + float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()* mpu6050.getGyroZ()); + float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ()); +// Serial.print(rotation); +// Serial.print(" "); +// Serial.println(acceleration); + + if (acceleration > 1.2) + digitalWrite(greenLED, HIGH); + else + digitalWrite(greenLED, LOW); + + if (rotation > 5) + digitalWrite(blueLED, HIGH); + else + digitalWrite(blueLED, LOW); // Serial1.println(counter++); }