Skip to content

Commit f9b2543

Browse files
committed
Add more plotting to the planar pcs simulation example
1 parent 05904bd commit f9b2543

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

examples/simulate_planar_pcs.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
strain_selector = jnp.array([True, False, False])
4444

4545
# define initial configuration
46-
q0 = jnp.array([10 * jnp.pi])
46+
q0 = jnp.array([5 * jnp.pi])
4747
# number of generalized coordinates
4848
n_q = q0.shape[0]
4949

@@ -142,6 +142,27 @@ def draw_robot(
142142
# the evolution of the generalized velocities
143143
q_d_ts = sol.ys[:, n_q:]
144144

145+
# evaluate the forward kinematics along the trajectory
146+
chi_ee_ts = vmap(forward_kinematics_fn, in_axes=(None, 0, None))(params, q_ts, jnp.array([jnp.sum(params["l"])]))
147+
# plot the end-effector position along the trajectory
148+
plt.figure()
149+
plt.plot(chi_ee_ts[0, :], chi_ee_ts[1, :])
150+
plt.axis("equal")
151+
plt.grid(True)
152+
plt.xlabel("x [m]")
153+
plt.ylabel("y [m]")
154+
plt.show()
155+
# plot end-effector position vs time
156+
plt.figure()
157+
plt.plot(video_ts, chi_ee_ts[:, 0], label="x")
158+
plt.plot(video_ts, chi_ee_ts[:, 1], label="y")
159+
plt.xlabel("Time [s]")
160+
plt.ylabel("Position [m]")
161+
plt.legend()
162+
plt.grid(True)
163+
plt.box(True)
164+
plt.show()
165+
145166
# plot the energy along the trajectory
146167
kinetic_energy_fn_vmapped = vmap(partial(auxiliary_fns["kinetic_energy_fn"], params))
147168
potential_energy_fn_vmapped = vmap(partial(auxiliary_fns["potential_energy_fn"], params))

0 commit comments

Comments
 (0)