Skip to content

Commit

Permalink
new PR for pendulum swing up variable duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter230655 committed Sep 19, 2024
1 parent 0b5c8bb commit 8f9925f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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()

0 comments on commit 8f9925f

Please sign in to comment.