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

Varying air pressure fixed #117

Merged
merged 4 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
16 changes: 8 additions & 8 deletions app/src/main/java/src/land/LandingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class LandingController
private final double grav = 1.352; // acceleration due to gravity
private final double k = 1.38064852e-23; // Boltzmann constants
private final double m = 27.60867588e-3; // average molar mass of air molecules

protected double stepSize = 1;
protected double deployParachuteHeight = 5000;
protected int parachuteState = 0;
protected boolean parachuteDeployed = false;

public ArrayList<LanderObject> plotTrajectory(Vector3d landerLocation,
Vector3d landerVelocity,
double landerMass,
double landerMass,
Vector3d planetLocation,
Vector3d planetVelocity,
double planetMass,
Expand All @@ -50,14 +50,14 @@ public ArrayList<LanderObject> plotTrajectory(Vector3d landerLocation,

ArrayList<LanderObject> trajectory = new ArrayList<LanderObject>();

Logger.logCSV("landing_controller", "Time,Pos X, Pos Y, Pos Z, Vel X, Vel Y, Vel Z");
Logger.logCSV("landing_controller3", "Time,Pos X, Pos Y, Pos Z, Vel X, Vel Y, Vel Z");

double time = 0;
while(!testHeight(currentState.position.get(0), currentState.position.get(1), planetRadius))
{
Logger.logCSV("landing_controller", time + "," + currentState.position.get(0).toCSV() + currentState.velocity.get(0).toCSV());
Logger.logCSV("landing_controller3", time + "," + currentState.position.get(0).toCSV() + currentState.velocity.get(0).toCSV());

Vector3d drag = calculateDrag(currentState.velocity.get(0), currentState.position.get(0), stepSize);
Vector3d drag = calculateDrag(currentState.velocity.get(0), currentState.position.get(0), stepSize, planetRadius);
currentState.velocity.set(0, currentState.velocity.get(0).sub(drag));
currentState = solver.step(f, time, currentState, stepSize);

Expand Down Expand Up @@ -111,7 +111,7 @@ public Vector3d removeZDimension(Vector3d v)
* Implementing Fd = Cd * rho * (V^2 * Area)/2 * unitVector
* Represents (respectively): Force of drag = dragCoefficient * airDensity * magnitudeOfVelocity^2 * 1/2 * unitVector
*/
public Vector3d calculateDrag(Vector3d velocity, Vector3d position, double stepSize)
public Vector3d calculateDrag(Vector3d velocity, Vector3d position, double stepSize, double radius)
{
if (velocity.getX() == 0 && velocity.getY() == 0)
return new Vector3d(0,0,0);
Expand All @@ -121,7 +121,7 @@ public Vector3d calculateDrag(Vector3d velocity, Vector3d position, double stepS
totalArea = totalArea + getParachuteState();

double veloMagnitude = velocity.norm();
double drag = DRAG_COEFFICIENT * airPresSeaLevel * ((totalArea * (veloMagnitude * veloMagnitude))/2);
double drag = DRAG_COEFFICIENT * airPressureScaling(position, radius) * ((totalArea * (veloMagnitude * veloMagnitude))/2);
drag = drag * stepSize;

Vector3d direction = velocity.unitVector();
Expand Down Expand Up @@ -212,7 +212,7 @@ else if (-radius<realDistance && realDistance<=0) { //touching or inside the p
return airPresSeaLevel;
}

double scaleOfDistance = realDistance/atmosphereMaxRange;
double scaleOfDistance = 1-(realDistance/atmosphereMaxRange);
return scaleOfDistance*airPresSeaLevel;
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/src/land/OpenLoopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public ArrayList<LanderObject> plotTrajectory(Vector3d landerLocation,
if(!parachuteDeployed && testHeight(currentState.position.get(0), currentState.position.get(1), planetRadius + deployParachuteHeight))
deployParachute();

Vector3d drag = calculateDrag(currentState.velocity.get(0), currentState.position.get(0), stepSize);
Vector3d drag = calculateDrag(currentState.velocity.get(0), currentState.position.get(0), stepSize, planetRadius);
currentState.velocity.set(0, currentState.velocity.get(0).sub(drag));
currentState = solver.step(f, time, currentState, stepSize);

trajectory.add(new LanderObject(currentState.position.get(0), 0));
trajectory.add(new LanderObject(currentState.position.get(0), 0));
time = time + stepSize;

if(time > 1e7)// Safety cutoff
Expand Down
36 changes: 25 additions & 11 deletions app/src/test/java/src/test/TestLandingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ void logBallFallFromOrbit()
{
LandingController controller = new LandingController();
Vector3d velocity = new Vector3d(5,10,0);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position, 1);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position, 1, 1); //placeholder radius value
Vector3d expectedDrag = new Vector3d(-608.5377,-1217.0754,-0);
assertEquals(expectedDrag.getX(),drag.getX(),0.01);
assertEquals(expectedDrag.getY(),drag.getY(),0.01);
assertEquals(expectedDrag.getZ(),drag.getZ(),0.01);
}
}

/**
* Tests drag for negative velocity
Expand All @@ -198,7 +198,7 @@ void logBallFallFromOrbit()
LandingController controller = new LandingController();
Vector3d velocity = new Vector3d(-5,-10,0);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position, 1);
Vector3d drag = controller.calculateDrag(velocity,position, 1, 1);
Vector3d expectedDrag = new Vector3d(608.5377,1217.0754,0);
System.out.println(drag.getX());
System.out.println(drag.getY());
Expand All @@ -220,7 +220,7 @@ void logBallFallFromOrbit()
LandingController controller = new LandingController();
Vector3d velocity = new Vector3d(0,0,0);
Vector3d position = new Vector3d();
Vector3d drag = controller.calculateDrag(velocity,position, 1);
Vector3d drag = controller.calculateDrag(velocity,position, 1, 1);
Vector3d expectedDrag = new Vector3d(0,0,0);
assertEquals(expectedDrag.getX(),drag.getX());
assertEquals(expectedDrag.getY(),drag.getY());
Expand Down Expand Up @@ -261,11 +261,13 @@ void logBallFallFromOrbit()


/*
* Partitions:
* Out of the atmosphere's range
* In the atmoshpere's range
* Touching the radius
* On/inside the planet
* PARTITIONS:
* Out of the atmosphere's range
* In the atmoshpere's range
* Touching the radius
* On/inside the planet
* Just above halfway
* Just below halfway
*/
@Test void testAirPresScalingAboveMax() {
LandingController control = new LandingController();
Expand All @@ -285,9 +287,21 @@ void logBallFallFromOrbit()
System.out.println(control.airPressureScaling(position,10));
}

@Test void testAirPresScalingHalfway() {
@Test void testAirPresScalingHalfway() { //should be 0.75
LandingController control = new LandingController();
Vector3d position = new Vector3d(0,500000,0);
System.out.println(control.airPressureScaling(position,200000));
}

@Test void testAirPresScalingHalfOffsetUp() { //should be less than 0.75
LandingController control = new LandingController();
Vector3d position = new Vector3d(0,550000,0);
System.out.println(control.airPressureScaling(position,200000));
}

@Test void testAirPresScalingHalfOffsetDown() { //should be more than 0.75
LandingController control = new LandingController();
Vector3d position = new Vector3d(0,450000,0);
System.out.println(control.airPressureScaling(position,200000));
}
}