def test_ToolAndModel(self): # Test tools module. cmc = osim.CMCTool() model = osim.Model() model.setName('alphabet') cmc.setModel(model) assert cmc.getModel().getName() == 'alphabet'
def generate_results(self, root_dir, args): self.parse_args(args) from transform_and_filter_ground_reaction import \ transform_and_filter_ground_reaction # TODO: We aren't actually using this filtered file yet. transform_and_filter_ground_reaction( os.path.join(root_dir, 'resources/Rajagopal2016/emg_walk_raw.anc'), os.path.join(root_dir, 'resources/Rajagopal2016/grf_walk.mot'), 'ground_reaction_forces', 'rlr', mode='multicutoff') modelProcessor = self.create_model_processor(root_dir) cmc = osim.CMCTool( os.path.join(root_dir, 'code/motion_prescribed_walking_cmc_setup.xml')) analyze = osim.AnalyzeTool( os.path.join(root_dir, 'code/motion_prescribed_walking_analyze_setup.xml')) # 2.5 minute if self.cmc: cmc.run() analyze.run() mesh_interval = (self.final_time - self.initial_time) / 25.0 # 8 minutes if self.inverse: solution_filepath = self.mocoinverse_solution_file % root_dir self.solve_inverse(root_dir, modelProcessor, mesh_interval, solution_filepath) # TODO # # 0.04 and 0.03 work # inverse.set_mesh_interval(0.01) # # inverse.set_convergence_tolerance(1e-4) # solution = inverse.solve() # solution.getMocoSolution().write(self.mocoinverse_fine_solution_file % root_dir) # MocoInverse, minimize joint reactions # ------------------------------------- inverse = self.create_inverse(root_dir, modelProcessor, mesh_interval) study = inverse.initialize() problem = study.updProblem() reaction_r = osim.MocoJointReactionGoal('reaction_r', 0.005) reaction_r.setJointPath('/jointset/walker_knee_r') reaction_r.setReactionMeasures(['force-x', 'force-y']) reaction_l = osim.MocoJointReactionGoal('reaction_l', 0.005) reaction_l.setJointPath('/jointset/walker_knee_l') reaction_l.setReactionMeasures(['force-x', 'force-y']) problem.addGoal(reaction_r) problem.addGoal(reaction_l) solver = osim.MocoCasADiSolver.safeDownCast(study.updSolver()) # 13 minutes. if self.knee: solution_reaction = study.solve() solution_reaction.write(self.mocoinverse_jointreaction_solution_file % root_dir)
def computedMuscleControl(): allDir = list(directories.main(directories)) paramsDir = allDir[1] subID = allDir[4] subResultsDir = allDir[5] ikResultsDir = allDir[6] idResultsDir = allDir[7] rraResultsDir = allDir[9] cmcResultsDir = allDir[10] # Input Files idData = idResultsDir + "/subject01_walk1_extLoads.xml" rraKinematics = rraResultsDir + "/" + "_kinematics_q.sto" adjustedModel = rraResultsDir + "/" + subID + "_adjustedModel.osim" # Set XML file Variables cmcTasks = paramsDir + "/" + "cmcTasks.xml" cmcActuators = paramsDir + "/" + "cmcActuators.xml" cmcControlConstraints = paramsDir + "/" + "cmcControlConstraints.xml" osimGUI = paramsDir + "/" + "osimGUI.xml" if os.path.exists(cmcResultsDir): shutil.rmtree(cmcResultsDir, ignore_errors=True) if not os.path.exists(cmcResultsDir): os.mkdir(cmcResultsDir) # Load Model aModel = osim.Model(adjustedModel) # initialize system aModel.initSystem() cmcTool = osim.CMCTool() cmcTool.setModel(aModel) cmcTool.setModelFilename(subID + ".osim") cmcTool.setDesiredKinematicsFileName(rraKinematics) cmcTool.setTaskSetFileName(cmcTasks) cmcTool.setExternalLoadsFileName(idData) cmcTool.setConstraintsFileName(cmcControlConstraints) cmcTool.setStartTime(0.8) cmcTool.setFinalTime(1.2) cmcTool.setLowpassCutoffFrequency(-1) cmcTool.setMaxDT(1) cmcTool.setMinDT(0.0000000001) cmcTool.setErrorTolerance(0.00001) # Force Set myForceSet = osim.ForceSet(aModel, cmcActuators) cmcTool.setReplaceForceSet(False) cmcTool.setResultsDir(cmcResultsDir) # Manually append Force Set modelForceSet = aModel.updForceSet() for i in range(myForceSet.getSize()): aModel.updForceSet().append(myForceSet.get(i)) cmcTool.run() cmcTool.printToXML(cmcResultsDir + "/" + "cmcSetup.xml") return ()
def test_AnalysisToolModel(self): # Test analyses module. cmc = osim.CMCTool() model = osim.Model() model.setName('eggplant') fr = osim.ForceReporter() fr.setName('strong') cmc.setModel(model) cmc.getAnalysisSet().adoptAndAppend(fr) assert cmc.getModel().getName() == 'eggplant' assert cmc.getAnalysisSet().get(0).getName() == 'strong'