Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/autonoma.ca.git

Adds more vertical thrust until target altitude is reached

Author djarvis <email>
Date 2024-12-18 15:33:22 GMT-0800
Commit 2712f4668e688830c4c65a9bc364e148ff772293
Parent f5a6738
calculators/rocket/payload/Rocket.js
}
+ altitudeReached(currentAltitude, currentSpeed) {
+ const G = 6.67384e-11;
+ const R0 = 6378137.0;
+ const M = 5.97219e24;
+ const mu = G * M;
+
+ const r1 = R0 + currentAltitude;
+ const r2 = mu / (-0.5 * currentSpeed ** 2 + mu / r1);
+ return r2 - R0;
+ }
+
/**
* Checks if the rocket is still flying, i.e., if it has fuel and has not
* reached the target altitude.
*
* @returns {boolean} True if the rocket is flying.
*/
flying() {
- return this.mass > this.dryMass && this.altitude < this.targetAltitude && this.altitude > 0;
+ return (
+ this.mass > this.dryMass &&
+ this.altitude < this.targetAltitude &&
+ this.altitude > 0
+ );
}
this.tThrust = this.exhaustVelocity * this.massFlowRate;
- const thrusting = this.tThrust > 0;
- const vThrust = thrusting ? -drag[1] : 0;
- const hThrust = thrusting ? Math.sqrt(this.tThrust ** 2 - vThrust ** 2) : 0;
+ let vThrust = 0.0;
+ let hThrust = 0.0;
+
+ if (this.tThrust > 0) {
+ vThrust = -drag[1];
+
+ const reached = this.altitudeReached(this.altitude, this.vVelocity);
+
+ // Increase vertical thrust until orbital altitude is reached.
+ if (reached < this.targetAltitude) {
+ vThrust = 0.99 * this.tThrust;
+ }
+
+ if (vThrust > this.tThrust) {
+ vThrust = this.tThrust;
+ }
+
+ hThrust = Math.sqrt(this.tThrust ** 2 - vThrust ** 2)
+ }
const g = this.planet.gravity(this.latitude, this.altitude);
Delta 35 lines added, 4 lines removed, 31-line increase