-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.h
More file actions
67 lines (57 loc) · 2.3 KB
/
simulation.h
File metadata and controls
67 lines (57 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _SIMULATION_H
#define _SIMULATION_H
#include "loopThrottle.h";
#include "sensorData.h";
#define SAMPLE_SIMULATION 1
struct simulationConfig {
double RocketMass = 1.76; // kg // from OR 3" rocket
double MotorFuelBurnRate = 0.176; // kg/s // from OR 3" rocket
double MotorFuelBurnTime = 1.6; // kg/s // from OR 3" rocket
double MotorFuelMass = 0.316; // kg // from OR 3" rocket
double MotorThrust = 2485.796; // m/s // from OR 3" rocket
double CrossSection = 4.56e-3; // m^20.0762 // from OR 3" rocket
double DragCoefficient = 0.87; // from OR 3" rocket
int sampleRate = 100;
};
// Very simple, and not very realistic, simulation only on the X and Y axis.
class simulation {
public:
simulation();
bool isRunning();
void outputSerialList();
void start(long initialAltitude);
void stop();
accelerometerValues valueAcceleration();
double valueAltitude();
private:
double AirDensity = 1.292; // kg/m^3
double AirDensityScale = 5600.0; // m -- height at which density is halved
double EarthMass = 5.97e24; // kg
double GravConstant = 6.67e-11; // m^3/kg/s^2;
double EarthRadius = 6.3e6; // m
int finalCountdown = 100;
bool _airborne = false;
double _altitudeInitial;
double _altitudeStarting;
double _burnoutTime; // s
simulationConfig _config;
float _elapsedTime;
double _motorThrust; // N
bool _running = false;
double _trace[3];
int _finalCountdown;
double _maxAltitude;
double _maxVelocity;
unsigned long _simulationTimestamp;
loopThrottle _simulationThrottle;
TaskHandle_t simulationTaskHandle;
void evaluateTimestep(float deltaT, double drag, double Mr, double Me, double G, double Ft, double *x);
void outputPrint(float delta, double mass, double thrust, double altitude, double airDensity, double drag, bool burnOut);
void outputPrintHeader();
void loopStep(float deltaT, bool output);
void simulationTask();
static void simulationTaskW(void * parameter);
};
extern simulation _simulation;
extern simulationConfig simulationConfigDefault;
#endif