[fixes #755] Correctly calculate cg.x override
This commit is contained in:
parent
86b0b0fcbd
commit
5b94bedb5f
@ -341,6 +341,17 @@ public class MassCalculation {
|
|||||||
|
|
||||||
// mass data for *this component only* in the rocket-frame
|
// mass data for *this component only* in the rocket-frame
|
||||||
compCM = parentTransform.transform( compCM.add(component.getPosition()) );
|
compCM = parentTransform.transform( compCM.add(component.getPosition()) );
|
||||||
|
if (component.getOverrideSubcomponents()) {
|
||||||
|
if (component.isMassOverridden()) {
|
||||||
|
double newMass = MathUtil.max(component.getOverrideMass(), MIN_MASS);
|
||||||
|
Coordinate newCM = this.getCM().setWeight( newMass );
|
||||||
|
this.setCM( newCM );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.isCGOverridden()) {
|
||||||
|
this.setCM( this.getCM().setX( compCM.x + component.getOverrideCGX()));
|
||||||
|
}
|
||||||
|
}
|
||||||
this.addMass( compCM );
|
this.addMass( compCM );
|
||||||
|
|
||||||
if(null != analysisMap){
|
if(null != analysisMap){
|
||||||
@ -357,28 +368,14 @@ public class MassCalculation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double compIx = component.getRotationalUnitInertia() * compCM.weight;
|
final double compIx = component.getRotationalUnitInertia() * compCM.weight;
|
||||||
double compIt = component.getLongitudinalUnitInertia() * compCM.weight;
|
final double compIt = component.getLongitudinalUnitInertia() * compCM.weight;
|
||||||
RigidBody componentInertia = new RigidBody( compCM, compIx, compIt, compIt );
|
final RigidBody componentInertia = new RigidBody( compCM, compIx, compIt, compIt );
|
||||||
|
|
||||||
this.addInertia( componentInertia );
|
this.addInertia( componentInertia );
|
||||||
// // vvv DEBUG
|
// // vvv DEBUG
|
||||||
// if( 0 < compCM.weight ) {
|
// if( 0 < compCM.weight ) {
|
||||||
// System.err.println(String.format( "%s....componentData: %s", prefix, compCM.toPreciseString() ));
|
// System.err.println(String.format( "%s....componentData: %s", prefix, compCM.toPreciseString() ));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (component.getOverrideSubcomponents()) {
|
|
||||||
if (component.isMassOverridden()) {
|
|
||||||
double newMass = MathUtil.max(component.getOverrideMass(), MIN_MASS);
|
|
||||||
Coordinate newCM = this.getCM().setWeight( newMass );
|
|
||||||
this.setCM( newCM );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.isCGOverridden()) {
|
|
||||||
Coordinate newCM = this.getCM().setX( component.getOverrideCGX() );
|
|
||||||
this.setCM( newCM );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// // vvv DEBUG
|
// // vvv DEBUG
|
||||||
|
@ -638,6 +638,41 @@ public class TestRockets {
|
|||||||
return rocket;
|
return rocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is not a production rocket -- it is construction, purely for testing Mass Overrides
|
||||||
|
// This function is used for unit, integration tests, DO NOT CHANGE (without updating tests).
|
||||||
|
public static final Rocket makeSimple2Stage(){
|
||||||
|
Rocket rocket = new Rocket();
|
||||||
|
rocket.createFlightConfiguration( TEST_FCID_0 );
|
||||||
|
rocket.setName("Simple 2-Stage Rocket");
|
||||||
|
|
||||||
|
final double bodytubeLength = 0.10;
|
||||||
|
final double bodytubeRadius = 0.01;
|
||||||
|
final double bodytubeThickness = 0.001;
|
||||||
|
{
|
||||||
|
final AxialStage sustainerStage = new AxialStage();
|
||||||
|
sustainerStage.setName("Sustainer Stage");
|
||||||
|
rocket.addChild(sustainerStage);
|
||||||
|
|
||||||
|
final BodyTube bodytube = new BodyTube(bodytubeLength, bodytubeRadius, bodytubeThickness);
|
||||||
|
bodytube.setName("Sustainer Body Tube");
|
||||||
|
sustainerStage.addChild(bodytube);
|
||||||
|
}{
|
||||||
|
final AxialStage boosterStage = new AxialStage();
|
||||||
|
boosterStage.setName("Booster Stage");
|
||||||
|
rocket.addChild(boosterStage);
|
||||||
|
|
||||||
|
final BodyTube boosterBody = new BodyTube(bodytubeLength, bodytubeRadius, bodytubeThickness);
|
||||||
|
boosterBody.setName("Booster Body Tube");
|
||||||
|
boosterStage.addChild(boosterBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
rocket.setSelectedConfiguration( TEST_FCID_0 );
|
||||||
|
rocket.getSelectedConfiguration().setAllStages();
|
||||||
|
|
||||||
|
rocket.enableEvents();
|
||||||
|
return rocket;
|
||||||
|
}
|
||||||
|
|
||||||
public static Rocket makeBigBlue() {
|
public static Rocket makeBigBlue() {
|
||||||
Rocket rocket;
|
Rocket rocket;
|
||||||
AxialStage stage;
|
AxialStage stage;
|
||||||
|
@ -22,7 +22,6 @@ public class MassCalculatorTest extends BaseTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAlphaIIIStructure() {
|
public void testAlphaIIIStructure() {
|
||||||
System.err.println("testing AlphaIII structure");
|
|
||||||
Rocket rocket = TestRockets.makeEstesAlphaIII();
|
Rocket rocket = TestRockets.makeEstesAlphaIII();
|
||||||
rocket.setName("AlphaIII." + Thread.currentThread().getStackTrace()[1].getMethodName());
|
rocket.setName("AlphaIII." + Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||||
|
|
||||||
@ -54,7 +53,6 @@ public class MassCalculatorTest extends BaseTestCase {
|
|||||||
assertEquals("Alpha III Longitudinal MOI calculated incorrectly: ", expMOIlong, actualMOIlong, EPSILON);
|
assertEquals("Alpha III Longitudinal MOI calculated incorrectly: ", expMOIlong, actualMOIlong, EPSILON);
|
||||||
|
|
||||||
// if we use a mass override, setting to same mass, we should get same result
|
// if we use a mass override, setting to same mass, we should get same result
|
||||||
System.err.println("calculating AlphaIII with mass override");
|
|
||||||
AxialStage sustainer = (AxialStage) rocket.getChild(0);
|
AxialStage sustainer = (AxialStage) rocket.getChild(0);
|
||||||
|
|
||||||
sustainer.setOverrideSubcomponents(true);
|
sustainer.setOverrideSubcomponents(true);
|
||||||
@ -160,7 +158,54 @@ public class MassCalculatorTest extends BaseTestCase {
|
|||||||
assertEquals(" Motor Mass " + desig + " is incorrect: ", expMass, actualMotorData.getMass(), EPSILON);
|
assertEquals(" Motor Mass " + desig + " is incorrect: ", expMass, actualMotorData.getMass(), EPSILON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStageOverride() {
|
||||||
|
final Rocket rocket = TestRockets.makeSimple2Stage();
|
||||||
|
final AxialStage sustainerStage = (AxialStage) rocket.getChild(0);
|
||||||
|
final AxialStage boosterStage = (AxialStage) rocket.getChild(1);
|
||||||
|
final FlightConfiguration config = rocket.getSelectedConfiguration();
|
||||||
|
|
||||||
|
{ // [0] verify / document structure
|
||||||
|
final BodyTube sustainerBody = (BodyTube) sustainerStage.getChild(0);
|
||||||
|
assertEquals(0.0, sustainerBody.getPosition().x, EPSILON);
|
||||||
|
assertEquals(0.1, sustainerBody.getLength(), EPSILON);
|
||||||
|
|
||||||
|
final BodyTube boosterBody = (BodyTube) boosterStage.getChild(0);
|
||||||
|
assertEquals(0.10, boosterBody.getComponentLocations()[0].x, EPSILON);
|
||||||
|
assertEquals(0.10, boosterBody.getLength(), EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // [1] test Rocket CM, before:
|
||||||
|
final RigidBody actualStructure = MassCalculator.calculateStructure(config);
|
||||||
|
|
||||||
|
final double actualRocketDryMass = actualStructure.cm.weight;
|
||||||
|
final double expRocketDryMass = 0.0081178754;
|
||||||
|
assertEquals(" Alpha III Empty Mass is incorrect: ", expRocketDryMass, actualRocketDryMass, EPSILON);
|
||||||
|
|
||||||
|
final Coordinate actualRocketDryCM = actualStructure.cm;
|
||||||
|
final double expCMx = 0.10;
|
||||||
|
assertEquals("Simple Rocket CM.x is incorrect: ", expCMx, actualRocketDryCM.x, EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
boosterStage.setOverrideSubcomponents(true);
|
||||||
|
boosterStage.setCGOverridden(true);
|
||||||
|
boosterStage.setOverrideCGX(0.0);
|
||||||
|
|
||||||
|
|
||||||
|
{ // [1] test Rocket CM, before:
|
||||||
|
final RigidBody actualStructure = MassCalculator.calculateStructure(config);
|
||||||
|
|
||||||
|
final double actualRocketDryMass = actualStructure.cm.weight;
|
||||||
|
final double expRocketDryMass = 0.0081178754;
|
||||||
|
assertEquals(" Alpha III Empty Mass is incorrect: ", expRocketDryMass, actualRocketDryMass, EPSILON);
|
||||||
|
|
||||||
|
final Coordinate actualRocketDryCM = actualStructure.cm;
|
||||||
|
final double expCMx = 0.075;
|
||||||
|
assertEquals("Simple Rocket CM.x is incorrect: ", expCMx, actualRocketDryCM.x, EPSILON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFalcon9HComponentMasses() {
|
public void testFalcon9HComponentMasses() {
|
||||||
Rocket rkt = TestRockets.makeFalcon9Heavy();
|
Rocket rkt = TestRockets.makeFalcon9Heavy();
|
||||||
@ -723,7 +768,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
|||||||
double expTotalMass = overrideMass;
|
double expTotalMass = overrideMass;
|
||||||
assertEquals(" Booster Launch Mass is incorrect: ", expTotalMass, calcTotalMass, EPSILON);
|
assertEquals(" Booster Launch Mass is incorrect: ", expTotalMass, calcTotalMass, EPSILON);
|
||||||
|
|
||||||
double expCMx = 6.0;
|
double expCMx = 6.484;
|
||||||
Coordinate expCM = new Coordinate(expCMx, 0, 0, expTotalMass);
|
Coordinate expCM = new Coordinate(expCMx, 0, 0, expTotalMass);
|
||||||
assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, boosterSetCM.x, EPSILON);
|
assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, boosterSetCM.x, EPSILON);
|
||||||
assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, boosterSetCM.y, EPSILON);
|
assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, boosterSetCM.y, EPSILON);
|
||||||
@ -735,7 +780,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
|||||||
double boosterMOI_xx = burnout.getRotationalInertia();
|
double boosterMOI_xx = burnout.getRotationalInertia();
|
||||||
assertEquals(" Booster x-axis MOI is incorrect: ", expMOI_axial, boosterMOI_xx, EPSILON);
|
assertEquals(" Booster x-axis MOI is incorrect: ", expMOI_axial, boosterMOI_xx, EPSILON);
|
||||||
|
|
||||||
double expMOI_tr = 14.815925423036177;
|
double expMOI_tr = 17.86133586701;
|
||||||
double boosterMOI_tr = burnout.getLongitudinalInertia();
|
double boosterMOI_tr = burnout.getLongitudinalInertia();
|
||||||
assertEquals(" Booster transverse MOI is incorrect: ", expMOI_tr, boosterMOI_tr, EPSILON);
|
assertEquals(" Booster transverse MOI is incorrect: ", expMOI_tr, boosterMOI_tr, EPSILON);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user