.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_straight_line.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_straight_line.py: Retime a straight path =============================== .. GENERATED FROM PYTHON SOURCE LINES 5-14 .. code-block:: default :lineno-start: 5 import toppra as ta import toppra.constraint as constraint import toppra.algorithm as algo import numpy as np import matplotlib.pyplot as plt import time time.sleep(0.1) .. GENERATED FROM PYTHON SOURCE LINES 15-25 .. code-block:: default :lineno-start: 15 way_pts, vel_limits, accel_limits = np.array([[0, 0, 1], [0.2, 0.3, 0]]), np.array([0.1, 0.2, 0.3]), np.r_[1.0,2,3] path_scalars = np.linspace(0, 1, len(way_pts)) path = ta.SplineInterpolator(path_scalars, way_pts) ss = np.linspace(0, 1, 100) qs = path(np.linspace(0, 1, 100)) for i in range(way_pts.shape[1]): plt.plot(ss, qs[:, i]) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_straight_line_001.png :alt: plot straight line :srcset: /auto_examples/images/sphx_glr_plot_straight_line_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 26-27 Create velocity bounds, then velocity constraint object .. GENERATED FROM PYTHON SOURCE LINES 27-40 .. code-block:: default :lineno-start: 27 vlim = np.vstack((-vel_limits, vel_limits)).T # Create acceleration bounds, then acceleration constraint object alim = np.vstack((-accel_limits, accel_limits)).T pc_vel = constraint.JointVelocityConstraint(vlim) pc_acc = constraint.JointAccelerationConstraint( alim, discretization_scheme=constraint.DiscretizationType.Interpolation) # Setup a parametrization instance. The keyword arguments are # optional. instance = algo.TOPPRA([pc_vel, pc_acc], path, solver_wrapper='seidel') jnt_traj = instance.compute_trajectory(0, 0) .. GENERATED FROM PYTHON SOURCE LINES 41-55 .. code-block:: default :lineno-start: 41 ts_sample = np.linspace(0, jnt_traj.get_duration(), 100) qs_sample = jnt_traj.eval(ts_sample) # sampled joint positions qds_sample = jnt_traj.evald(ts_sample) # sampled joint velocities qdds_sample = jnt_traj.evaldd(ts_sample) # sampled joint accelerations for i in range(jnt_traj.dof): # plot the i-th joint trajectory plt.plot(ts_sample, qds_sample[:, i], c="C{:d}".format(i)) # plot the i-th joint waypoints # plt.plot(data['t_waypts'], way_pts[:, i], 'x', c="C{:d}".format(i)) plt.xlabel("Time (s)") plt.ylabel("Joint velocity (rad/s^2)") plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_straight_line_002.png :alt: plot straight line :srcset: /auto_examples/images/sphx_glr_plot_straight_line_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/circleci/repo/toppra/utils.py:23: DeprecationWarning: Call to deprecated function get_duration in module toppra.interpolator. warnings.warn( .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.399 seconds) .. _sphx_glr_download_auto_examples_plot_straight_line.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_straight_line.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_straight_line.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_