Detecting decrease (apogee)

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");
}

}

This is wrong. Think again what you want to do.

You want to compare the value to the last time you took a reading.

Exactly, I want to compare the current reading to the last time reading. I am quite new to Arduino. How would you do this?

In the old days we used a mercury switch.

1 Like

You would have a global variable called perhaps "lastAltitude" and use that to compare it to the current altitude. Then after the comparison update this "lastAltitude" variable to the latest reading.
Note a global variable is one declared outside of any function.

1 Like

Yes that was before the world got paranoid about mercury.
It was fascinating stuff to handle.

I see what you mean. I can see how this would work if you get 10 readings.
For example altitude[9] < altitude[10], means increasing
altitude [9] > altitude [10], means decreasing and falling.

However, how is this done with 'live' readings?

Sorry for not completely understanding how to do this and being a noob to arduino.

No you don't.

if (estimated_altitude < lastReading) {
Serial.println("descending");
}
lastReading = estimated_altitude;

How is lastReading declared?

So anywhere outside of a function, it is normal for this to be just before the setup function.

float lastReading = 0;
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.