def test_markAdopted2(self): a = osim.Model() # We just need the following not to cause a segfault. # Model add* pa = osim.PathActuator() pa.setName('pa') a.addForce(pa) probe = osim.Umberger2010MuscleMetabolicsProbe() probe.setName('probe') a.addProbe(probe) ma = osim.MuscleAnalysis() ma.setName('ma') a.addAnalysis(ma) pc = osim.PrescribedController() pc.setName('pc') a.addController(pc) body = osim.Body('body1', 1.0, osim.Vec3(0, 0, 0), osim.Inertia(0, 0, 0)) loc_in_parent = osim.Vec3(0, 0, 0) orient_in_parent = osim.Vec3(0, 0, 0) loc_in_body = osim.Vec3(0, 0, 0) orient_in_body = osim.Vec3(0, 0, 0) print "creating Weld Joint.." joint = osim.WeldJoint("weld_joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) print "adding a body .." a.addBody(body) print "adding a joint .." a.addJoint(joint) print "Creating a ConstantDistanceConstraint.." constr = osim.ConstantDistanceConstraint() constr.setBody1ByName("ground") constr.setBody1PointLocation(osim.Vec3(0, 0, 0)) constr.setBody2ByName("body") constr.setBody2PointLocation(osim.Vec3(1, 0, 0)) constr.setConstantDistance(1) a.addConstraint(constr) f = osim.BushingForce("bushing", "ground", "body", osim.Vec3(2, 2, 2), osim.Vec3(1, 1, 1), osim.Vec3(0, 0, 0), osim.Vec3(0, 0, 0)) a.addForce(f) f2 = osim.BushingForce() a.addForce(f2) f3 = osim.SpringGeneralizedForce() a.addForce(f3) model = osim.Model(os.path.join(test_dir, "arm26.osim")) g = osim.CoordinateActuator('r_shoulder_elev') model.addForce(g)
def generate_results(self, root_dir, args): model = osim.Model() body = osim.Body("b", 1, osim.Vec3(0), osim.Inertia(0)) model.addBody(body) joint = osim.SliderJoint("j", model.getGround(), body) joint.updCoordinate().setName("coord") model.addJoint(joint) damper = osim.SpringGeneralizedForce("coord") damper.setViscosity(-1.0) model.addForce(damper) actu = osim.CoordinateActuator("coord") model.addForce(actu) model.finalizeConnections() moco = osim.MocoStudy() problem = moco.updProblem() problem.setModel(model) problem.setTimeBounds(0, 2) problem.setStateInfo("/jointset/j/coord/value", [-10, 10], 0, 5) problem.setStateInfo("/jointset/j/coord/speed", [-10, 10], 0, 2) problem.setControlInfo("/forceset/coordinateactuator", [-50, 50]) problem.addGoal(osim.MocoControlGoal("effort", 0.5)) solver = moco.initCasADiSolver() solver.set_num_mesh_intervals(50) solution = moco.solve() solution.write(self.solution_file % root_dir)
def assisted_model(self, root_dir): model = self.muscle_driven_model(root_dir) device = osim.SpringGeneralizedForce('knee_extension_r') device.setName('spring') device.setStiffness(50) device.setRestLength(0) device.setViscosity(0) model.addForce(device) return model
def test_markAdoptedSets(): # Set's. fus = osim.FunctionSet() fu1 = osim.Constant() fus.adoptAndAppend(fu1) del fus del fu1 s = osim.ScaleSet() o = osim.Scale() s.adoptAndAppend(o) del s del o s = osim.ControlSet() o = osim.ControlLinear() s.adoptAndAppend(o) del s del o s = osim.BodyScaleSet() o = osim.BodyScale() s.adoptAndAppend(o) del s del o s = osim.PathPointSet() o = osim.PathPoint() s.adoptAndAppend(o) del s del o s = osim.IKTaskSet() o = osim.IKMarkerTask() s.adoptAndAppend(o) del s del o s = osim.MarkerPairSet() o = osim.MarkerPair() s.adoptAndAppend(o) del s del o s = osim.MeasurementSet() o = osim.Measurement() s.adoptAndAppend(o) del s del o s = osim.FrameSet() o = osim.Body() s.adoptAndAppend(o) del s del o s = osim.ForceSet() o = osim.CoordinateLimitForce() s.adoptAndAppend(o) del s del o s = osim.ForceSet() o = osim.SpringGeneralizedForce() s.append(o) s = osim.ProbeSet() o = osim.Umberger2010MuscleMetabolicsProbe() s.adoptAndAppend(o) del s del o a = osim.Model() body = osim.Body('body', 1.0, osim.Vec3(0, 0, 0), osim.Inertia(0, 0, 0) ) loc_in_parent = osim.Vec3(0, -0, 0) orient_in_parent = osim.Vec3(0, 0, 0) loc_in_body = osim.Vec3(0, 0, 0) orient_in_body = osim.Vec3(0, 0, 0) joint = osim.WeldJoint("weld_joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) a.addBody(body) constr = osim.ConstantDistanceConstraint() constr.setBody1ByName("ground") constr.setBody1PointLocation(osim.Vec3(0, 0, 0)) constr.setBody2ByName("body") constr.setBody2PointLocation(osim.Vec3(1, 0, 0)) constr.setConstantDistance(1) a.addConstraint(constr)
model.set_gravity(osim.Vec3(0, 0, 0)) body = osim.Body('body', np.multiply(0.5, mass), osim.Vec3(0), osim.Inertia(0)) model.addComponent(body) # Adding a marker to body in the model marker = osim.Marker('marker', body, osim.Vec3(0)) model.addMarker(marker) # Allows translation along x. joint = osim.SliderJoint('slider', model.getGround(), body) coord = joint.updCoordinate() coord.setName('position') model.addComponent(joint) # Adds the spring component spring = osim.SpringGeneralizedForce() spring.set_coordinate('position') spring.setRestLength(0.) spring.setStiffness(stiffness) spring.setViscosity(0.) model.addComponent(spring) # Create MocoStudy. # ================ moco = osim.MocoStudy() moco.setName('oscillator_spring_stiffness') # Define the optimal control problem. # =================================== problem = moco.updProblem()
inverse.append_output_paths('.*passive_force_multiplier') # Part 4d: Solve! Write the MocoSolution to file. inverseSolution = inverse.solve() solution = inverseSolution.getMocoSolution() solution.write('inverseSolution.sto') # Part 4e: Get the outputs we calculated from the inverse solution. inverseOutputs = inverseSolution.getOutputs() sto = osim.STOFileAdapter() sto.write(inverseOutputs, 'muscleOutputs.sto') ## Part 5: Muscle-driven Inverse Problem with Passive Assistance # Part 5a: Create a new muscle-driven model, now adding a SpringGeneralizedForce # about the knee coordinate. device = osim.SpringGeneralizedForce('knee_angle_r') device.setStiffness(50) device.setRestLength(0) device.setViscosity(0) muscleDrivenModel.addForce(device) # Part 5b: Create a ModelProcessor similar to the previous one, using the same # reserve actuator strength so we can compare muscle activity accurately. modelProcessor = osim.ModelProcessor(muscleDrivenModel) modelProcessor.append(osim.ModOpAddReserves(2)) inverse.setModel(modelProcessor) # Part 5c: Solve! Write solution. inverseDeviceSolution = inverse.solve() deviceSolution = inverseDeviceSolution.getMocoSolution() deviceSolution.write('inverseDeviceSolution.sto')