This is Moco's simplest example.
23model.setName(
'sliding_mass')
24model.set_gravity(osim.Vec3(0, 0, 0))
25body = osim.Body(
'body', 2.0, osim.Vec3(0), osim.Inertia(0))
26model.addComponent(body)
29joint = osim.SliderJoint(
'slider', model.getGround(), body)
30coord = joint.updCoordinate()
31coord.setName(
'position')
32model.addComponent(joint)
34actu = osim.CoordinateActuator()
35actu.setCoordinate(coord)
36actu.setName(
'actuator')
37actu.setOptimalForce(1)
38model.addComponent(actu)
40body.attachGeometry(osim.Sphere(0.05))
42model.finalizeConnections()
46study = osim.MocoStudy()
47study.setName(
'sliding_mass')
51problem = study.updProblem()
55problem.setModel(model)
60problem.setTimeBounds(osim.MocoInitialBounds(0.), osim.MocoFinalBounds(0., 5.))
64problem.setStateInfo(
'/slider/position/value', osim.MocoBounds(-5, 5),
65 osim.MocoInitialBounds(0), osim.MocoFinalBounds(1))
68problem.setStateInfo(
'/slider/position/speed', [-50, 50], [0], [0])
71problem.setControlInfo(
'/actuator', osim.MocoBounds(-50, 50))
75problem.addGoal(osim.MocoFinalTimeGoal())
79solver = study.initCasADiSolver()
80solver.set_num_mesh_intervals(100)
83study.printToXML(
'sliding_mass.omoco')
87solution = study.solve()
89solution.write(
'sliding_mass_solution.sto')
91if os.getenv(
'OPENSIM_USE_VISUALIZER') !=
'0':
92 study.visualize(solution);