Merge pull request #315 from teyrana/fix-cg
[Fix][Issue #295] CG now correctly updates when Stages are toggled
This commit is contained in:
commit
c8eaca6cb0
@ -403,27 +403,103 @@ public class MassCalculatorTest extends BaseTestCase {
|
|||||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||||
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||||
|
|
||||||
|
FlightConfiguration config = rocket.getEmptyConfiguration();
|
||||||
|
MassCalculator mc = new MassCalculator();
|
||||||
|
|
||||||
|
{
|
||||||
|
// validate payload stage
|
||||||
|
AxialStage payloadStage = (AxialStage) rocket.getChild(0);
|
||||||
|
int plNum = payloadStage.getStageNumber();
|
||||||
|
config.setOnlyStage( plNum );
|
||||||
|
|
||||||
|
// System.err.println( config.toStageListDetail());
|
||||||
|
// System.err.println( rocket.toDebugTree());
|
||||||
|
|
||||||
|
MassData upperMass = mc.calculateBurnoutMassData( config );
|
||||||
|
Coordinate actCM = upperMass.getCM();
|
||||||
|
|
||||||
|
double expMass = 0.116287;
|
||||||
|
double expCMx = 0.278070785749;
|
||||||
|
assertEquals("Upper Stage Mass is incorrect: ", expMass, upperMass.getCM().weight, EPSILON);
|
||||||
|
|
||||||
|
assertEquals("Upper Stage CM.x is incorrect: ", expCMx, upperMass.getCM().x, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.y is incorrect: ", 0.0f, upperMass.getCM().y, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.z is incorrect: ", 0.0f, upperMass.getCM().z, EPSILON);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Validate Boosters
|
||||||
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||||
int boostNum = boosters.getStageNumber();
|
int boostNum = boosters.getStageNumber();
|
||||||
|
config.setOnlyStage( boostNum );
|
||||||
|
|
||||||
FlightConfiguration config = rocket.getEmptyConfiguration();
|
//System.err.println( config.toStageListDetail());
|
||||||
config.setOnlyStage( boostNum);
|
//System.err.println( rocket.toDebugTree());
|
||||||
|
|
||||||
// Validate Boosters
|
MassData boosterMass = mc.calculateBurnoutMassData( config);
|
||||||
MassCalculator mc = new MassCalculator();
|
|
||||||
MassData md = mc.calculateBurnoutMassData( config);
|
|
||||||
Coordinate actCM = md.getCM();
|
|
||||||
|
|
||||||
double expMass = BOOSTER_SET_NO_MOTORS_MASS;
|
double expMass = BOOSTER_SET_NO_MOTORS_MASS;
|
||||||
double expCMx = BOOSTER_SET_NO_MOTORS_CMX;
|
double expCMx = BOOSTER_SET_NO_MOTORS_CMX;
|
||||||
double calcMass = actCM.weight;
|
assertEquals("Heavy Booster Mass is incorrect: ", expMass, boosterMass.getCM().weight, EPSILON);
|
||||||
assertEquals(" Delta Heavy Booster Mass is incorrect: ", expMass, calcMass, EPSILON);
|
|
||||||
|
|
||||||
Coordinate expCM = new Coordinate(expCMx,0,0, expMass);
|
assertEquals("Heavy Booster CM.x is incorrect: ", expCMx, boosterMass.getCM().x, EPSILON);
|
||||||
assertEquals(" Delta Heavy Booster CM.x is incorrect: ", expCM.x, md.getCM().x, EPSILON);
|
assertEquals("Heavy Booster CM.y is incorrect: ", 0.0f, boosterMass.getCM().y, EPSILON);
|
||||||
assertEquals(" Delta Heavy Booster CM.y is incorrect: ", expCM.y, md.getCM().y, EPSILON);
|
assertEquals("Heavy Booster CM.z is incorrect: ", 0.0f, boosterMass.getCM().z, EPSILON);
|
||||||
assertEquals(" Delta Heavy Booster CM.z is incorrect: ", expCM.z, md.getCM().z, EPSILON);
|
}
|
||||||
assertEquals(" Delta Heavy Booster CM is incorrect: ", expCM, md.getCM() );
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCMCache() {
|
||||||
|
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||||
|
rocket.setName("TestRocket."+Thread.currentThread().getStackTrace()[1].getMethodName());
|
||||||
|
|
||||||
|
FlightConfiguration config = rocket.getEmptyConfiguration();
|
||||||
|
MassCalculator mc = new MassCalculator();
|
||||||
|
|
||||||
|
{
|
||||||
|
// validate payload stage
|
||||||
|
AxialStage payloadStage = (AxialStage) rocket.getChild(0);
|
||||||
|
int plNum = payloadStage.getStageNumber();
|
||||||
|
config.setOnlyStage( plNum );
|
||||||
|
|
||||||
|
MassData calcMass = mc.calculateBurnoutMassData( config );
|
||||||
|
|
||||||
|
double expMass = 0.116287;
|
||||||
|
double expCMx = 0.278070785749;
|
||||||
|
assertEquals("Upper Stage Mass is incorrect: ", expMass, calcMass.getCM().weight, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.x is incorrect: ", expCMx, calcMass.getCM().x, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.y is incorrect: ", 0.0f, calcMass.getCM().y, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.z is incorrect: ", 0.0f, calcMass.getCM().z, EPSILON);
|
||||||
|
|
||||||
|
MassData rocketLaunchMass = mc.getRocketLaunchMassData( config);
|
||||||
|
assertEquals("Upper Stage Mass (cache) is incorrect: ", expMass, rocketLaunchMass.getCM().weight, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.x (cache) is incorrect: ", expCMx, rocketLaunchMass.getCM().x, EPSILON);
|
||||||
|
|
||||||
|
MassData rocketSpentMass = mc.getRocketSpentMassData( config);
|
||||||
|
assertEquals("Upper Stage Mass (cache) is incorrect: ", expMass, rocketSpentMass.getCM().weight, EPSILON);
|
||||||
|
assertEquals("Upper Stage CM.x (cache) is incorrect: ", expCMx, rocketSpentMass.getCM().x, EPSILON);
|
||||||
|
}{
|
||||||
|
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1);
|
||||||
|
int boostNum = boosters.getStageNumber();
|
||||||
|
config.setOnlyStage( boostNum );
|
||||||
|
|
||||||
|
mc.voidMassCache();
|
||||||
|
MassData boosterMass = mc.calculateBurnoutMassData( config);
|
||||||
|
|
||||||
|
double expMass = BOOSTER_SET_NO_MOTORS_MASS;
|
||||||
|
double expCMx = BOOSTER_SET_NO_MOTORS_CMX;
|
||||||
|
assertEquals("Heavy Booster Mass is incorrect: ", expMass, boosterMass.getCM().weight, EPSILON);
|
||||||
|
assertEquals("Heavy Booster CM.x is incorrect: ", expCMx, boosterMass.getCM().x, EPSILON);
|
||||||
|
assertEquals("Heavy Booster CM.y is incorrect: ", 0.0f, boosterMass.getCM().y, EPSILON);
|
||||||
|
assertEquals("Heavy Booster CM.z is incorrect: ", 0.0f, boosterMass.getCM().z, EPSILON);
|
||||||
|
|
||||||
|
MassData rocketLaunchMass = mc.getRocketLaunchMassData( config);
|
||||||
|
assertEquals(" Booster Stage Mass (cache) is incorrect: ", expMass, rocketLaunchMass.getCM().weight, EPSILON);
|
||||||
|
assertEquals(" Booster Stage CM.x (cache) is incorrect: ", expCMx, rocketLaunchMass.getCM().x, EPSILON);
|
||||||
|
|
||||||
|
MassData rocketSpentMass = mc.getRocketSpentMassData( config);
|
||||||
|
assertEquals(" Booster Stage Mass (cache) is incorrect: ", expMass, rocketSpentMass.getCM().weight, EPSILON);
|
||||||
|
assertEquals(" Booster Stage CM.x (cache) is incorrect: ", expCMx, rocketSpentMass.getCM().x, EPSILON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class StageSelector extends JPanel implements StateChangeListener {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
rocket.getSelectedConfiguration().toggleStage(stageNumber);
|
rocket.getSelectedConfiguration().toggleStage(stageNumber);
|
||||||
rocket.fireComponentChangeEvent(ComponentChangeEvent.GRAPHIC_CHANGE);
|
rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user