Dave Jarvis' Repositories

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

Adds logging

Author djarvis <email>
Date 2024-12-02 23:22:14 GMT-0800
Commit 819f478d21b6399575e0b1b4bc4e11c9903c6d9c
Parent 3058b31
calculators/rocket/payload/Earth.js
airDensity(altitude) {
- const density = this.atmosphere.airDensity(altitude);
-
- return Math.max(0, density);
+ return this.atmosphere.airDensity(altitude);
}
}
calculators/rocket/payload/Rocket.js
+function LaunchResult(orbital, horizontal, target, deltaV, deltaVRocket, rocketDrag, mfr, hVelocity, vVelocity) {
+ this.orbital = orbital;
+ this.horizontal = horizontal;
+ this.target = target;
+ this.deltaV = deltaV;
+ this.deltaVRocket = deltaVRocket;
+ this.rocketDrag = rocketDrag;
+ this.mfr = mfr;
+ this.hVelocity = hVelocity;
+ this.vVelocity = vVelocity;
+}
+
+function DragLog(rho, hVelocityNet, vVelocity, totalSpeed, ballisticCoefficient, magnitude, forceRatio) {
+ this.rho = rho;
+ this.hVelocityNet = hVelocityNet;
+ this.vVelocity = vVelocity;
+ this.totalSpeed = totalSpeed;
+ this.ballisticCoefficient = ballisticCoefficient;
+ this.magnitude = magnitude;
+ this.forceRatio = forceRatio;
+}
+
+function FlightLog(time, thrust, altitude, hVelocity, vVelocity, dragForce, hAcceleration, vAcceleration, mass, massFlowRate) {
+ this.time = time;
+ this.thrust = thrust;
+ this.altitude = altitude;
+ this.hVelocity = hVelocity;
+ this.vVelocity = vVelocity;
+ this.dragForce = dragForce;
+ this.hAcceleration = hAcceleration;
+ this.vAcceleration = vAcceleration;
+ this.mass = mass;
+ this.massFlowRate = massFlowRate;
+}
+
+function RecordLog(time, altitude, hVelocity, percentSpeed, mass, magnitude) {
+ this.time = time;
+ this.altitude = altitude;
+ this.hVelocity = hVelocity;
+ this.percentSpeed = percentSpeed;
+ this.mass = mass;
+ this.magnitude = magnitude;
+}
+
class Rocket {
constructor(wet, payload, diameter, dragCoefficient, specificImpulse) {
this.totalThrust = 0.0;
this.targetAltitude = 0.0;
+ this.massFlowRate = 0.0;
const crossSectionArea = Math.PI * this.radius ** 2;
this.ballisticCoefficient = dragCoefficient * crossSectionArea;
this.flightRecorder = false;
this.launched = false;
this.relocated = false;
this.world = false;
- this.massFlowRate = 5.0;
+ this.launchResults = [];
+ this.flightLogs = [];
+ this.recordLogs = [];
+ this.dragLogs = [];
}
this.hVelocity = hVelocity + this.rotationalSpeed;
+ console.log("ROTATIONAL SPEED: " + this.rotationalSpeed);
this.vVelocity = vVelocity;
const vRocket = this.vExhaust * Math.log(this.wet / this.targetMass);
- console.info(`orbital and horizontal = ${vOrb} ${this.hVelocity}`);
- console.info(`dry + payload = ${this.targetMass}`);
- console.info(`Δv = ${vReq}; Δv rocket = ${vRocket}`);
- console.info(`mass flow rate = ${this.massFlowRate}`);
- console.info(`drag force = ${dragForce}`);
- console.info(`hVelocity = ${hVelocity}`);
- console.info(`vVelocity = ${vVelocity}`);
+ const result = new LaunchResult(vOrb, this.hVelocity, this.targetMass, vReq, vRocket, dragForce, this.massFlowRate, this.hVelocity, this.vVelocity);
+ this.launchResults.push(result);
}
const forceRatio = [-hVelocityNet / totalSpeed, -this.vVelocity / totalSpeed];
- console.info(`rho = ${rho}`);
- console.info(`hV (net) = ${hVelocityNet}`);
- console.info(`vV = ${this.vVelocity}`);
- console.info(`totalSpeed = ${totalSpeed}`);
- console.info(`bC = ${this.ballisticCoefficient}`);
- console.info(`magnitude = ${magnitude}`);
- console.info(`ratio = [${forceRatio}]`);
+ const log = new DragLog(rho, hVelocityNet, this.vVelocity, totalSpeed, this.ballisticCoefficient, magnitude, forceRatio);
+ this.dragLogs.push(log);
return [forceRatio[0] * magnitude, forceRatio[1] * magnitude];
this.hAcceleration = dragForce[0] / this.wet + hThrust / this.wet;
- this.vAcceleration = dragForce[1] / this.wet + this.planet.gravity(this.latitude, this.altitude) + vThrust / this.wet;
+ this.vAcceleration = dragForce[1] / this.wet - this.planet.gravity(this.latitude, this.altitude) + vThrust / this.wet;
// Records the initial values and all subsequent deltas.
this.wet -= this.massFlowRate * time;
-
- console.log(`Time: ${time}, Altitude: ${this.altitude}, hVelocity: ${this.hVelocity}, vVelocity: ${this.vVelocity}`);
- console.log(`Drag: ${dragForce}, hAcc: ${this.hAcceleration}, vAcc: ${this.vAcceleration}, Mass: ${this.wet}, Mass Flow Rate: ${this.massFlowRate}`);
if (this.hVelocity < this.targetVelocity) {
- const accelerationMagnitude = Math.sqrt(
+ const magnitude = Math.sqrt(
this.hAcceleration ** 2 + this.vAcceleration ** 2
- );
+ ) / 9.8;
- if (accelerationMagnitude > this.maxAcceleration &&
+ console.log(magnitude);
+
+ if (magnitude > this.maxAcceleration &&
this.vExhaust * this.massFlowRate * 0.98 > absDragForce) {
this.massFlowRate *= 0.99;
this.massFlowRate = 0.0;
}
+
+ const log = new FlightLog(time, this.totalThrust, this.altitude, this.hVelocity, this.vVelocity, dragForce, this.hAcceleration, this.vAcceleration, this.wet, this.massFlowRate);
+ this.flightLogs.push(log);
+ }
+
+ stop() {
+ console.table(this.launchResults);
+ console.table(this.dragLogs);
+ console.table(this.flightLogs);
+ console.table(this.recordLogs);
}
const percentSpeed = this.hVelocity / this.targetVelocity * 100.0;
- console.info('time, alt, hVel :',
- time,
- this.altitude,
- this.hVelocity, percentSpeed, this.wet, magnitude)
+ const recordLog = new RecordLog(time, this.altitude, this.hVelocity, percentSpeed, this.wet, magnitude);
+ this.recordLogs.push(recordLog);
}
}
calculators/rocket/payload/calculator.js
const PAYLOAD_MASS = 25.0;
const DRAG_COEFFICIENT = 0.29;
- const SPECIFIC_IMPULSE = 1700.0; // seconds
+ const SPECIFIC_IMPULSE = 1400.0; // seconds
const earth = new Earth(INITIAL_LATITUDE);
const SPEED_OF_SOUND = earth.soundSpeed(INITIAL_ALTITUDE);
- console.info( `sound speed = ${SPEED_OF_SOUND}` );
-
const INITIAL_HORIZONTAL_VELOCITY = 0;
const INITIAL_VERTICAL_VELOCITY = INITIAL_VELOCITY * SPEED_OF_SOUND;
}
+ rocket.stop();
blackBox.plot();
});
Delta 75 lines added, 32 lines removed, 43-line increase