Dear arduino users,
I am working on a rocket project where a parachute should be deployed when it has hit apogee.
I have a working script which measures the pressure (BMP180) and converts this to relative height. A kalman filter is used to filter out the noise. My idea was that as soon apogee (maximum height) would have been reached and the height would decrease a parachute can be deployed. This was tried with the following line:
if (estimated_altitude>2 && estimated_altitude--)
{Serial.println("descending");
}
I tried to see if this would work and walked up the stairs and almost as soon I was above 2 meters it would print 'descending', but I was still walking up the stairs and not down the stairs. Can somebody help me how to create a sort of if current_value < previous_value then deploy parachute?
Some clearification:
estimated_alittude is the height estimated using the Kalman filter and apogee should be based on this number.
This is the code that has been used:
#include <SimpleKalmanFilter.h>
#include <SFE_BMP180.h>
SimpleKalmanFilter pressureKalmanFilter(1, 1, 0.01);
SFE_BMP180 pressure;
// Serial output refresh time
const long SERIAL_REFRESH_TIME = 100;
long refresh_time;
float baseline; // baseline pressure
double getPressure() {
char status;
double T,P;
status = pressure.startTemperature();
if (status != 0) {
delay(status);
status = pressure.getTemperature(T);
if (status != 0) {
status = pressure.startPressure(3);
if (status != 0) {
delay(status);
status = pressure.getPressure(P,T);
if (status != 0) {
return(P);
}
}
}
}
}
void setup() {
Serial.begin(115200);
// BMP180 Pressure sensor start
if (!pressure.begin()) {
Serial.println("BMP180 Pressure Sensor Error!");
while(1); // Pause forever.
}
baseline = getPressure();
}
void loop() {
float p = getPressure();
float altitude = pressure.altitude(p,baseline);
float estimated_altitude = pressureKalmanFilter.updateEstimate(altitude);
if (millis() > refresh_time) {
Serial.print(altitude,6);
Serial.print(",");
Serial.print(estimated_altitude,6);
Serial.println();
refresh_time=millis()+SERIAL_REFRESH_TIME;
}
if (estimated_altitude>2 && estimated_altitude--)
{Serial.println("descending");
}
}