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

reduced frames in animation, better initial guess #244

Open
wants to merge 2 commits 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 added examples-gallery/parallel_park_solution.npy
Binary file not shown.
20 changes: 14 additions & 6 deletions examples-gallery/plot_parallel_park.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@
prob.add_option('nlp_scaling_method', 'gradient-based')

# %%
# Give some rough estimates for the x and y trajectories.
# Give some rough estimates for the x and y trajectories. They were used to
# generate the initial guess, now stored in the file parallel_park_solution.npy.
x_guess = 3.0/duration*2.0*time
x_guess[num_nodes//2:] = 6.0 - 3.0/duration*2.0*time[num_nodes//2:]
y_guess = 2.0/duration*time
Expand All @@ -184,11 +185,17 @@
prob.plot_trajectories(initial_guess)

# %%
# Find the optimal solution.
# Solve the optimisation, using the initial guess stored in the file
# parallel_park_solution.npy.
initial_guess = np.load('parallel_park_solution.npy')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add these to examples, we need to explain to the reader why we are doing so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add these to examples, we need to explain to the reader why we are doing so.

I will correct. Just slipped.

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

# %%
#Improved initial_guess may be saved and stored like this:
# ```np.save('parallel_park_solution.npy', solution)```

# %%
# Plot the optimal state and input trajectories.
prob.plot_trajectories(solution)
Expand Down Expand Up @@ -223,8 +230,7 @@
coords = []
for xi, ui in zip(xs.T, us.T):
coords.append(eval_point_coords(xi, ui, list(par_map.values())))
coords = np.array(coords) # shape(600, 3, 8)

coords = np.array(coords) # shape(501, 3, 5)

def frame(i):

Expand Down Expand Up @@ -252,6 +258,8 @@ def frame(i):

fig, title_text, lines, Pr_path, Pf_path = frame(0)

time = list(time)
time[-3:] = [time[-1]]*3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you doing with these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you doing with these lines?

Without them I did not get the time showing on the animation to end at the correct time. It ended ar 29.88 sec (if I recall correctly) instead of at 30 sec.


def animate(i):
title_text.set_text('Time = {:1.2f} s'.format(time[i]))
Expand All @@ -260,8 +268,8 @@ def animate(i):
Pf_path.set_data(coords[:i, 0, 2], coords[:i, 1, 2])


ani = animation.FuncAnimation(fig, animate, len(time),
interval=int(interval_value*1000))
ani = animation.FuncAnimation(fig, animate, range(0, len(time), 3),
interval=int(interval_value*1000*2))

# %%
# A frame from the animation.
Expand Down
Loading