added sim_mode variable, set when i2c bus 1 and 3 are off

pull/72/head
alanbjohnston 5 years ago committed by GitHub
parent 5e3612e569
commit a82fd8f5be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -125,7 +125,7 @@ float latitude = 39.027702, longitude = -77.078064;
float lat_file, long_file; float lat_file, long_file;
float axis[3], angle[3], volts_max[3], amps_max[3], batt, speed, period, tempS, temp_max, temp_min; float axis[3], angle[3], volts_max[3], amps_max[3], batt, speed, period, tempS, temp_max, temp_min;
int eclipse; int eclipse, i2c_bus0 = OFF, i2c_bus1 = OFF, i2c_bus3 = OFF, sim_mode = FALSE;
double eclipse_time; double eclipse_time;
int test_i2c_bus(int bus); int test_i2c_bus(int bus);
@ -400,6 +400,20 @@ else
} }
} }
// test i2c buses
i2c_bus0 = (test_i2c_bus(0) != -1) ? ON: OFF;
i2c_bus1 = (test_i2c_bus(1) != -1) ? ON: OFF;
i2c_bus3 = (test_i2c_bus(3) != -1) ? ON: OFF;
if ((i2c_bus1 == OFF) && (i2c_bus3 == OFF))
sim_mode = TRUE;
if (sim_mode)
{
printf("Simulated telemetry mode!\n");
srand(time(0)); srand(time(0));
axis[0] = rnd_float(-0.2, 0.2); axis[0] = rnd_float(-0.2, 0.2);
@ -424,22 +438,24 @@ amps_max[2] = (amps_avg + rnd_float(-25.0, 25.0)) * (float) cos(angle[1] - angle
batt = rnd_float(3.8, 4.3); batt = rnd_float(3.8, 4.3);
speed = rnd_float(1.0, 2.5); speed = rnd_float(1.0, 2.5);
//eclipse_time = rnd_float(0, 300);
eclipse = (rnd_float(-1, +4) > 0) ? 1 : 0; eclipse = (rnd_float(-1, +4) > 0) ? 1 : 0;
period = rnd_float(150, 300); period = rnd_float(150, 300);
tempS = rnd_float(20, 55); tempS = rnd_float(20, 55);
temp_max = rnd_float(50, 70); temp_max = rnd_float(50, 70);
temp_min = rnd_float(10,20); temp_min = rnd_float(10,20);
#ifdef DEBUG_LOGGING
for(int i=0; i < 3; i++) 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("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: %d period: %f temp: %f max: %f min: %f\n", batt, speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min); printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max: %f min: %f\n", batt, speed, eclipse_time, eclipse, period, tempS, temp_max, temp_min);
#endif
time_start = millis(); time_start = millis();
eclipse_time = millis()/1000.0; eclipse_time = millis()/1000.0;
if (eclipse == 0) if (eclipse == 0)
eclipse_time -= period/2; // if starting in eclipse, shorten interval eclipse_time -= period/2; // if starting in eclipse, shorten interval
}
int ret; int ret;
//uint8_t data[1024]; //uint8_t data[1024];
@ -1028,12 +1044,12 @@ if (firstTime != ON)
} }
fclose(cpuTempSensor); fclose(cpuTempSensor);
if (sim_mode)
{
// simulated telemetry // simulated telemetry
double time = (millis() - time_start)/1000.0; double time = (millis() - time_start)/1000.0;
printf("Eclipse time left: %d \n", period - time + eclipse_time);
if ((time - eclipse_time) > period) if ((time - eclipse_time) > period)
{ {
eclipse = (eclipse == 1) ? 0 : 1; eclipse = (eclipse == 1) ? 0 : 1;
@ -1041,9 +1057,6 @@ if (firstTime != ON)
printf("\n\nSwitching eclipse mode! \n\n"); printf("\n\nSwitching eclipse mode! \n\n");
} }
// double Xi = 10.0 * sin(1.37) * sin(2.0 * 3.14 * time / (46.0 * 2)) + rnd_float(-1, 1);
// double Yi = 8.5 * sin(1.37) * sin((2.0 * 3.14 * time / (46.0 * 2)) + (3.14/2.0)) + rnd_float(-1, 1);
// double Zi = 9.0 * cos(1.37 - 0.2) * sin((2.0 * 3.14 * time / (46.0 * 2)) + 3.14 + 0.785) + rnd_float(-1, 1);
/* /*
double Xi = eclipse * amps_max[0] * sin(2.0 * 3.14 * time / (46.0 * speed)) * fabs(sin(2.0 * 3.14 * time / (46.0 * speed))) + rnd_float(-2, 2); double Xi = eclipse * amps_max[0] * sin(2.0 * 3.14 * time / (46.0 * speed)) * fabs(sin(2.0 * 3.14 * time / (46.0 * speed))) + rnd_float(-2, 2);
double Yi = eclipse * amps_max[1] * sin((2.0 * 3.14 * time / (46.0 * speed)) + (3.14/2.0)) * fabs(sin((2.0 * 3.14 * time / (46.0 * speed)) + (3.14/2.0))) + rnd_float(-2, 2); double Yi = eclipse * amps_max[1] * sin((2.0 * 3.14 * time / (46.0 * speed)) + (3.14/2.0)) * fabs(sin((2.0 * 3.14 * time / (46.0 * speed)) + (3.14/2.0))) + rnd_float(-2, 2);
@ -1057,7 +1070,7 @@ if (firstTime != ON)
double Yv = eclipse * volts_max[1] * sin((2.0 * 3.14 * time / (46.0 * speed)) + (3.14/2.0)) + rnd_float(-0.2, 0.2); double Yv = eclipse * volts_max[1] * sin((2.0 * 3.14 * time / (46.0 * speed)) + (3.14/2.0)) + rnd_float(-0.2, 0.2);
double Zv = 2.0 * eclipse * volts_max[2] * sin((2.0 * 3.14 * time / (46.0 * speed)) + 3.14 + angle[2]) + rnd_float(-0.2, 0.2); double Zv = 2.0 * eclipse * volts_max[2] * sin((2.0 * 3.14 * time / (46.0 * speed)) + 3.14 + angle[2]) + rnd_float(-0.2, 0.2);
printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv); // printf("Yi: %f Zi: %f %f %f Zv: %f \n", Yi, Zi, amps_max[2], angle[2], Zv);
current[map[PLUS_X]] = ( Xi >= 0) ? Xi: 0; current[map[PLUS_X]] = ( Xi >= 0) ? Xi: 0;
current[map[MINUS_X]] = ( Xi >= 0) ? 0: ((-1.0) * Xi); current[map[MINUS_X]] = ( Xi >= 0) ? 0: ((-1.0) * Xi);
@ -1073,22 +1086,20 @@ if (firstTime != ON)
voltage[map[PLUS_Z]] = ( Zv >= 1) ? Zv: rnd_float(0.9, 1.1); voltage[map[PLUS_Z]] = ( Zv >= 1) ? Zv: rnd_float(0.9, 1.1);
voltage[map[MINUS_Z]] = ( Zv <= -1) ? ((-1.0) * Zv): rnd_float(0.9, 1.1); voltage[map[MINUS_Z]] = ( Zv <= -1) ? ((-1.0) * Zv): rnd_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]]); // 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); 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); IHUcpuTemp = (int)((tempS + rnd_float(-1.0, 1.0)) * 10 + 0.5);
printf("IHUcpuTemp: %d \n", IHUcpuTemp);
voltage[map[BUS]] = rnd_float(5.0, 5.005); voltage[map[BUS]] = rnd_float(5.0, 5.005);
current[map[BUS]] = rnd_float(158, 171); current[map[BUS]] = rnd_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 = 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) + rnd_float(-4.0, 4.0));
printf("Charging: %f \n", charging);
current[map[BAT]] = ((current[map[BUS]] * voltage[map[BUS]]) / (batt * 1.0)) - charging; current[map[BAT]] = ((current[map[BUS]] * voltage[map[BUS]]) / (batt * 1.0)) - 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]]); // 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[map[BAT]]/30000: current[map[BAT]]/3000; batt -= (batt > 3.5) ? current[map[BAT]]/30000: current[map[BAT]]/3000;
if (batt < 3.0) if (batt < 3.0)
@ -1099,6 +1110,7 @@ if (firstTime != ON)
voltage[map[BAT]] = batt + rnd_float(-0.01, 0.01); voltage[map[BAT]] = batt + rnd_float(-0.01, 0.01);
// end of simulated telemetry // end of simulated telemetry
}
memset(rs_frame,0,sizeof(rs_frame)); memset(rs_frame,0,sizeof(rs_frame));
memset(parities,0,sizeof(parities)); memset(parities,0,sizeof(parities));
@ -1145,7 +1157,6 @@ if (firstTime != ON)
negZv = (int)(voltage[map[MINUS_Z]] * 100); negZv = (int)(voltage[map[MINUS_Z]] * 100);
batt_c_v = (int)(voltage[map[BAT]] * 100); batt_c_v = (int)(voltage[map[BAT]] * 100);
// batt_c_v = (int)(batt * 100);
battCurr = (int)(current[map[BAT]] + 0.5) + 2048; battCurr = (int)(current[map[BAT]] + 0.5) + 2048;
PSUVoltage = (int)(voltage[map[BUS]] * 100); PSUVoltage = (int)(voltage[map[BUS]] * 100);

Loading…
Cancel
Save

Powered by TurnKey Linux.