.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_scalar_example.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_scalar_example.py: Retime an one dimensional path =============================== .. GENERATED FROM PYTHON SOURCE LINES 6-7 Import necessary libraries. .. GENERATED FROM PYTHON SOURCE LINES 7-15 .. code-block:: default :lineno-start: 7 import toppra as ta import toppra.constraint as constraint import toppra.algorithm as algo import numpy as np import matplotlib.pyplot as plt ta.setup_logging("INFO") .. GENERATED FROM PYTHON SOURCE LINES 16-22 We now generate a simply path. When constructing a path, you must "align" the waypoint properly yourself. For instance, if the waypoints are [0, 1, 10] like in the above example, the path position should be aligned like [0, 0.1, 1.0]. If this is not done, the CubicSpline Interpolator might result undesirable oscillating paths! .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: default :lineno-start: 23 waypts = [[0], [1], [10]] path = ta.SplineInterpolator([0, 0.1, 1.0], waypts) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Setup the velocity and acceleration .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: default :lineno-start: 29 vlim = np.array([[-3, 3]]) alim = np.array([[-4, 4]]) pc_vel = constraint.JointVelocityConstraint(vlim) pc_acc = constraint.JointAccelerationConstraint( alim, discretization_scheme=constraint.DiscretizationType.Interpolation) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Setup the problem instance and solve it. .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: default :lineno-start: 38 instance = algo.TOPPRA([pc_vel, pc_acc], path, solver_wrapper='seidel') jnt_traj = instance.compute_trajectory(0, 0) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO [algorithm.py : 104] No gridpoint specified. Automatically choose a gridpoint with 129 points INFO [algorithm.py : 191] Successfully parametrize path. Duration: 4.084, previously 1.000) INFO [algorithm.py : 193] Finish parametrization in 0.006 secs .. GENERATED FROM PYTHON SOURCE LINES 42-43 We can now visualize the result .. GENERATED FROM PYTHON SOURCE LINES 43-54 .. code-block:: default :lineno-start: 43 duration = jnt_traj.duration print("Found optimal trajectory with duration {:f} sec".format(duration)) ts = np.linspace(0, duration, 100) fig, axs = plt.subplots(3, 1, sharex=True) qs = jnt_traj.eval(ts) qds = jnt_traj.evald(ts) qdds = jnt_traj.evaldd(ts) axs[0].plot(ts, qs) axs[1].plot(ts, qds) axs[2].plot(ts, qdds) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_scalar_example_001.png :alt: plot scalar example :srcset: /auto_examples/images/sphx_glr_plot_scalar_example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Found optimal trajectory with duration 4.083554 sec .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.634 seconds) .. _sphx_glr_download_auto_examples_plot_scalar_example.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_scalar_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_scalar_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_