Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new PR for pendulum swing up variable duration #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
16 changes: 12 additions & 4 deletions examples-gallery/plot_pendulum_swing_up_variable_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ def obj_grad(free):
initial_guess = np.zeros(prob.num_free)

# %%
# Find the optimal solution.
# Find the optimal solution. Initial guess is stored in the file
# ```pendulum_swing_up_variable_duration_solution.npy```

initial_guess = np.load('pendulum_swing_up_variable_duration_solution.npy')
solution, info = prob.solve(initial_guess)
print(info['status_msg'])
print(info['obj_val'])

# %%
# Here the better initial conditions are saved and stored
# ```np.save('pendulum_swing_up_variable_duration_solution', solution)```

# %%
# Plot the optimal state and input trajectories.
prob.plot_trajectories(solution)
Expand Down Expand Up @@ -125,9 +132,10 @@ def animate(i):
time_text.set_text(time_template.format(i*interval_value))
return line, time_text


ani = animation.FuncAnimation(fig, animate, range(num_nodes),
interval=int(interval_value*1000),
time = list(time)
time[-5:] = [time[-1]] * 5
ani = animation.FuncAnimation(fig, animate, range(0, int(num_nodes), 5),
interval=int(interval_value*1000*5),
blit=True, init_func=init)

plt.show()
Loading