Commit 79e8a5b4 authored by Carlos Mastalli's avatar Carlos Mastalli
Browse files

[example] Display the cartpole in cartpole_swing_up.py

parent e95b9a3d
Pipeline #17445 passed with stage
in 33 minutes and 55 seconds
# Display the solution
import numpy as np
from IPython.display import HTML
from cartpole_utils import animateCartpole
import crocoddyl
......@@ -79,4 +77,5 @@ ddp = crocoddyl.SolverDDP(problem)
ddp.setCallbacks([crocoddyl.CallbackVerbose()])
ddp.solve([], [], 300)
HTML(animateCartpole(ddp.xs).to_html5_video())
# Display animation
animateCartpole(ddp.xs, show=True)
\ No newline at end of file
......@@ -5,7 +5,7 @@ from matplotlib import animation
from matplotlib import pyplot as plt
def animateCartpole(xs, sleep=50):
def animateCartpole(xs, sleep=50, show=False):
print("processing the animation ... ")
cart_size = 1.
pole_length = 5.
......@@ -35,4 +35,6 @@ def animateCartpole(xs, sleep=50):
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=len(xs), interval=sleep, blit=True)
print("... processing done")
if show:
plt.show()
return anim
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment