예제 #1
0
    u_init = InitialConditionsList()
    u_init.add([tau_init] * biorbd_model.nbGeneralizedTorque() +
               [muscle_init] * biorbd_model.nbMuscleTotal())
    # ------------- #

    return OptimalControlProgram(
        biorbd_model,
        dynamics,
        number_shooting_points,
        final_time,
        x_init,
        u_init,
        x_bounds,
        u_bounds,
        objective_functions,
    )


if __name__ == "__main__":
    ocp = prepare_ocp(biorbd_model_path="arm26.bioMod",
                      final_time=2,
                      number_shooting_points=20)

    # --- Solve the program --- #
    sol = ocp.solve(show_online_optim=True)

    # --- Show results --- #
    result = ShowResult(ocp, sol)
    result.animate()
예제 #2
0
    return OptimalControlProgram(
        biorbd_model,
        problem_type,
        number_shooting_points,
        phase_time,
        X_init,
        U_init,
        X_bounds,
        U_bounds,
        objective_functions,
        constraints,
        tau_mapping=tau_mapping,
    )


if __name__ == "__main__":
    model_path = "2segments_4dof_2contacts.bioMod"
    t = 0.5
    ns = 20
    ocp = prepare_ocp(model_path=model_path,
                      phase_time=t,
                      number_shooting_points=ns,
                      use_actuators=False)

    # --- Solve the program --- #
    sol = ocp.solve(show_online_optim=True)

    # --- Show results --- #
    result = ShowResult(ocp, sol)
    result.animate(nb_frames=40)
예제 #3
0
    u_init = InitialConditionsList()
    u_init.add([tau_init] * biorbd_model.nbGeneralizedTorque() +
               [muscle_init] * biorbd_model.nbMuscleTotal())
    # ------------- #

    return OptimalControlProgram(
        biorbd_model,
        dynamics,
        number_shooting_points,
        final_time,
        x_init,
        u_init,
        x_bounds,
        u_bounds,
        objective_functions,
    )


if __name__ == "__main__":
    ocp = prepare_ocp(biorbd_model_path="arm26_with_contact.bioMod",
                      final_time=2,
                      number_shooting_points=20)

    # --- Solve the program --- #
    sol = ocp.solve(show_online_optim=True)

    # --- Show results --- #
    result = ShowResult(ocp, sol)
    result.animate(show_meshes=False)
    result.graphs()
        biorbd_model,
        dynamics,
        number_shooting_points,
        final_time,
        x_init,
        u_init,
        x_bounds,
        u_bounds,
        objective_functions,
        nb_integration_steps=5,
        control_type=control_type,
    )


if __name__ == "__main__":
    ocp = prepare_ocp(
        biorbd_model_path="cube_and_line.bioMod",
        number_shooting_points=30,
        final_time=2,
        marker_velocity_or_displacement="disp",  # "velo"
        marker_in_first_coordinates_system=True,
        control_type=ControlType.LINEAR_CONTINUOUS,
    )

    # --- Solve the program --- #
    sol = ocp.solve(show_online_optim=True)

    # --- Show results --- #
    result = ShowResult(ocp, sol)
    result.animate(nb_frames=200)
예제 #5
0
        x_bounds,
        u_bounds,
        objective_functions,
        nb_threads=nb_threads,
        use_SX=use_SX,
    )


if __name__ == "__main__":
    ocp = prepare_ocp(
        biorbd_model_path="pendulum.bioMod", final_time=3, number_shooting_points=41, nb_threads=4, use_SX=True
    )

    # --- Solve the program --- #
    tic = time()
    sol_ip = ocp.solve(solver=Solver.IPOPT)
    toc = time() - tic
    print(f"Time to solve with IPOPT: {toc}sec")
    tic = time()
    sol_ac = ocp.solve(solver=Solver.ACADOS)
    toc = time() - tic
    print(f"Time to solve with ACADOS: {toc}sec")

    # --- Show results --- #
    result_ip = ShowResult(ocp, sol_ip)
    result_ac = ShowResult(ocp, sol_ac)
    result_ip.graphs()
    result_ac.graphs()
    result_ip.animate()
    result_ac.animate()
예제 #6
0
        "CoM_dot",
        lambda x, u, p: plot_CoM_dot(x, "../models/jumper2contacts.bioMod"),
        phase_number=0,
        plot_type=PlotType.PLOT,
    )
    ocp.add_plot(
        "CoM_dot",
        lambda x, u, p: plot_CoM_dot(x, "../models/jumper1contacts.bioMod"),
        phase_number=1,
        plot_type=PlotType.PLOT,
    )

    sol = ocp.solve(show_online_optim=True,
                    solver_options={
                        "hessian_approximation": "exact",
                        "max_iter": 1000
                    })

    #--- Show results --- #
    # param = Data.get_data(ocp, sol["x"], get_states=False, get_controls=False, get_parameters=True)
    # print(
    #     f"The optimized phases times are: {param['time'][0, 0]}s and {param['time'][1, 0]}s."
    # )

    toc = time() - tic
    print(f"Time to solve : {toc}sec")

    result = ShowResult(ocp, sol)
    result.graphs(adapt_graph_size_to_bounds=True)
    result.animate(nb_frames=61)
예제 #7
0
    )
    toc = time() - tic
    print(f"Time to solve with ACADOS: {toc}sec")

    ocp = prepare_ocp(biorbd_model_path="arm26.bioMod",
                      final_time=2,
                      number_shooting_points=51,
                      use_SX=False)
    tic = time()
    sol_ip = ocp.solve(
        solver=Solver.IPOPT,
        show_online_optim=False,
        solver_options={
            "tol": 1e-3,
            "dual_inf_tol": 1e-3,
            "constr_viol_tol": 1e-3,
            "compl_inf_tol": 1e-3,
            "linear_solver": "ma57",
        },
    )
    toc = time() - tic
    print(f"Time to solve with IPOPT: {toc}sec")

    # --- Show results --- #
    result_ac = ShowResult(ocp, sol_ac)
    result_ip = ShowResult(ocp, sol_ip)
    # result_ac.graphs()
    # result_ip.graphs()
    result_ac.animate(title="ferf")
    result_ip.animate()
예제 #8
0
pendulum = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pendulum)

ocp = pendulum.prepare_ocp(
    biorbd_model_path="pendulum.bioMod",
    final_time=2,
    number_shooting_points=10,
    nb_threads=2,
)

X = InitialConditions([0, 0, 0, 0])
U = InitialConditions([-1, 1])

# --- Single shooting --- #
sol_simulate_single_shooting = Simulate.from_controls_and_initial_states(
    ocp, X, U, single_shoot=True)
result_single = ShowResult(ocp, sol_simulate_single_shooting)
result_single.graphs()

# --- Multiple shooting --- #
sol_simulate_multiple_shooting = Simulate.from_controls_and_initial_states(
    ocp, X, U, single_shoot=False)
result_multiple = ShowResult(ocp, sol_simulate_multiple_shooting)
result_multiple.graphs()

# --- Single shooting --- #
result_single.animate()

# --- Multiple shooting --- #
result_multiple.animate()