From c42a7b25987a47768b5f95a778e4efd8428a7454 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 25 Feb 2023 12:08:24 -0500 Subject: [PATCH 01/42] flush before reboot, print + each time get_input called --- cubesatsim/cubesatsim.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d3968bd8..59042f20 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4958,6 +4958,7 @@ void start_clockgen() { } void get_input() { + Serial.print("+"); // if (((skip++)%2) == 0) serial_input(); @@ -4987,7 +4988,8 @@ void get_input() { // mode = new_mode; // change modes if button pressed write_mode(new_mode); - Serial.println("Rebooting..."); + Serial.println("Rebooting..."); + Serial.flush(); watchdog_reboot (0, SRAM_END, 10); // restart Pico sleep(20.0); From e050d311928e610162e038409732ef7caf262599 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 25 Feb 2023 12:12:23 -0500 Subject: [PATCH 02/42] reboot in 500ms --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 59042f20..1236bb0f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4990,7 +4990,7 @@ void get_input() { Serial.println("Rebooting..."); Serial.flush(); - watchdog_reboot (0, SRAM_END, 10); // restart Pico + watchdog_reboot (0, SRAM_END, 500); //10); // restart Pico sleep(20.0); /* From 793815303da8f0691549fb46d757dd86d53dfcf6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 25 Feb 2023 12:24:07 -0500 Subject: [PATCH 03/42] add a serial_input to loop timer --- cubesatsim/cubesatsim.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1236bb0f..4f325c4e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -332,6 +332,7 @@ void loop() { } // get_input(); + serial_input(); // Calculate loop time if (debug_mode) { From 37db51b524f9bbbc9ebd1610088d810f90044120 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 25 Feb 2023 12:32:10 -0500 Subject: [PATCH 04/42] all reboots to 500ms and flush --- cubesatsim/cubesatsim.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4f325c4e..c9fcfc96 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4604,8 +4604,9 @@ void prompt_for_input() { break; case PROMPT_REBOOT: - Serial.println("Rebooting..."); - watchdog_reboot (0, SRAM_END, 10); // restart Pico + Serial.println("Rebooting..."); + Serial.flush(); + watchdog_reboot (0, SRAM_END, 500); // restart Pico sleep(20.0); break; @@ -4614,7 +4615,8 @@ void prompt_for_input() { // Serial.println("Reboot or power cycle to restart the CubeSatSim"); // while (1) ; // infinite loop Serial.println("Rebooting..."); - watchdog_reboot (0, SRAM_END, 10); // restart Pico + Serial.flush(); + watchdog_reboot (0, SRAM_END, 500); // restart Pico sleep(20.0); break; From 5b747ae1f7ffa38ed49a935e77f3cf2d7b6c2f97 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 25 Feb 2023 12:40:18 -0500 Subject: [PATCH 05/42] only print + if not SSTV, only do serial on interrupt for SSTV and CW modes --- cubesatsim/cubesatsim.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index c9fcfc96..ccc3998e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4961,9 +4961,9 @@ void start_clockgen() { } void get_input() { - Serial.print("+"); - - // if (((skip++)%2) == 0) + if (mode != SSTV) + Serial.print("+"); + if ((mode == CW) || (mode == SSTV)) serial_input(); // check for button press From c9bc2001a1024c00fd5fc06f42aab9e1c57c2fc3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 17:33:52 -0500 Subject: [PATCH 06/42] add prompt after serial_input --- cubesatsim/cubesatsim.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index ccc3998e..e4308a6c 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -333,6 +333,11 @@ void loop() { // get_input(); serial_input(); + if (prompt) { +// Serial.println("Need to prompt for input!"); + prompt_for_input(); + prompt = false; + } // Calculate loop time if (debug_mode) { From 5d8feebc6631ffba3fcea40a9a325cf932d64058 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 17:47:28 -0500 Subject: [PATCH 07/42] config simulated telem if read from file in setup --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index e4308a6c..7610faee 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -168,7 +168,7 @@ void setup() { */ start_ina219(); - if (i2c_bus3 == false) + if ((i2c_bus3 == false) || (sim_mode)) // if ((i2c_bus3 == false) || (mode == FSK)) // force simulated telemetry mode for FSK config_simulated_telem(); From 2c179afb0f70412e1ad51b03706c8f051f34e6c2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 17:51:08 -0500 Subject: [PATCH 08/42] print sim telem config info --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 7610faee..1e61e78f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -876,7 +876,7 @@ void config_simulated_telem() { sim_mode = TRUE; - Serial.println("Simulated telemetry mode!"); + Serial.println("Simulated telemetry mode!!"); // srand((unsigned int)time(0)); @@ -909,9 +909,9 @@ void config_simulated_telem() temp_min = rnd_float(10, 20); // #ifdef DEBUG_LOGGING -// for (int i = 0; i < 3; i++) -// printf("axis: %f angle: %f v: %f i: %f \n", axis[i], angle[i], volts_max[i], amps_max[i]); -// printf("batt: %f speed: %f eclipse_time: %f eclipse: %f period: %f temp: %f max: %f min: %f\n", batt, speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min); + for (int i = 0; i < 3; i++) + printf("axis: %f angle: %f v: %f i: %f \n", axis[i], angle[i], volts_max[i], amps_max[i]); + printf("batt: %f speed: %f eclipse_time: %f eclipse: %f period: %f temp: %f max: %f min: %f\n", batt, speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min); // #endif time_start = (long int) millis(); From 942e9dac70d264f5733900ce324996c9531c2de0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 17:55:45 -0500 Subject: [PATCH 09/42] rotation_speed --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1e61e78f..24146f8a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -910,8 +910,8 @@ void config_simulated_telem() // #ifdef DEBUG_LOGGING for (int i = 0; i < 3; i++) - printf("axis: %f angle: %f v: %f i: %f \n", axis[i], angle[i], volts_max[i], amps_max[i]); - printf("batt: %f speed: %f eclipse_time: %f eclipse: %f period: %f temp: %f max: %f min: %f\n", batt, speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min); + Serial.printf("axis: %f angle: %f v: %f i: %f \n", axis[i], angle[i], volts_max[i], amps_max[i]); + Serial.printf("batt: %f speed: %f eclipse_time: %f eclipse: %f period: %f temp: %f max: %f min: %f\n", batt, rotation_speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min); // #endif time_start = (long int) millis(); From 656422174603817b28500afb569effc9932a8f86 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:05:50 -0500 Subject: [PATCH 10/42] added rnd_float --- cubesatsim/cubesatsim.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 24146f8a..d7fc83ac 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -80,6 +80,10 @@ char call[] = "AMSAT"; // put your callsign here extern bool get_camera_image(bool debug); extern bool start_camera(); +float rnd_float(float upper, float lower) { + return (float)(random(upper*100, lower*100)/100.0); +} + void setup() { set_sys_clock_khz(133000, true); From f46715a8ae5f1d9082b3661deccd01972e89a3c2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:13:32 -0500 Subject: [PATCH 11/42] change to rand_float and add randomSeed --- cubesatsim/cubesatsim.ino | 80 ++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d7fc83ac..9f12fc55 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -80,7 +80,7 @@ char call[] = "AMSAT"; // put your callsign here extern bool get_camera_image(bool debug); extern bool start_camera(); -float rnd_float(float upper, float lower) { +float rand_float(float upper, float lower) { return (float)(random(upper*100, lower*100)/100.0); } @@ -819,13 +819,13 @@ void generate_simulated_telem() { Serial.println("\n\nSwitching eclipse mode! \n\n"); } - double Xi = eclipse * amps_max[0] * (float) sin(2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + rnd_float(-2, 2); - double Yi = eclipse * amps_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rnd_float(-2, 2); - double Zi = eclipse * amps_max[2] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + 3.14 + angle[2]) + rnd_float(-2, 2); + double Xi = eclipse * amps_max[0] * (float) sin(2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + rand_float(-2, 2); + double Yi = eclipse * amps_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rand_float(-2, 2); + double Zi = eclipse * amps_max[2] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + 3.14 + angle[2]) + rand_float(-2, 2); - double Xv = eclipse * volts_max[0] * (float) sin(2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + rnd_float(-0.2, 0.2); - double Yv = eclipse * volts_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rnd_float(-0.2, 0.2); - double Zv = 2.0 * eclipse * volts_max[2] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + 3.14 + angle[2]) + rnd_float(-0.2, 0.2); + double Xv = eclipse * volts_max[0] * (float) sin(2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + rand_float(-0.2, 0.2); + double Yv = eclipse * volts_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rand_float(-0.2, 0.2); + double Zv = 2.0 * eclipse * volts_max[2] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + 3.14 + angle[2]) + rand_float(-0.2, 0.2); // printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv); @@ -836,25 +836,25 @@ void generate_simulated_telem() { current[mapping[PLUS_Z]] = (Zi >= 0) ? Zi : 0; current[mapping[MINUS_Z]] = (Zi >= 0) ? 0 : ((-1.0f) * Zi); - voltage[mapping[PLUS_X]] = (Xv >= 1) ? Xv : rnd_float(0.9, 1.1); - voltage[mapping[MINUS_X]] = (Xv <= -1) ? ((-1.0f) * Xv) : rnd_float(0.9, 1.1); - voltage[mapping[PLUS_Y]] = (Yv >= 1) ? Yv : rnd_float(0.9, 1.1); - voltage[mapping[MINUS_Y]] = (Yv <= -1) ? ((-1.0f) * Yv) : rnd_float(0.9, 1.1); - voltage[mapping[PLUS_Z]] = (Zv >= 1) ? Zv : rnd_float(0.9, 1.1); - voltage[mapping[MINUS_Z]] = (Zv <= -1) ? ((-1.0f) * Zv) : rnd_float(0.9, 1.1); + voltage[mapping[PLUS_X]] = (Xv >= 1) ? Xv : rand_float(0.9, 1.1); + voltage[mapping[MINUS_X]] = (Xv <= -1) ? ((-1.0f) * Xv) : rand_float(0.9, 1.1); + voltage[mapping[PLUS_Y]] = (Yv >= 1) ? Yv : rand_float(0.9, 1.1); + voltage[mapping[MINUS_Y]] = (Yv <= -1) ? ((-1.0f) * Yv) : rand_float(0.9, 1.1); + voltage[mapping[PLUS_Z]] = (Zv >= 1) ? Zv : rand_float(0.9, 1.1); + voltage[mapping[MINUS_Z]] = (Zv <= -1) ? ((-1.0f) * Zv) : rand_float(0.9, 1.1); // 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.0f) : ((temp_min - tempS) / 50.0f); - tempS += +rnd_float(-1.0, 1.0); - // IHUcpuTemp = (int)((tempS + rnd_float(-1.0, 1.0)) * 10 + 0.5); + tempS += +rand_float(-1.0, 1.0); + // IHUcpuTemp = (int)((tempS + rand_float(-1.0, 1.0)) * 10 + 0.5); other[IHU_TEMP] = tempS; - voltage[mapping[BUS]] = rnd_float(5.0, 5.005); - current[mapping[BUS]] = rnd_float(158, 171); + voltage[mapping[BUS]] = rand_float(5.0, 5.005); + current[mapping[BUS]] = rand_float(158, 171); // float charging = current[map[PLUS_X]] + current[map[MINUS_X]] + current[map[PLUS_Y]] + current[map[MINUS_Y]] + current[map[PLUS_Z]] + current[map[MINUS_Z]]; - float charging = eclipse * (fabs(amps_max[0] * 0.707) + fabs(amps_max[1] * 0.707) + rnd_float(-4.0, 4.0)); + float charging = eclipse * (fabs(amps_max[0] * 0.707) + fabs(amps_max[1] * 0.707) + rand_float(-4.0, 4.0)); current[mapping[BAT]] = ((current[mapping[BUS]] * voltage[mapping[BUS]]) / batt) - charging; @@ -871,7 +871,7 @@ void generate_simulated_telem() { if (batt > 4.5) batt = 4.5; - voltage[mapping[BAT]] = batt + rnd_float(-0.01, 0.01); + voltage[mapping[BAT]] = batt + rand_float(-0.01, 0.01); // end of simulated telemetry } @@ -884,33 +884,33 @@ void config_simulated_telem() // srand((unsigned int)time(0)); - axis[0] = rnd_float(-0.2, 0.2); + axis[0] = rand_float(-0.2, 0.2); if (axis[0] == 0) - axis[0] = rnd_float(-0.2, 0.2); - axis[1] = rnd_float(-0.2, 0.2); - axis[2] = (rnd_float(-0.2, 0.2) > 0) ? 1.0 : -1.0; + axis[0] = rand_float(-0.2, 0.2); + axis[1] = rand_float(-0.2, 0.2); + axis[2] = (rand_float(-0.2, 0.2) > 0) ? 1.0 : -1.0; angle[0] = (float) atan(axis[1] / axis[2]); angle[1] = (float) atan(axis[2] / axis[0]); angle[2] = (float) atan(axis[1] / axis[0]); - volts_max[0] = rnd_float(4.5, 5.5) * (float) sin(angle[1]); - volts_max[1] = rnd_float(4.5, 5.5) * (float) cos(angle[0]); - volts_max[2] = rnd_float(4.5, 5.5) * (float) cos(angle[1] - angle[0]); + volts_max[0] = rand_float(4.5, 5.5) * (float) sin(angle[1]); + volts_max[1] = rand_float(4.5, 5.5) * (float) cos(angle[0]); + volts_max[2] = rand_float(4.5, 5.5) * (float) cos(angle[1] - angle[0]); - float amps_avg = rnd_float(150, 300); + float amps_avg = rand_float(150, 300); - amps_max[0] = (amps_avg + rnd_float(-25.0, 25.0)) * (float) sin(angle[1]); - amps_max[1] = (amps_avg + rnd_float(-25.0, 25.0)) * (float) cos(angle[0]); - amps_max[2] = (amps_avg + rnd_float(-25.0, 25.0)) * (float) cos(angle[1] - angle[0]); + amps_max[0] = (amps_avg + rand_float(-25.0, 25.0)) * (float) sin(angle[1]); + amps_max[1] = (amps_avg + rand_float(-25.0, 25.0)) * (float) cos(angle[0]); + amps_max[2] = (amps_avg + rand_float(-25.0, 25.0)) * (float) cos(angle[1] - angle[0]); - batt = rnd_float(3.8, 4.3); - rotation_speed = rnd_float(1.0, 2.5); - eclipse = (rnd_float(-1, +4) > 0) ? 1.0 : 0.0; - period = rnd_float(150, 300); - tempS = rnd_float(20, 55); - temp_max = rnd_float(50, 70); - temp_min = rnd_float(10, 20); + batt = rand_float(3.8, 4.3); + rotation_speed = rand_float(1.0, 2.5); + eclipse = (rand_float(-1, +4) > 0) ? 1.0 : 0.0; + period = rand_float(150, 300); + tempS = rand_float(20, 55); + temp_max = rand_float(50, 70); + temp_min = rand_float(10, 20); // #ifdef DEBUG_LOGGING for (int i = 0; i < 3; i++) @@ -1491,7 +1491,7 @@ int twosToInt(int val,int len) { // Convert twos compliment to integer return(val); } - +/* float rnd_float(double min,double max) { // returns 2 decimal point random number int val = (rand() % ((int)(max*100) - (int)(min*100) + 1)) + (int)(min*100); @@ -1499,7 +1499,7 @@ float rnd_float(double min,double max) { // returns 2 decimal point random num return(ret); } - +*/ float toAprsFormat(float input) { // converts decimal coordinate (latitude or longitude) to APRS DDMM.MM format int dd = (int) input; @@ -3766,6 +3766,8 @@ void config_gpio() { pinMode(TEMPERATURE_PIN, INPUT); Serial.print("Diode voltage (temperature): "); Serial.println(analogRead(TEMPERATURE_PIN)); + + randomSeed(analogRead(TEMPERATURE_PIN); pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); From 69ca808e8a92f45fefbe60e2a5d7e0002fece8c6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:15:13 -0500 Subject: [PATCH 12/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9f12fc55..b453a363 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3767,7 +3767,7 @@ void config_gpio() { Serial.print("Diode voltage (temperature): "); Serial.println(analogRead(TEMPERATURE_PIN)); - randomSeed(analogRead(TEMPERATURE_PIN); + randomSeed(analogRead(TEMPERATURE_PIN)); pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); From a3822a8ff374e819890833139f3cc9fdb1a380f3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:20:39 -0500 Subject: [PATCH 13/42] switch upper and lower for rand_float --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b453a363..5c4a34ae 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -80,7 +80,7 @@ char call[] = "AMSAT"; // put your callsign here extern bool get_camera_image(bool debug); extern bool start_camera(); -float rand_float(float upper, float lower) { +float rand_float(float lower, float upper) { return (float)(random(upper*100, lower*100)/100.0); } From 07ebf90f4bd4a739fd55b4acca00a69cbbaaeb23 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:24:39 -0500 Subject: [PATCH 14/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 5c4a34ae..cda2f114 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -911,6 +911,12 @@ void config_simulated_telem() tempS = rand_float(20, 55); temp_max = rand_float(50, 70); temp_min = rand_float(10, 20); + + time_start = (long int) millis(); + + eclipse_time = (long int)(millis() / 1000.0); + if (eclipse == 0.0) + eclipse_time -= period / 2; // if starting in eclipse, shorten interval // #ifdef DEBUG_LOGGING for (int i = 0; i < 3; i++) @@ -918,11 +924,7 @@ void config_simulated_telem() Serial.printf("batt: %f speed: %f eclipse_time: %f eclipse: %f period: %f temp: %f max: %f min: %f\n", batt, rotation_speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min); // #endif - time_start = (long int) millis(); - eclipse_time = (long int)(millis() / 1000.0); - if (eclipse == 0.0) - eclipse_time -= period / 2; // if starting in eclipse, shorten interval // } // tx_freq_hz -= tx_channel * 50000; From 44a3e070e83561d5758123a181e7f38bf4127661 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:31:46 -0500 Subject: [PATCH 15/42] prints in gen_sim --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index cda2f114..7cfd83a7 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -818,6 +818,7 @@ void generate_simulated_telem() { if (debug_mode) Serial.println("\n\nSwitching eclipse mode! \n\n"); } + Serial.println((eclipse == 1.0)); double Xi = eclipse * amps_max[0] * (float) sin(2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + rand_float(-2, 2); double Yi = eclipse * amps_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rand_float(-2, 2); @@ -827,7 +828,7 @@ void generate_simulated_telem() { double Yv = eclipse * volts_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rand_float(-0.2, 0.2); double Zv = 2.0 * eclipse * volts_max[2] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + 3.14 + angle[2]) + rand_float(-0.2, 0.2); - // printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv); + Serial.printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv); current[mapping[PLUS_X]] = (Xi >= 0) ? Xi : 0; current[mapping[MINUS_X]] = (Xi >= 0) ? 0 : ((-1.0f) * Xi); From 2e62d493b286061eb8642f19fd102d8395e4af00 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 18:38:44 -0500 Subject: [PATCH 16/42] add prints in sim telemetry --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 7cfd83a7..3902375d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -844,7 +844,7 @@ void generate_simulated_telem() { voltage[mapping[PLUS_Z]] = (Zv >= 1) ? Zv : rand_float(0.9, 1.1); voltage[mapping[MINUS_Z]] = (Zv <= -1) ? ((-1.0f) * Zv) : rand_float(0.9, 1.1); - // 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]]); + Serial.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.0f) : ((temp_min - tempS) / 50.0f); tempS += +rand_float(-1.0, 1.0); @@ -859,7 +859,7 @@ void generate_simulated_telem() { current[mapping[BAT]] = ((current[mapping[BUS]] * voltage[mapping[BUS]]) / batt) - charging; - // printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[map[BAT]], current[map[BUS]], batt, voltage[map[BUS]]); + Serial.printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[map[BAT]], current[map[BUS]], batt, voltage[map[BUS]]); batt -= (batt > 3.5) ? current[mapping[BAT]] / 30000 : current[mapping[BAT]] / 3000; if (batt < 3.0) { @@ -873,6 +873,7 @@ void generate_simulated_telem() { batt = 4.5; voltage[mapping[BAT]] = batt + rand_float(-0.01, 0.01); + Serial.printf("Batt voltage: %f \n", voltage[mapping[BAT]]); // end of simulated telemetry } From e89aa379ce0251c7fb2c667e2bb197a032359223 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 19:59:58 -0500 Subject: [PATCH 17/42] map to mapping in printfs --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 3902375d..c4adcbd3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -844,7 +844,7 @@ void generate_simulated_telem() { voltage[mapping[PLUS_Z]] = (Zv >= 1) ? Zv : rand_float(0.9, 1.1); voltage[mapping[MINUS_Z]] = (Zv <= -1) ? ((-1.0f) * Zv) : rand_float(0.9, 1.1); - Serial.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]]); + Serial.printf("temp: %f Time: %f Eclipse: %d : %f %f | %f %f | %f %f\n",tempS, time, eclipse, voltage[mapping[PLUS_X]], voltage[mapping[MINUS_X]], voltage[mapping[PLUS_Y]], voltage[mapping[MINUS_Y]], current[mapping[PLUS_Z]], current[mapping[MINUS_Z]]); tempS += (eclipse > 0) ? ((temp_max - tempS) / 50.0f) : ((temp_min - tempS) / 50.0f); tempS += +rand_float(-1.0, 1.0); @@ -859,7 +859,7 @@ void generate_simulated_telem() { current[mapping[BAT]] = ((current[mapping[BUS]] * voltage[mapping[BUS]]) / batt) - charging; - Serial.printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[map[BAT]], current[map[BUS]], batt, voltage[map[BUS]]); + Serial.printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[mapping[BAT]], current[mapping[BUS]], batt, voltage[mapping[BUS]]); batt -= (batt > 3.5) ? current[mapping[BAT]] / 30000 : current[mapping[BAT]] / 3000; if (batt < 3.0) { From 1bd407c568373dac51efe447482119e4c8402f3f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 Feb 2023 20:12:52 -0500 Subject: [PATCH 18/42] add temp add read --- cubesatsim/cubesatsim.ino | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index c4adcbd3..e9f8be5b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3771,7 +3771,15 @@ void config_gpio() { Serial.print("Diode voltage (temperature): "); Serial.println(analogRead(TEMPERATURE_PIN)); - randomSeed(analogRead(TEMPERATURE_PIN)); + adc_gpio_init(29); + adc_select_input(4); + const float conversion_factor = 3.27f / (1 << 12); + uint16_t raw = adc_read(); + float result = raw * conversion_factor; + float temp = 27 - (result - 0.706)/0.001721; + Serial.printf(" temp = %f C", temp); + + randomSeed(raw); pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); From ca9ebee8cbfcc4ae722404b77b98cc655799d65b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 16:43:29 -0500 Subject: [PATCH 19/42] print raw temp --- cubesatsim/cubesatsim.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index e9f8be5b..162c1080 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3775,6 +3775,7 @@ void config_gpio() { adc_select_input(4); const float conversion_factor = 3.27f / (1 << 12); uint16_t raw = adc_read(); + Serial.printf("Raw: %d\n",raw); float result = raw * conversion_factor; float temp = 27 - (result - 0.706)/0.001721; Serial.printf(" temp = %f C", temp); From 02b54c0b3dd7f04440f9a58ad2e2a1f817fdc5c9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:02:40 -0500 Subject: [PATCH 20/42] print 20 random values at start --- cubesatsim/cubesatsim.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 162c1080..aa02511f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3781,6 +3781,9 @@ void config_gpio() { Serial.printf(" temp = %f C", temp); randomSeed(raw); + + for (int j=0; j++; j < 20) + Serial.println(rand_float(-.2, .2); pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); From d1cf77a3e1dbe3e4c574de4db5b114b6d5cb7fdb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:30:18 -0500 Subject: [PATCH 21/42] fixed rand_float --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index aa02511f..bab8e476 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -81,7 +81,8 @@ extern bool get_camera_image(bool debug); extern bool start_camera(); float rand_float(float lower, float upper) { - return (float)(random(upper*100, lower*100)/100.0); + + return (float)(random(lower*100, upperf*100)/100.0); } void setup() { From 2754230250f412afadad47c54a2eaf7e37499730 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:31:25 -0500 Subject: [PATCH 22/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bab8e476..9fc1d010 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3783,7 +3783,7 @@ void config_gpio() { randomSeed(raw); - for (int j=0; j++; j < 20) + for (int j=0; j<20; j <++) Serial.println(rand_float(-.2, .2); pinMode(AUDIO_IN_PIN, INPUT); From 3b837e07faf50012ce3cd9b6772b862a36a04c68 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:33:12 -0500 Subject: [PATCH 23/42] typo --- cubesatsim/cubesatsim.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9fc1d010..4a975e93 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -82,7 +82,7 @@ extern bool start_camera(); float rand_float(float lower, float upper) { - return (float)(random(lower*100, upperf*100)/100.0); + return (float)(random(lower*100, upper*100)/100.0); } void setup() { @@ -95,8 +95,7 @@ void setup() { LittleFS.begin(); // LittleFS.format(); // only format if files of size 0 keep showing up - - read_mode(); + read_mode() // mode = BPSK; // force to BPSK From c8385c06ce4d4b906fc63e805196a121abb95f0d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:34:04 -0500 Subject: [PATCH 24/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 4a975e93..490c105d 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -95,7 +95,7 @@ void setup() { LittleFS.begin(); // LittleFS.format(); // only format if files of size 0 keep showing up - read_mode() + read_mode(); // mode = BPSK; // force to BPSK From 03d5a594607b543bed184dd690f472cae455a209 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:34:59 -0500 Subject: [PATCH 25/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 490c105d..1647bbae 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3782,7 +3782,7 @@ void config_gpio() { randomSeed(raw); - for (int j=0; j<20; j <++) + for (int j=0; j<20; j++) Serial.println(rand_float(-.2, .2); pinMode(AUDIO_IN_PIN, INPUT); From 7ff976802ad243c5ca7c5e9b6ca1d765d0912d18 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:35:46 -0500 Subject: [PATCH 26/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1647bbae..0589a8e6 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3783,7 +3783,7 @@ void config_gpio() { randomSeed(raw); for (int j=0; j<20; j++) - Serial.println(rand_float(-.2, .2); + Serial.println(rand_float(-.2, .2)); pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); From 8a81598ac5d9bf62155aebc8a4d6ca2401aeceba Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:41:13 -0500 Subject: [PATCH 27/42] make PSU same as battery in sim telem --- cubesatsim/cubesatsim.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 0589a8e6..bb8d97ae 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -851,8 +851,8 @@ void generate_simulated_telem() { // IHUcpuTemp = (int)((tempS + rand_float(-1.0, 1.0)) * 10 + 0.5); other[IHU_TEMP] = tempS; - voltage[mapping[BUS]] = rand_float(5.0, 5.005); - current[mapping[BUS]] = rand_float(158, 171); +// voltage[mapping[BUS]] = rand_float(5.0, 5.005); +// current[mapping[BUS]] = rand_float(158, 171); // float charging = current[map[PLUS_X]] + current[map[MINUS_X]] + current[map[PLUS_Y]] + current[map[MINUS_Y]] + current[map[PLUS_Z]] + current[map[MINUS_Z]]; float charging = eclipse * (fabs(amps_max[0] * 0.707) + fabs(amps_max[1] * 0.707) + rand_float(-4.0, 4.0)); @@ -873,6 +873,10 @@ void generate_simulated_telem() { batt = 4.5; voltage[mapping[BAT]] = batt + rand_float(-0.01, 0.01); + + voltage[mapping[BUS]] = voltage[mapping[BAT]]; + current[mapping[BUS]] = current[mapping[BAT]]; + Serial.printf("Batt voltage: %f \n", voltage[mapping[BAT]]); // end of simulated telemetry From 537355283d81d11ab5724e36e2b77d2347aba1b8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:44:34 -0500 Subject: [PATCH 28/42] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index bb8d97ae..9ce12e06 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -851,8 +851,8 @@ void generate_simulated_telem() { // IHUcpuTemp = (int)((tempS + rand_float(-1.0, 1.0)) * 10 + 0.5); other[IHU_TEMP] = tempS; -// voltage[mapping[BUS]] = rand_float(5.0, 5.005); -// current[mapping[BUS]] = rand_float(158, 171); + voltage[mapping[BUS]] = rand_float(5.0, 5.005); + current[mapping[BUS]] = rand_float(158, 171); // float charging = current[map[PLUS_X]] + current[map[MINUS_X]] + current[map[PLUS_Y]] + current[map[MINUS_Y]] + current[map[PLUS_Z]] + current[map[MINUS_Z]]; float charging = eclipse * (fabs(amps_max[0] * 0.707) + fabs(amps_max[1] * 0.707) + rand_float(-4.0, 4.0)); From 95208cfdc7e99c619aeb602b60ea2ae06edcc986 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 17:54:41 -0500 Subject: [PATCH 29/42] remove sim telem prints --- cubesatsim/cubesatsim.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9ce12e06..81e043bf 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -818,7 +818,7 @@ void generate_simulated_telem() { if (debug_mode) Serial.println("\n\nSwitching eclipse mode! \n\n"); } - Serial.println((eclipse == 1.0)); +// Serial.println((eclipse == 1.0)); double Xi = eclipse * amps_max[0] * (float) sin(2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + rand_float(-2, 2); double Yi = eclipse * amps_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rand_float(-2, 2); @@ -828,7 +828,7 @@ void generate_simulated_telem() { double Yv = eclipse * volts_max[1] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + (3.14 / 2.0)) + rand_float(-0.2, 0.2); double Zv = 2.0 * eclipse * volts_max[2] * (float) sin((2.0 * 3.14 * time_stamp / (46.0 * rotation_speed)) + 3.14 + angle[2]) + rand_float(-0.2, 0.2); - Serial.printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv); +// Serial.printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv); current[mapping[PLUS_X]] = (Xi >= 0) ? Xi : 0; current[mapping[MINUS_X]] = (Xi >= 0) ? 0 : ((-1.0f) * Xi); @@ -844,7 +844,7 @@ void generate_simulated_telem() { voltage[mapping[PLUS_Z]] = (Zv >= 1) ? Zv : rand_float(0.9, 1.1); voltage[mapping[MINUS_Z]] = (Zv <= -1) ? ((-1.0f) * Zv) : rand_float(0.9, 1.1); - Serial.printf("temp: %f Time: %f Eclipse: %d : %f %f | %f %f | %f %f\n",tempS, time, eclipse, voltage[mapping[PLUS_X]], voltage[mapping[MINUS_X]], voltage[mapping[PLUS_Y]], voltage[mapping[MINUS_Y]], current[mapping[PLUS_Z]], current[mapping[MINUS_Z]]); +// Serial.printf("temp: %f Time: %f Eclipse: %d : %f %f | %f %f | %f %f\n",tempS, time, eclipse, voltage[mapping[PLUS_X]], voltage[mapping[MINUS_X]], voltage[mapping[PLUS_Y]], voltage[mapping[MINUS_Y]], current[mapping[PLUS_Z]], current[mapping[MINUS_Z]]); tempS += (eclipse > 0) ? ((temp_max - tempS) / 50.0f) : ((temp_min - tempS) / 50.0f); tempS += +rand_float(-1.0, 1.0); @@ -859,7 +859,7 @@ void generate_simulated_telem() { current[mapping[BAT]] = ((current[mapping[BUS]] * voltage[mapping[BUS]]) / batt) - charging; - Serial.printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[mapping[BAT]], current[mapping[BUS]], batt, voltage[mapping[BUS]]); + // Serial.printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[mapping[BAT]], current[mapping[BUS]], batt, voltage[mapping[BUS]]); batt -= (batt > 3.5) ? current[mapping[BAT]] / 30000 : current[mapping[BAT]] / 3000; if (batt < 3.0) { @@ -876,8 +876,8 @@ void generate_simulated_telem() { voltage[mapping[BUS]] = voltage[mapping[BAT]]; current[mapping[BUS]] = current[mapping[BAT]]; - - Serial.printf("Batt voltage: %f \n", voltage[mapping[BAT]]); + +// Serial.printf("Batt voltage: %f \n", voltage[mapping[BAT]]); // end of simulated telemetry } From d5bd07b0d4686dc506ada2d25c5716403b670960 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:18:16 -0500 Subject: [PATCH 30/42] added get_cpu_temp --- cubesatsim/cubesatsim.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 26373e7f..64d037cd 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -139,6 +139,8 @@ volatile int prompt = false; char serial_string[128]; +float get_cpu_temp(); + //#define WAV_DATA_LENGTH (50000 * 8) uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; From af10ce6807bc2d1c4813e62503798649a40dc333 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:23:18 -0500 Subject: [PATCH 31/42] added read_cpu_temp --- cubesatsim/cubesatsim.ino | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 81e043bf..44d5446b 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -3775,16 +3775,9 @@ void config_gpio() { Serial.print("Diode voltage (temperature): "); Serial.println(analogRead(TEMPERATURE_PIN)); - adc_gpio_init(29); - adc_select_input(4); - const float conversion_factor = 3.27f / (1 << 12); - uint16_t raw = adc_read(); - Serial.printf("Raw: %d\n",raw); - float result = raw * conversion_factor; - float temp = 27 - (result - 0.706)/0.001721; - Serial.printf(" temp = %f C", temp); - - randomSeed(raw); + adc_gpio_init(29); // setup internal temperature sensor + Serial.printf("CPU Temperature: %4.1f \n", get_cpu_temp()); + randomSeed(get_cpu_temp()); for (int j=0; j<20; j++) Serial.println(rand_float(-.2, .2)); @@ -5058,3 +5051,18 @@ void transmit_led(bool status) { digitalWrite(MAIN_LED_BLUE, status); } } + +float get_cpu_temp() { + + adc_select_input(4); + const float conversion_factor = 3.27f / (1 << 12); + uint16_t raw = adc_read(); + // Serial.printf("Raw: %d\n",raw); + float result = raw * conversion_factor; + float temp = 27 - (result - 0.706)/0.001721; + // Serial.printf(" temp = %f C", temp); + + return(temp); + +} + From 214992b8800f106f837e68fef034245f866df154 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:26:46 -0500 Subject: [PATCH 32/42] include cpu temp as other[IHU_TEMP] --- cubesatsim/cubesatsim.ino | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 44d5446b..571912b2 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -768,8 +768,9 @@ void get_tlm_ao7() { tlm[3][B_] = (int)(voltage[mapping[BUS]] * 10.0) % 100; // 5V supply to Pi -// tlm[4][A] = (int)((95.8 - other[IHU_TEMP]) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet - tlm[4][A_] = (int)((95.8 - analogReadTemp()) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet + other[IHU_TEMP] = get_cpu_temp(); + tlm[4][A] = (int)((95.8 - other[IHU_TEMP]) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet +// tlm[4][A_] = (int)((95.8 - analogReadTemp()) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet tlm[6][B_] = 0; tlm[6][D_] = 49 + rand() % 3; @@ -1242,6 +1243,7 @@ void get_tlm_fox() { encodeB(b_min, 49 + head_offset, 2048); } } + other[IHU_TEMP] = get_cpu_temp(); // Serial.println("C"); encodeA(b, 30 + head_offset, PSUVoltage); encodeB(b, 31 + head_offset, ((int)(other[SPIN] * 10)) + 2048); @@ -3778,9 +3780,6 @@ void config_gpio() { adc_gpio_init(29); // setup internal temperature sensor Serial.printf("CPU Temperature: %4.1f \n", get_cpu_temp()); randomSeed(get_cpu_temp()); - - for (int j=0; j<20; j++) - Serial.println(rand_float(-.2, .2)); pinMode(AUDIO_IN_PIN, INPUT); Serial.print("Audio In: "); From 1e6ccdc65a97e7abd1a4232775d33783bb31db7e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:27:41 -0500 Subject: [PATCH 33/42] A_ typo --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 571912b2..ea0ad67c 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -769,7 +769,7 @@ void get_tlm_ao7() { tlm[3][B_] = (int)(voltage[mapping[BUS]] * 10.0) % 100; // 5V supply to Pi other[IHU_TEMP] = get_cpu_temp(); - tlm[4][A] = (int)((95.8 - other[IHU_TEMP]) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet + tlm[4][A_] = (int)((95.8 - other[IHU_TEMP]) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet // tlm[4][A_] = (int)((95.8 - analogReadTemp()) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet tlm[6][B_] = 0; From 4edc3218d74de543ace2245f00228078753200fb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:46:43 -0500 Subject: [PATCH 34/42] read cpu temp in ina219 so doesn't override sim mode --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index ea0ad67c..87f2aff5 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -768,7 +768,6 @@ void get_tlm_ao7() { tlm[3][B_] = (int)(voltage[mapping[BUS]] * 10.0) % 100; // 5V supply to Pi - other[IHU_TEMP] = get_cpu_temp(); tlm[4][A_] = (int)((95.8 - other[IHU_TEMP]) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet // tlm[4][A_] = (int)((95.8 - analogReadTemp()) / 1.48 + 0.5) % 100; // was [B] but didn't display in online TLM spreadsheet @@ -1243,7 +1242,6 @@ void get_tlm_fox() { encodeB(b_min, 49 + head_offset, 2048); } } - other[IHU_TEMP] = get_cpu_temp(); // Serial.println("C"); encodeA(b, 30 + head_offset, PSUVoltage); encodeB(b, 31 + head_offset, ((int)(other[SPIN] * 10)) + 2048); @@ -2293,6 +2291,9 @@ void test_radio() void read_ina219() { + + other[IHU_TEMP] = get_cpu_temp(); + unsigned long read_time = millis(); unsigned long read_time_total = millis(); if (voltage_read && !i2c_bus1 && !i2c_bus3) From 29379094bc9fcb8b20e91b264bff9ecde6aa76fb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:57:52 -0500 Subject: [PATCH 35/42] added reset_min_max --- cubesatsim/cubesatsim.ino | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 87f2aff5..9d5adcdf 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -721,6 +721,8 @@ void config_telem() { if (debug_mode) Serial.println("Clearing min and max telemetry values"); + reset_max_min(); +/* for (int i = 0; i < 9; i++) { voltage_min[i] = 1000.0; current_min[i] = 1000.0; @@ -735,7 +737,8 @@ void config_telem() { for (int i = 0; i < 3; i++) { other_min[i] = 1000.0; other_max[i] = -1000.0; - } + } +*/ firstTime = TRUE; } @@ -4550,10 +4553,12 @@ void prompt_for_input() { get_serial_char(); if ((serial_string[0] == 'y') || (serial_string[0] == 'Y')) { Serial.println("Setting Simulated telemetry to on"); + reset_min_max(); config_simulated_telem(); write_config_file(); } else if ((serial_string[0] == 'n') || (serial_string[0] == 'N')) { Serial.println("Setting Simulated telemetry to off"); + reset_min_max(); sim_mode = false; if (!ina219_started) start_ina219(); @@ -5065,4 +5070,25 @@ float get_cpu_temp() { return(temp); } + +void reset_min_max() { + + for (int 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; + } + 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++) { + other_min[i] = 1000.0; + other_max[i] = -1000.0; + } + + +} From a46499e588ff458969d1526a195060f83ae7045d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 18:58:37 -0500 Subject: [PATCH 36/42] added reset_min_max() --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 64d037cd..9ad25fe0 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -221,6 +221,7 @@ void load_sstv_image_1_as_cam_dot_jpg(); void load_sstv_image_2_as_cam_dot_jpg(); void get_input(); void transmit_led(bool status); +void reset_min_max(); #ifndef STASSID #define STASSID "Pico" From 50ebf224c90a854aee9efd87b771752c310fd42a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 19:00:04 -0500 Subject: [PATCH 37/42] max min typo --- cubesatsim/cubesatsim.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 9d5adcdf..f40c70bc 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -721,7 +721,7 @@ void config_telem() { if (debug_mode) Serial.println("Clearing min and max telemetry values"); - reset_max_min(); + reset_min_max(); /* for (int i = 0; i < 9; i++) { voltage_min[i] = 1000.0; From 02897ac9fead11e544b4c71f35765d05872bd826 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 27 Feb 2023 19:06:23 -0500 Subject: [PATCH 38/42] added v and i BUS to zero if no battery --- cubesatsim/cubesatsim.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index f40c70bc..d7a832ee 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2406,6 +2406,8 @@ void read_ina219() } else { voltage[BAT] = 0.0; current[BAT] = 0.0; + voltage[BUS] = 0.0; + current[BUS] = 0.0; } if (i2c5) { From 647278461363f4df74e5fc50f21ac177cbf16cae Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 28 Feb 2023 00:11:50 -0500 Subject: [PATCH 39/42] added prompting --- cubesatsim/cubesatsim.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 9ad25fe0..4bdcb82c 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -137,6 +137,8 @@ #define PAYLOAD_CLEAR 3 volatile int prompt = false; +volatile int prompting = false; + char serial_string[128]; float get_cpu_temp(); From ba0b31bc72fc1fd90e3012a33776290d21566a15 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 28 Feb 2023 00:13:30 -0500 Subject: [PATCH 40/42] added prompting --- cubesatsim/cubesatsim.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index d7a832ee..3159c5e6 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4464,8 +4464,11 @@ void serial_input() { } } -void prompt_for_input() { +void prompt_for_input() { float float_result; + + if (!prompting) { + prompting = true; while (Serial.available() > 0) // clear any characters in serial input buffer Serial.read(); @@ -4838,7 +4841,9 @@ void prompt_for_input() { break; } - prompt = false; + prompt = false; + prompting = false; + } } void get_serial_string() { From d518fbab038e7a51a87766f0ba7448968aaa8167 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 28 Feb 2023 00:18:45 -0500 Subject: [PATCH 41/42] print when prompting --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 3159c5e6..1d4bb593 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4843,7 +4843,8 @@ void prompt_for_input() { } prompt = false; prompting = false; - } + } else + Serial.println("Already prompting!"); } void get_serial_string() { From 6bea66ee8e90bc466655aa7e0d1aa9607215c11f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 28 Feb 2023 00:28:59 -0500 Subject: [PATCH 42/42] remove else prompting print --- cubesatsim/cubesatsim.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1d4bb593..9fcd7781 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -4843,8 +4843,9 @@ void prompt_for_input() { } prompt = false; prompting = false; - } else - Serial.println("Already prompting!"); + } +// else +// Serial.println("Already prompting!"); } void get_serial_string() {