-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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') | ||
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) | ||
|
@@ -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): | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you doing with these lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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])) | ||
|
@@ -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. | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will correct. Just slipped.