Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Air pressure height impl #112

Merged
merged 5 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions app/src/main/java/src/land/LandingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class LandingController
private final double AIR_DENSITY = 5.428; // https://www.aero.psu.edu/avia/pubs/LanSch17.pdf, page 3
private final double LANDER_AREA = 1.91; // Mars InSight lander was 1.56 meters in diameter, pi * radius^2
private final double PARACHUTE_AREA = 1000;
private final double airPresSeaLevel = 1.5; // 1.5 bars
private final double grav = 1.352; // acceleration due to gravity
private final double k = 1.38064852e-23; // Boltzmann constants
private final double m = 27.60867588; // average molar mass of air molecules


protected boolean parachuteDeployed = false;

Expand Down Expand Up @@ -50,8 +55,9 @@ public ArrayList<LanderObject> plotTrajectory(Vector3d landerLocation,
{
Logger.logCSV("landing_controller", time + "," + currentState.position.get(0).toCSV() + currentState.velocity.get(0).toCSV());

//Vector3d drag = calculateDrag(currentState.velocity.get(0));
//currentState.velocity.set(0, currentState.velocity.get(0).add(drag));
Vector3d drag = calculateDrag(currentState.velocity.get(0),currentState.position.get(0));
currentState.velocity.set(0, currentState.velocity.get(0).add(drag));


currentState = solver.step(f, time, currentState, stepSize);
trajectory.add(new LanderObject(currentState.position.get(0), 0));
Expand Down Expand Up @@ -101,7 +107,7 @@ public Vector3d removeZDimension(Vector3d v)
* Implementing Fd = Cd * rho * V^2 * Area * 1/2 * unitVector
* Represents (respectively): Force of drag = dragCoefficient * airDensity * magnitudeOfVelocity^2 * 1/2 * unitVector
*/
public Vector3d calculateDrag(Vector3d velocity)
public Vector3d calculateDrag(Vector3d velocity, Vector3d position)
{
if (velocity.getX() == 0 && velocity.getY() == 0) {
return new Vector3d(0,0,0);
Expand All @@ -114,7 +120,7 @@ public Vector3d calculateDrag(Vector3d velocity)
if(parachuteDeployed)
totalArea = totalArea + PARACHUTE_AREA;

double constant = DRAG_COEFFICIENT * totalArea * AIR_DENSITY * veloMagnitude * veloMagnitude * 0.5;
double constant = DRAG_COEFFICIENT * LANDER_AREA * airPresSeaLevel * veloMagnitude * veloMagnitude * 0.5;

Vector3d dragForce = vectorDirection.mul(constant); //scale the unit vector by the constants we have, to get the actual drag force vector
return dragForce;
Expand All @@ -136,4 +142,48 @@ protected void deployParachute()
{
parachuteDeployed = true;
}

/*
* Method represents:
* Ph = P0 * e^((-m*g*h)/k*T
* Where:
* Ph is pressure at height, P0 pressure at seal level
* m is mass of one molecule of..., g is gravitational acceleration, h is the height
* k is Boltzmann's constant, t is the absolute temperature (in kelvin)
*
*
* if impact() is true, return 1.5 (on surface)
*/
public double airPressureAt(Vector3d height) {

double h = height.dist(new Vector3d());
double t = generateTemp(h);

double result = airPresSeaLevel * Math.exp((-m*grav*h)/k*t);
return result;
}

public double generateTemp(double height) {
if (height == 0) { // if impacted on surface hence temp is given
return 94;
}
else if (0<height && height<50000) {
long min = (long) 71;
long max = (long) 81;
double randValue = (double)Math.floor(Math.random()*(max-min+1)+min);
return randValue;
}
else if (height>=50000 && height<200000) {
long min = (long) 71;
long max = (long) 180;
double randValue = (double)Math.floor(Math.random()*(max-min+1)+min);
return randValue;
}
else {
long min = (long) 160;
long max = (long) 180;
double randValue = (double)Math.floor(Math.random()*(max-min+1)+min);
return randValue;
}
}
}
36 changes: 32 additions & 4 deletions app/src/test/java/src/test/TestLandingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ void logFallFromOrbit()
double titanRadius = 2575.5e3;
}

@Test
void logBallFallFromOrbit()
{
LandingController lc = new LandingController();

Vector3d landerPos = new Vector3d(0,20000,100);
Vector3d landerVel = new Vector3d(0,0,0);
double landerMass = 1000;
Vector3d titanPos = new Vector3d(0,0,0);
Vector3d titanVel = new Vector3d(0,0,0);
double titanMass = 1e16;
double titanRadius = 100;

Vector3d[] array = lc.plotTrajectory(landerPos, landerVel, landerMass, titanPos, titanVel, titanMass, titanRadius);
for(int i = 0;i<array.length;i++)
{
System.out.println(array[i]);
}
}


/**
* Testing Strategy:
* | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
Expand Down Expand Up @@ -158,7 +179,8 @@ void logFallFromOrbit()
{
LandingController controller = new LandingController();
Vector3d velocity = new Vector3d(5,10,0);
Vector3d drag = controller.calculateDrag(velocity);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position);
Vector3d expectedDrag = new Vector3d(-608.5377,-1217.0754,-0);
assertEquals(expectedDrag.getX(),drag.getX(),0.01);
assertEquals(expectedDrag.getY(),drag.getY(),0.01);
Expand All @@ -177,7 +199,8 @@ void logFallFromOrbit()
{
LandingController controller = new LandingController();
Vector3d velocity = new Vector3d(-5,-10,0);
Vector3d drag = controller.calculateDrag(velocity);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position);
Vector3d expectedDrag = new Vector3d(608.5377,1217.0754,0);
System.out.println(drag.getX());
System.out.println(drag.getY());
Expand All @@ -198,7 +221,8 @@ void logFallFromOrbit()
{
LandingController controller = new LandingController();
Vector3d velocity = new Vector3d(0,0,0);
Vector3d drag = controller.calculateDrag(velocity);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position);
Vector3d expectedDrag = new Vector3d(0,0,0);
assertEquals(expectedDrag.getX(),drag.getX());
assertEquals(expectedDrag.getY(),drag.getY());
Expand Down Expand Up @@ -231,6 +255,10 @@ void logFallFromOrbit()
assertEquals(control.normalise(new Vector3d(100,94,45),new Vector3d(213,432,113)),new Vector3d(-113,-338,-68));
}


@Test void testPressureAt() {
LandingController control = new LandingController();
Vector3d position = new Vector3d(0,2e25,0);
System.out.println(control.airPressureAt(position));
}

}
97 changes: 97 additions & 0 deletions app/src/test/java/src/test/TestOpenLoopController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package src.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import src.land.LandingController;
Expand All @@ -8,6 +10,101 @@

public class TestOpenLoopController {

/*
* REP. INV.:
* Height should be > radius
*
* PARTITIONS: Above | Below
* Left-hand side of planet point = -ve,0 > height| point = -ve,0 < height
* Right-hand side of planet point = +ve,0 > height| point = +ve,0 < height
* Centre above planet point = 0,+ve > height| point = 0,+ve < height
* Centre below planet point = 0,-ve > height| point = 0,-ve < height
*
* Special cases:
* Height of point == height, --> false
* Height of point, impact() is true, --> true
*/

@Test
void testAboveHeightRHSide() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(50000,0,0);
assertEquals(!controller.belowHeight(point),true);
}

@Test
void testAboveHeightLHSide() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(-50000,0,0);
assertEquals(!controller.belowHeight(point),true);
}

@Test
void testAboveHeightCentreTop() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(0,60000,0);
assertEquals(!controller.belowHeight(point),true);
}

@Test
void testAboveHeightCentreBottom() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(0,-60000,0);
assertEquals(!controller.belowHeight(point),true);
}

@Test
void testBelowHeightRHSide() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(5000,0,0);
assertEquals(controller.belowHeight(point),true);
}

@Test
void testBelowHeightLHSide() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(-5000,0,0);
assertEquals(controller.belowHeight(point),true);
}

@Test
void testBelowHeightCentreTop() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(0,6000,0);
assertEquals(controller.belowHeight(point),true);
}

@Test
void testBelowHeightCentreBottom() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(0,-6000,0);
assertEquals(controller.belowHeight(point),true);
}

@Test
void testHeightsEqual() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(0,40000,0);
assertEquals(!controller.belowHeight(point),true);
}

@Test
void testImpactTrue() {

OpenLoopController controller = new OpenLoopController();
Vector3d point = new Vector3d(100,100,0);
assertEquals(controller.belowHeight(point),true);
}

@Test
void logFallFromOrbit()
{
Expand Down