Switch float to double
This commit is contained in:
parent
cc123773b5
commit
aba9954053
|
@ -4,21 +4,21 @@
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
|
|
||||||
bool simulating = false;
|
bool simulating = false;
|
||||||
float simulatedPressure = 0.0;
|
double simulatedPressure = 0.0;
|
||||||
float inflatePSIPerSecond = 0.0;
|
double inflatePSIPerSecond = 0.0;
|
||||||
float deflatePSIPerSecond = 0.0;
|
double deflatePSIPerSecond = 0.0;
|
||||||
float pressureChangeRate = 0.0;
|
double pressureChangeRate = 0.0;
|
||||||
float deflateOffsetMultiplier = 0.0;
|
double deflateOffsetMultiplier = 0.0;
|
||||||
float inflateOffsetMultiplier = 0.0;
|
double inflateOffsetMultiplier = 0.0;
|
||||||
float offsetMultiplier = 0.0;
|
double offsetMultiplier = 0.0;
|
||||||
|
|
||||||
void initSimulation() {
|
void initSimulation() {
|
||||||
simulating = true;
|
simulating = true;
|
||||||
simulatedPressure = (float) random(10, 30);
|
simulatedPressure = (double) random(10, 30);
|
||||||
inflatePSIPerSecond = 0.0303;
|
inflatePSIPerSecond = 0.0303;
|
||||||
deflatePSIPerSecond = 0.0958;
|
deflatePSIPerSecond = 0.0958;
|
||||||
deflateOffsetMultiplier = random(3, 10) / 100.0;
|
deflateOffsetMultiplier = random(3, 10) / 100.0;
|
||||||
inflateOffsetMultiplier = 1.0 - deflateOffsetMultiplier;
|
inflateOffsetMultiplier = random(103, 160) / 100.0;
|
||||||
offsetMultiplier = 1.0;
|
offsetMultiplier = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,33 +26,33 @@ void tickSimulation() {
|
||||||
static unsigned long lastTick = millis();
|
static unsigned long lastTick = millis();
|
||||||
|
|
||||||
if (millis() > lastTick + 100) {
|
if (millis() > lastTick + 100) {
|
||||||
float pressureDelta = (millis() - lastTick) / 1000.0 * pressureChangeRate;
|
double pressureDelta = (millis() - lastTick) / 1000.0 * pressureChangeRate;
|
||||||
|
|
||||||
simulatedPressure += pressureDelta;
|
simulatedPressure += pressureDelta;
|
||||||
lastTick = millis();
|
lastTick = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void measurePressure(float &pressureValue) {
|
void measurePressure(double &pressureValue) {
|
||||||
if (simulating) {
|
if (simulating) {
|
||||||
float adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
double adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
||||||
adjusted *= offsetMultiplier;
|
adjusted *= offsetMultiplier;
|
||||||
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
||||||
} else {
|
} else {
|
||||||
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
|
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
|
||||||
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
double adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
||||||
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resamplePressure(float &pressureValue) {
|
void resamplePressure(double &pressureValue) {
|
||||||
if (simulating) {
|
if (simulating) {
|
||||||
float adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
double adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
||||||
adjusted *= offsetMultiplier;
|
adjusted *= offsetMultiplier;
|
||||||
pressureValue = adjusted;
|
pressureValue = adjusted;
|
||||||
} else {
|
} else {
|
||||||
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
|
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
|
||||||
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
double adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
||||||
pressureValue = adjusted;
|
pressureValue = adjusted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
#define SOLENOID_INFLATE 1
|
#define SOLENOID_INFLATE 1
|
||||||
#define SOLENOID_DEFLATE 2
|
#define SOLENOID_DEFLATE 2
|
||||||
|
|
||||||
#define RELAY1_PIN 11
|
#define RELAY1_PIN 7
|
||||||
#define RELAY2_PIN 7
|
#define RELAY2_PIN 11
|
||||||
|
|
||||||
#define PRESSURE_SENSOR_PIN A0
|
#define PRESSURE_SENSOR_PIN A0
|
||||||
|
|
||||||
extern float simulatedPressure;
|
extern double simulatedPressure;
|
||||||
|
|
||||||
void initSimulation();
|
void initSimulation();
|
||||||
void tickSimulation();
|
void tickSimulation();
|
||||||
void measurePressure(float &pressureValue);
|
void measurePressure(double &pressureValue);
|
||||||
void resamplePressure(float &pressureValue);
|
void resamplePressure(double &pressureValue);
|
||||||
void setSoleniod(int solenoidState);
|
void setSoleniod(int solenoidState);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,13 +72,14 @@ enum buttonStates enterButton = OPEN;
|
||||||
enum buttonStates downButton = OPEN;
|
enum buttonStates downButton = OPEN;
|
||||||
|
|
||||||
enum screenStates screenState = BOOT_UP;
|
enum screenStates screenState = BOOT_UP;
|
||||||
float pressureValue = 0.0;
|
double pressureValue = 0.0;
|
||||||
int pressureSetPoint = 0;
|
int pressureSetPoint = 0;
|
||||||
//float initialPressure = 0.0;
|
double initialPressure = 0.0;
|
||||||
//float runningPressure = 0.0;
|
//double runningPressure = 0.0;
|
||||||
float sampledPressure = 0.0;
|
double sampledPressure = 0.0;
|
||||||
|
double runningRateInv = 0.0;
|
||||||
|
|
||||||
int debounceValue(float value) {
|
int debounceValue(double value) {
|
||||||
static int prevValue = (int) value;
|
static int prevValue = (int) value;
|
||||||
|
|
||||||
if (abs(prevValue - value) > 0.4) {
|
if (abs(prevValue - value) > 0.4) {
|
||||||
|
@ -135,6 +136,8 @@ void logData() {
|
||||||
#endif
|
#endif
|
||||||
Serial.print(", sampled: ");
|
Serial.print(", sampled: ");
|
||||||
Serial.print(sampledPressure);
|
Serial.print(sampledPressure);
|
||||||
|
Serial.print(", rate (inv): ");
|
||||||
|
Serial.print(runningRateInv);
|
||||||
Serial.print(", setpoint: ");
|
Serial.print(", setpoint: ");
|
||||||
Serial.print(pressureSetPoint);
|
Serial.print(pressureSetPoint);
|
||||||
Serial.print(", state: ");
|
Serial.print(", state: ");
|
||||||
|
@ -151,6 +154,7 @@ void runUI() {
|
||||||
static unsigned long timer = millis();
|
static unsigned long timer = millis();
|
||||||
|
|
||||||
static unsigned long startTime = millis();
|
static unsigned long startTime = millis();
|
||||||
|
static unsigned long stopTime = millis();
|
||||||
static bool isInflating = false;
|
static bool isInflating = false;
|
||||||
static bool isDeflating = false;
|
static bool isDeflating = false;
|
||||||
|
|
||||||
|
@ -249,7 +253,7 @@ void runUI() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INIT_RUN:
|
case INIT_RUN:
|
||||||
//initialPressure = pressureValue;
|
initialPressure = pressureValue;
|
||||||
startTime = millis();
|
startTime = millis();
|
||||||
timer = millis();
|
timer = millis();
|
||||||
screenState = BEGIN_RUN;
|
screenState = BEGIN_RUN;
|
||||||
|
@ -284,6 +288,7 @@ void runUI() {
|
||||||
setSoleniod(SOLENOID_STOP);
|
setSoleniod(SOLENOID_STOP);
|
||||||
screenState = MEASURING;
|
screenState = MEASURING;
|
||||||
timer = millis();
|
timer = millis();
|
||||||
|
stopTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -292,6 +297,22 @@ void runUI() {
|
||||||
if (millis() >= timer + 3000) {
|
if (millis() >= timer + 3000) {
|
||||||
sampledPressure = pressureValue;
|
sampledPressure = pressureValue;
|
||||||
|
|
||||||
|
runningRateInv = (stopTime - startTime) / (sampledPressure - initialPressure);
|
||||||
|
|
||||||
|
Serial.print("stopTime: ");
|
||||||
|
Serial.print(stopTime);
|
||||||
|
Serial.print(", startTime: ");
|
||||||
|
Serial.print(startTime);
|
||||||
|
Serial.print(", sampledPressure: ");
|
||||||
|
Serial.print(sampledPressure);
|
||||||
|
Serial.print(", initialPressure: ");
|
||||||
|
Serial.print(initialPressure);
|
||||||
|
Serial.print(", rate: ");
|
||||||
|
Serial.print(runningRateInv);
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
initialPressure = sampledPressure;
|
||||||
|
|
||||||
if (isInflating && (int) sampledPressure >= pressureSetPoint) {
|
if (isInflating && (int) sampledPressure >= pressureSetPoint) {
|
||||||
screenState = SAY_DONE;
|
screenState = SAY_DONE;
|
||||||
nextState = PRESSURE;
|
nextState = PRESSURE;
|
||||||
|
@ -303,6 +324,7 @@ void runUI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = millis();
|
timer = millis();
|
||||||
|
startTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (millis() < timer + 500) {
|
if (millis() < timer + 500) {
|
||||||
|
@ -323,14 +345,17 @@ void runUI() {
|
||||||
|
|
||||||
case RUNNING:
|
case RUNNING:
|
||||||
if (enterButton == PRESSED) {
|
if (enterButton == PRESSED) {
|
||||||
|
setSoleniod(SOLENOID_STOP);
|
||||||
screenState = SAY_CANCEL;
|
screenState = SAY_CANCEL;
|
||||||
nextState = PRESSURE;
|
nextState = PRESSURE;
|
||||||
timer = millis();
|
timer = millis();
|
||||||
} else if (upButton == PRESSED) {
|
} else if (upButton == PRESSED) {
|
||||||
|
setSoleniod(SOLENOID_STOP);
|
||||||
screenState = SAY_CANCEL;
|
screenState = SAY_CANCEL;
|
||||||
nextState = PRESSURE;
|
nextState = PRESSURE;
|
||||||
timer = millis();
|
timer = millis();
|
||||||
} else if (downButton == PRESSED) {
|
} else if (downButton == PRESSED) {
|
||||||
|
setSoleniod(SOLENOID_STOP);
|
||||||
screenState = SAY_CANCEL;
|
screenState = SAY_CANCEL;
|
||||||
nextState = PRESSURE;
|
nextState = PRESSURE;
|
||||||
timer = millis();
|
timer = millis();
|
||||||
|
@ -339,9 +364,11 @@ void runUI() {
|
||||||
if (isInflating && millis() >= timer + 20000) {
|
if (isInflating && millis() >= timer + 20000) {
|
||||||
screenState = MEASURING;
|
screenState = MEASURING;
|
||||||
timer = millis();
|
timer = millis();
|
||||||
|
stopTime = millis();
|
||||||
} else if (isDeflating && millis() >= timer + 10000) {
|
} else if (isDeflating && millis() >= timer + 10000) {
|
||||||
screenState = MEASURING;
|
screenState = MEASURING;
|
||||||
timer = millis();
|
timer = millis();
|
||||||
|
stopTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInflating) {
|
if (isInflating) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user