def setUp(self): simRunner = Simulation( "MAPLEAF/Examples/Simulations/EventDetector.mapleaf", silent=True) self.rocket = simRunner.createRocket() self.rocket.rigidBody.time = 30 # Set to arbitrary time > 1 sec self.calledCount = 0 self.eventDetector = SimEventDetector(self.rocket)
def setUp(self): simDef = SimDefinition("MAPLEAF/Examples/Simulations/Canards.mapleaf", silent=True) simDef.setValue("SimControl.loggingLevel", "0") simDef.setValue("Rocket.ControlSystem.MomentController.gainTableFilePath", "MAPLEAF/Examples/TabulatedData/testPIDControlLaw.txt") simDef.setValue("Rocket.Sustainer.Canards.Actuators.deflectionTablePath","MAPLEAF/Examples/TabulatedData/testFinDeflectionLaw.txt") simDef.removeKey("Rocket.ControlSystem.FlightPlan.filePath") simRunner = Simulation(simDefinition=simDef, silent=True) self.rocket = simRunner.createRocket()
def test_stagedInitialization(self): # Check that positions of objects in first and second stages are different. The stages are otherwise identical, except the first stage doesn't have a nosecone bodyTube1 = self.stagingRocket.stages[0].getComponentsOfType( RecoverySystem)[0] firstStageRecoveryPosition = bodyTube1.position.Z bodyTube2 = self.stagingRocket.stages[1].getComponentsOfType( RecoverySystem)[0] secondStageRecoveryPosition = bodyTube2.position.Z self.assertEqual(firstStageRecoveryPosition - 4.011, secondStageRecoveryPosition) orbitalSimRunner = Simulation( "MAPLEAF/Examples/Simulations/NASATwoStageOrbitalRocket.mapleaf", silent=True) rocket = orbitalSimRunner.createRocket() initInertia = rocket.getInertia(0, rocket.rigidBody.state) self.assertAlmostEqual(initInertia.mass, 314000.001, 2)
def test_instantTurn(self): simulationDefinition = SimDefinition("MAPLEAF/Examples/Simulations/Canards.mapleaf", silent=True) # Use an ideal moment controller simulationDefinition.setValue("Rocket.ControlSystem.MomentController.Type", "IdealMomentController") # Set initial direction to be pointing directly upwards simulationDefinition.setValue("Rocket.initialDirection", "(0 0 1)") # Ask for an Immediate Turn simulationDefinition.setValue("Rocket.ControlSystem.desiredFlightDirection", "(0 1 1)") runner = Simulation(simDefinition=simulationDefinition, silent=True) rocket = runner.createRocket() # Take a time step and check that the desired direction has been achieved immediately rocket.timeStep(0.01) currentDirection = rocket.rigidBody.state.orientation.rotate(Vector(0,0,1)) expectedDirection = Vector(0,1,1).normalize() assertVectorsAlmostEqual(self, currentDirection, expectedDirection, 5)
def setUpClass(cls): simRunner1 = Simulation("MAPLEAF/Examples/Simulations/test2.mapleaf", silent=True) cls.rocket = simRunner1.createRocket() simRunner2 = Simulation("MAPLEAF/Examples/Simulations/test6.mapleaf", silent=True) cls.rocket2 = simRunner2.createRocket() canardRunner = Simulation( "MAPLEAF/Examples/Simulations/Canards.mapleaf", silent=True) canardRunner.simDefinition.setValue("SimControl.loggingLevel", "0") cls.canardRocket = canardRunner.createRocket() cls.originalCanardRocketState = cls.canardRocket.rigidBody.state cls.stagingRunner = Simulation( "MAPLEAF/Examples/Simulations/Staging.mapleaf", silent=True) cls.stagingRunner.simDefinition.setValue("SimControl.loggingLevel", "0") cls.stagingRocket = cls.stagingRunner.createRocket()
def test_BarrowmanCPLocation(self): # Check that for a cone, XCP = 0.666 Length length = 1 baseArea = 1 tipArea = 0 volume = baseArea * length / 3 XCP_cone = AeroFunctions.Barrowman_GetCPLocation( length, tipArea, baseArea, volume) self.assertAlmostEqual(XCP_cone.Z, -0.666666666) # Check that for a tangent ogive nosecone, XCP = 0.466 Length SimRunner = Simulation("MAPLEAF/Examples/Simulations/test3.mapleaf", silent=True) rocket = SimRunner.createRocket() rocketNosecone = rocket.stages[0].getComponentsOfType(NoseCone)[0] noseconeLength = rocketNosecone.length expectedCp = rocketNosecone.position + Vector( 0, 0, -0.46666 * noseconeLength) actualCp = rocketNosecone.CPLocation assertVectorsAlmostEqual(self, expectedCp, actualCp, 2)
def test_AddAndRemoveTimeSteppingConstraint(self): simDefinition = SimDefinition("MAPLEAF/Examples/Simulations/Canards.mapleaf", silent=True) simDefinition.setValue("SimControl.loggingLevel", "0") # Set time step incompatible with a fixed control system update rate, and a larger initial time step simDefinition.setValue("SimControl.timeDiscretization", "RK45Adaptive") simDefinition.setValue("SimControl.timeStep", "0.02") simDefinition.setValue("TimeStepAdaptation.controller", "PID") # Make the recovery system deploy immediately simDefinition.setValue("Rocket.Sustainer.RecoverySystem.stage1Trigger", "Time") simDefinition.setValue("Rocket.Sustainer.RecoverySystem.stage1TriggerValue", "0.005") simDefinition.setValue("Rocket.Sustainer.RecoverySystem.stage1DelayTime", "0") # Set a fixed control system update rate simDefinition.setValue("Rocket.ControlSystem.updateRate", "100") simRunner = Simulation(simDefinition=simDefinition) rocket = simRunner.createRocket() # Check that the time step has been changed to be fixed, and is 0.01 seconds self.assertTrue(isinstance(rocket.rigidBody.integrate, ClassicalIntegrator)) # As oppopsed to AdaptiveIntegrator self.assertEqual(rocket.rigidBody.integrate.method, "RK4") # Check it's been switched from RK45Adaptive integrationResult = rocket.timeStep(0.01) # Recovery system should deploy during this time step rocket.simEventDetector.triggerEvents() # Time stepping should revert to the original method self.assertAlmostEqual(integrationResult.timeStepAdaptationFactor, 1.0) self.assertAlmostEqual(integrationResult.dt, 0.01) # Check that original time stepping method is back self.assertTrue(isinstance(rocket.rigidBody.integrate, AdaptiveIntegrator)) self.assertEqual(rocket.rigidBody.integrate.method, "RK45Adaptive") integrationResult2 = rocket.timeStep(0.01) self.assertTrue(abs(integrationResult2.timeStepAdaptationFactor - 1.0) > 0.00000000000000001) self.assertEqual(integrationResult2.dt, 0.01)
def setUp(self): # Init rocket + environment simRunner = Simulation(simDefinitionFilePath= "MAPLEAF/Examples/Simulations/Recovery.mapleaf", silent=True) self.recoveryRocket = simRunner.createRocket() self.rSys = self.recoveryRocket.recoverySystem self.environment = self.recoveryRocket.environment velDown = Vector(0, 0, -100) velUp = Vector(0, 0, 100) pos = Vector(0, 0, 500) orientation = Quaternion(axisOfRotation=Vector(0, 0, 1), angle=0) angVel = AngularVelocity(rotationVector=Vector(0, 0, 0)) self.descendingState = RigidBodyState(pos, velDown, orientation, angVel) self.descendingState_3DoF = RigidBodyState_3DoF(pos, velDown) self.descendingTime = 2 self.ascendingState = RigidBodyState(pos, velUp, orientation, angVel) self.ascendingState_3DoF = RigidBodyState_3DoF(pos, velUp) self.ascendingTime = 2
def test_delayedStaging(self): # Create simRunner & Rocket simDef = deepcopy(self.stagingRunner.simDefinition) simDef.setValue("SimControl.timeDiscretization", "RK4") simDef.setValue("Rocket.FirstStage.separationDelay", "0.01") stagingSimRunner = Simulation(simDefinition=simDef, silent=True) twoStageRocket = stagingSimRunner.createRocket() # Initialize properties in the simRunner required for stage separation. These are normally created in simRunner._run stagingSimRunner.rocketStages = [twoStageRocket] stagingSimRunner.dts = [0.011] stagingSimRunner.endDetectors = [ stagingSimRunner._getEndDetectorFunction( twoStageRocket, stagingSimRunner.simDefinition) ] stagingSimRunner.stageFlightPaths = [ stagingSimRunner._setUpCachingForFlightAnimation(twoStageRocket) ] # Set separation delay, take first time step twoStageRocket.rigidBody.time = 4.99 # 0.01 seconds before motor burnout (5 seconds) twoStageRocket.timeStep( 0.011 ) # Past motor burnout - should schedule delayed separation for 10.511 seconds twoStageRocket.simEventDetector.triggerEvents() # Sim time reached: 5.01 # Check that separation has not triggered self.assertEqual(len(twoStageRocket.stages), 2) # Take time step that triggers separation twoStageRocket.timeStep( 0.011) # Past delayed separation point (5.011 seconds) twoStageRocket.simEventDetector.triggerEvents() # Sim time reached: 5.012 # Check that separation has triggered self.assertEqual(len(twoStageRocket.stages), 1)