-
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 1 commit
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# %% | ||
""" | ||
Parallel Park a Car | ||
=================== | ||
|
@@ -185,10 +186,14 @@ | |
|
||
# %% | ||
# Find the optimal solution. | ||
initial_guess = np.load('parallel_park_solution.npy') | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more.
I will correct. Just slipped. |
||
solution, info = prob.solve(initial_guess) | ||
print(info['status_msg']) | ||
print(info['obj_val']) | ||
|
||
# %% | ||
#Improved initial_guess is stored like this | ||
# ```np.save('parallel_park_solution.npy', solution)``` | ||
# %% | ||
# Plot the optimal state and input trajectories. | ||
prob.plot_trajectories(solution) | ||
|
@@ -223,8 +228,18 @@ | |
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) | ||
|
||
coords1 = [] | ||
time1 = [] | ||
for i in range(coords.shape[0]): | ||
if i % 3 == 0: | ||
coords1.append(coords[i, :, :]) | ||
time1.append(time[i]) | ||
coords1.append(coords[-1, :, :]) | ||
time1.append(time[-1]) | ||
time = np.array(time1) | ||
coords = np.array(coords1) | ||
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. This is an overly complicated way to skip frames (if that is what it does). It isn't so favorable for such things to be in examples for beginners. 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. Just use slicing in 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.
Yes, I wanted to skip frames, and I could not think of a simpler way. 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. I thought one of the examples already has exactly what Timo suggests. 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.
Not sure, I understand what slicing means - my Python skill are limited. Could you explain, please. 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.
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.
Now clear! This I even know, just did not think about it :-( 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. All the PRs I made today have equally clumsy ways of reducing the frames. 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. @Peter230655 in this case it is even easier to use 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.
I will try this first thing tomorrow morning!! :-) |
||
|
||
def frame(i): | ||
|
||
|
@@ -261,12 +276,12 @@ def animate(i): | |
|
||
|
||
ani = animation.FuncAnimation(fig, animate, len(time), | ||
interval=int(interval_value*1000)) | ||
interval=int(interval_value*1000*1)) | ||
|
||
# %% | ||
# A frame from the animation. | ||
|
||
# sphinx_gallery_thumbnail_number = 7 | ||
frame(450) | ||
frame(140) | ||
|
||
plt.show() |
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.
Not sure why this is added as the first line, should be removed.
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 have to add this in VSC so I can run the simulation from the begining.
I will remove before I push