Skip to content

Commit c0e1c08

Browse files
authored
Add files via upload
1 parent 611d5f6 commit c0e1c08

28 files changed

+1711
-17
lines changed

README.md

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
# Model Rocket Computer
2-
Just an Arduino that records rocket's telemetry, detects apogee for parachute release, keep track of battery Voltage and has a Radio downlink
3-
4-
5-
**This is an updated version.**
6-
7-
**Feel free to check Archive Branch for the old version**
8-
9-
10-
11-
### Coded on Visual Studio Code
12-
- MCU: Seeeduino XIAO,
13-
- IMU: MPU6050,
14-
- Barometric Sensor: BMP388
15-
- SD Card
16-
- UART Radio
17-
1+
# Model Rocket Computer
2+
Just an Arduino that records rocket's telemetry and detects apogee for parachute release.
3+
4+
Coded on Visual Studio Code
5+
- MCU: Seeeduino XIAO,
6+
- IMU: MPU6050,
7+
- Barometric Sensor: BMP388
8+
9+
1st version of the code was written back in 2019, It has since been archived [here](https://github.com/ndanilo8/ModelRocketComputer)
10+

include/README

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
https://github.com/sebnil/Moving-Avarage-Filter--Arduino-Library-
3+
4+
The MIT License (MIT)
5+
6+
Copyright (c) 2019 Sebastian Nilsson
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.
25+
26+
********
27+
28+
A moving average, also called rolling average, rolling mean or running average, is a type of finite impulse response filter (FIR) used to analyze a set of datum points by creating a series of averages of different subsets of the full data set.
29+
https://en.wikipedia.org/wiki/Moving_average
30+
31+
*/
32+
#include "MovingAverageFilter.h"
33+
34+
MovingAverageFilter::MovingAverageFilter(unsigned int newDataPointsCount)
35+
{
36+
k = 0; //initialize so that we start to write at index 0
37+
if (newDataPointsCount < MAX_DATA_POINTS)
38+
dataPointsCount = newDataPointsCount;
39+
else
40+
dataPointsCount = MAX_DATA_POINTS;
41+
42+
for (i = 0; i < dataPointsCount; i++)
43+
{
44+
values[i] = 0; // fill the array with 0's
45+
}
46+
}
47+
48+
float MovingAverageFilter::process(float in)
49+
{
50+
out = 0;
51+
52+
values[k] = in;
53+
k = (k + 1) % dataPointsCount;
54+
55+
for (i = 0; i < dataPointsCount; i++)
56+
{
57+
out += values[i];
58+
}
59+
60+
return out / dataPointsCount;
61+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
https://github.com/sebnil/Moving-Avarage-Filter--Arduino-Library-
3+
The MIT License (MIT)
4+
5+
Copyright (c) 2019 Sebastian Nilsson
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*******
26+
A moving average, also called rolling average, rolling mean or running average, is a type of finite impulse response filter (FIR) used to analyze a set of datum points by creating a series of averages of different subsets of the full data set.
27+
https://en.wikipedia.org/wiki/Moving_average
28+
*/
29+
#ifndef MovingAverageFilter_h
30+
#define MovingAverageFilter_h
31+
32+
#define MAX_DATA_POINTS 20
33+
34+
class MovingAverageFilter
35+
{
36+
public:
37+
//construct without coefs
38+
MovingAverageFilter(unsigned int newDataPointsCount);
39+
40+
float process(float in);
41+
42+
private:
43+
float values[MAX_DATA_POINTS];
44+
int k; // k stores the index of the current array read to create a circular memory through the array
45+
int dataPointsCount;
46+
float out;
47+
int i; // just a loop counter
48+
};
49+
#endif

lib/AHRS/Altimeter/altimeter.cpp

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include <Altimeter/altimeter.h>
2+
#include <Adafruit_BMP3XX.h>
3+
// #include "MovingAverageFilter.h"
4+
#include <Chrono.h>
5+
6+
#include <global.h>
7+
#include <config.h>
8+
9+
#define SEALEVELPRESSURE_HPA (1013.25)
10+
11+
Adafruit_BMP3XX bmp;
12+
// MovingAverageFilter MAF_altitude(20);
13+
14+
Chrono apogeeTimer;
15+
16+
bool Altimeter::begin()
17+
{
18+
// Start sensor on I2C
19+
if (bmp.begin_I2C())
20+
{
21+
#if is_DEBUG
22+
Serial.println("Starting BMP --> OK!");
23+
#endif
24+
// Set up oversampling and filter initialization
25+
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
26+
bmp.setPressureOversampling(BMP3_OVERSAMPLING_8X);
27+
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
28+
bmp.setOutputDataRate(BMP3_ODR_200_HZ);
29+
30+
// KalmanInit(); // start kalman filter for the Altitude readings // KALMAN FILTER ON main.cpp
31+
32+
#if is_DEBUG
33+
Serial.print("Calculating Relative Altitude");
34+
#endif
35+
36+
for (int i = 0; i < 50; i++) // let the sensor make a few readings to get it started
37+
{
38+
bmp.readPressure();
39+
bmp.readTemperature();
40+
}
41+
42+
// Just take the average for (relative Altitude determination)
43+
for (int i = 0; i < startingAltitudeReadings; i++)
44+
{
45+
sealevel_offset += bmp.readAltitude(SEALEVELPRESSURE_HPA);
46+
47+
// ground_pressure += bmp.readPressure();
48+
49+
#if is_DEBUG
50+
Serial.print(".");
51+
#endif
52+
}
53+
sealevel_offset /= startingAltitudeReadings;
54+
55+
// ground_pressure /= 100; // Pascal to hPa
56+
// ground_pressure /= startingAltitudeReadings; // Avg to get relative ground pressure (set my AGL to 0m)
57+
58+
// Equation taken from BMP180 datasheet (page 16):
59+
// http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
60+
// current_altitude = 44330.0 * (1.0 - pow((bmp.pressure / 100.0) / ground_pressure, 0.1903)); // /100 Pascal to hPa
61+
62+
current_altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA) - sealevel_offset;
63+
data.altimeter.altitude = current_altitude;
64+
data.altimeter.temperature = bmp.readTemperature();
65+
previous_altitude = 0; // make sure this is 0
66+
67+
#if is_DEBUG
68+
Serial.println();
69+
Serial.println("LAUNCH ALTITUDE: " + String(data.altimeter.altitude) + " TEMP: " + String(data.altimeter.temperature));
70+
#endif
71+
72+
#if is_DEBUG
73+
Serial.println("PYRO CHANNELS --> OK!");
74+
#endif
75+
return true;
76+
}
77+
else
78+
{
79+
#if is_DEBUG
80+
Serial.println("Starting BMP --> FAILED!");
81+
#endif
82+
return false;
83+
}
84+
}
85+
86+
bool Altimeter::update()
87+
{
88+
if (bmp.performReading())
89+
{
90+
current_altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA) - sealevel_offset;
91+
data.altimeter.temperature = bmp.temperature;
92+
}
93+
94+
// current_altitude = MAF_altitude.process(current_altitude); // when used the Moving average filter
95+
data.altimeter.altitude = current_altitude;
96+
97+
// Record the max altitude
98+
if (current_altitude > max_altitude)
99+
{
100+
max_altitude = data.altimeter.altitude;
101+
}
102+
103+
// Replace the previous_altitude with the current altitude for next loop
104+
previous_altitude = current_altitude;
105+
return true;
106+
}
107+
108+
bool Altimeter::detectApogge()
109+
{
110+
if ((current_altitude < max_altitude))
111+
{
112+
if (apogeeTimer.hasPassed(10))
113+
{
114+
#if is_DEBUG
115+
Serial.println("---- APOGGE! ---- Max altitude: ");
116+
Serial.print(max_altitude);
117+
#endif
118+
return true;
119+
}
120+
}
121+
else
122+
{
123+
return false;
124+
}
125+
}
126+
127+
float Altimeter::getVerticalVelocity()
128+
{
129+
return (current_altitude - previous_altitude) / data.delta_t; // check data struct for the kalman derived velocity
130+
}

lib/AHRS/Altimeter/altimeter.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef ALTIMETER_H
2+
#define ALTIMETER_H
3+
4+
#include <Arduino.h>
5+
#include "data.h"
6+
7+
/**
8+
* @brief Altimeter
9+
*
10+
*/
11+
class Altimeter
12+
{
13+
public:
14+
Altimeter(){};
15+
16+
bool begin(); // return true if OK
17+
bool update(); // update Altimeter Data and it goes on top of the loop()
18+
bool detectApogge(); // detect apogge
19+
20+
private:
21+
float getVerticalVelocity();
22+
float getAltitude_Temperature();
23+
24+
float current_pressure, ground_pressure; // Pressure
25+
float previous_altitude, current_altitude, max_altitude = 0; // Altitude
26+
float startingAltitudeReadings = 16.0f; // amount of readings
27+
28+
float sealevel_offset = 0;
29+
30+
};
31+
32+
#endif /* ALTIMETER_H */

0 commit comments

Comments
 (0)