.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/examples/plot_benchmark.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_examples_plot_benchmark.py: ================================ Benchmark Carvallo-Whipple Model ================================ Meijaard et al. presents a benchmark minimal linear Carvallo-Whipple bicycle model ([Meijaard2007]_, [Carvallo1899]_, [Whipple1899]_) with 27 unique constant parameters and two coordinates: roll angle :math:`\phi` and steer angle :math:`\delta`. .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python import numpy as np from bicycleparameters import Bicycle from bicycleparameters.io import remove_uncertainties from bicycleparameters.parameter_sets import Meijaard2007ParameterSet from bicycleparameters.models import Meijaard2007Model data_dir = "../../data" .. GENERATED FROM PYTHON SOURCE LINES 22-27 Benchmark Parameter Values ========================== First, create a :class:`~bicycleparameters.main.Bicycle` object from the parameter file in the data directory. .. GENERATED FROM PYTHON SOURCE LINES 27-29 .. code-block:: Python bicycle = Bicycle("Benchmark", pathToData=data_dir) .. rst-class:: sphx-glr-script-out .. code-block:: none Looks like you've already got some parameters for Benchmark, use forceRawCalc to recalculate. .. GENERATED FROM PYTHON SOURCE LINES 30-34 Strip the uncertainties from the parameters and add a speed parameter :math:`v`, then create a :class:`~bicycleparameters.parameter_sets.Meijaard2007ParameterSet` set from the parameter values. .. GENERATED FROM PYTHON SOURCE LINES 34-39 .. code-block:: Python par = remove_uncertainties(bicycle.parameters['Benchmark']) par['v'] = 4.6 par_set = Meijaard2007ParameterSet(par, True) par_set .. raw:: html
Meijaard2007
VariableValue
\(I_{Bxx}\)9.200
\(I_{Bxz}\)2.400
\(I_{Byy}\)11.000
\(I_{Bzz}\)2.800
\(I_{Fxx}\)0.141
\(I_{Fyy}\)0.280
\(I_{Hxx}\)0.059
\(I_{Hxz}\)-0.008
\(I_{Hyy}\)0.060
\(I_{Hzz}\)0.007
\(I_{Rxx}\)0.060
\(I_{Ryy}\)0.120
\(c\)0.080
\(g\)9.810
\(\lambda\)0.314
\(m_B\)85.000
\(m_F\)3.000
\(m_H\)4.000
\(m_R\)2.000
\(r_F\)0.350
\(r_R\)0.300
\(v\)4.600
\(w\)1.020
\(x_B\)0.300
\(x_H\)0.900
\(z_B\)-0.900
\(z_H\)-0.700


.. GENERATED FROM PYTHON SOURCE LINES 40-43 The bicycle geometry and representations of the inertia of the four rigid bodies (B: rear frame, F: front wheel, H: front frame, R: rear wheel) can be visualized with the parameter set plot methods. .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: Python ax = par_set.plot_all() .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_001.png :alt: plot benchmark :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-52 Linear Carvallo-Whipple Model ============================= Create a :class:`~bicycleparameters.models.Meijaard2007Model` that represents linear Carvallo-Whipple model presented in [Meijaard2007]_ and populate it with the parameter values in the parameter set. .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python model = Meijaard2007Model(par_set) .. GENERATED FROM PYTHON SOURCE LINES 55-80 This model can be written in this form: .. math:: \mathbf{M}\ddot{\vec{q}} + v\mathbf{C}_1\dot{\vec{q}} + \left[ g \mathbf{K}_0 + v^2 \mathbf{K}_2 \right] \vec{q} = \vec{F} where the essential coordinates are the roll angle :math:`\phi` and steer angle :math:`\delta`, respectively: .. math:: \vec{q} = [\phi \quad \delta]^T and the forcing terms are: .. math:: \vec{F} = [T_\phi \quad T_\delta]^T The model can calculate the mass, damping, and stiffness coefficient matrices, which should match the paper's results when using the matching parameter values: .. GENERATED FROM PYTHON SOURCE LINES 80-83 .. code-block:: Python M, C1, K0, K2 = model.form_reduced_canonical_matrices() M .. rst-class:: sphx-glr-script-out .. code-block:: none array([[80.817, 2.319], [ 2.319, 0.298]]) .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: Python C1 .. rst-class:: sphx-glr-script-out .. code-block:: none array([[ 0. , 33.866], [-0.85 , 1.685]]) .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. code-block:: Python K0 .. rst-class:: sphx-glr-script-out .. code-block:: none array([[-80.95 , -2.6 ], [ -2.6 , -0.803]]) .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: Python K2 .. rst-class:: sphx-glr-script-out .. code-block:: none array([[ 0. , 76.597], [ 0. , 2.654]]) .. GENERATED FROM PYTHON SOURCE LINES 93-98 The root locus can be plotted as a function of any model parameter. This plot is most often used to show how stability is dependent on the speed parameter.The blue lines indicate the weave eigenmode, the green the capsize eigenmode, and the orange the caster eigenmode. Vertical dashed lines indicate speeds that are examined further below. .. GENERATED FROM PYTHON SOURCE LINES 98-106 .. code-block:: Python v = np.linspace(0.0, 10.0, num=401) ax = model.plot_eigenvalue_parts(v=v, colors=['C0', 'C0', 'C1', 'C2'], hide_zeros=True) for vi in [0.0, 2.0, 5.0, 8.0]: ax.axvline(vi, color='k', linestyle='--') ax.set_ylim((-10.0, 10.0)) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_002.png :alt: plot benchmark :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (-10.0, 10.0) .. GENERATED FROM PYTHON SOURCE LINES 107-119 Modes of Motion =============== When populated with realistic parameter values the linear Carvallo-Whipple model exhibits four characteristic eigenmodes that transition into three eigenmodes when two roots bifurcate into an imaginary pair. Low Speed, Unstable Inverted Pendulum ------------------------------------- Before the bifurcation point into the weave mode, there are four real eigenvalues that describe the motion. .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: Python ax = model.plot_eigenvectors(v=0.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_003.png :alt: Eigenvalue: 5.531, Eigenvalue: 3.132, Eigenvalue: -5.531, Eigenvalue: -3.132 :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 122-124 The unstable eigenmodes dominate the motion and this results in the steer angle growing rapidly and the roll angle following suite, but slower. .. GENERATED FROM PYTHON SOURCE LINES 124-127 .. code-block:: Python times = np.linspace(0.0, 1.0) ax = model.plot_mode_simulations(times, v=0.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_004.png :alt: Eigenvalue: 5.531, Eigenvalue: 5.531, Eigenvalue: 3.132, Eigenvalue: 3.132, Eigenvalue: -5.531, Eigenvalue: -5.531, Eigenvalue: -3.132, Eigenvalue: -3.132 :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 128-129 The total motion shows that the bicycle falls over, as expected. .. GENERATED FROM PYTHON SOURCE LINES 129-131 .. code-block:: Python ax = model.plot_simulation(times, [0.01, 0.0, 0.0, 0.0], v=0.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_005.png :alt: plot benchmark :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 132-141 Low Speed, Unstable Weave ------------------------- Moving up in speed past the bifurcation, the bicycle has an unstable oscillatory eigenmode that is called "weave". The steer angle has about twice the magnitude as the roll angle and they both grow together with close to 90 degrees phase. The other two stable real valued eigenmodes are called "capsize" and "caster", with capsize being primarily a roll motion and caster a steer motion. .. GENERATED FROM PYTHON SOURCE LINES 141-142 .. code-block:: Python ax = model.plot_eigenvectors(v=2.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_006.png :alt: Eigenvalue: 2.682+1.681j, Eigenvalue: 2.682-1.681j, Eigenvalue: -3.072+0.000j, Eigenvalue: -8.674+0.000j :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 143-146 .. code-block:: Python times = np.linspace(0.0, 1.0) ax = model.plot_mode_simulations(times, v=2.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_007.png :alt: Eigenvalue: 2.682+1.681j, Eigenvalue: 2.682+1.681j, Eigenvalue: 2.682-1.681j, Eigenvalue: 2.682-1.681j, Eigenvalue: -3.072+0.000j, Eigenvalue: -3.072+0.000j, Eigenvalue: -8.674+0.000j, Eigenvalue: -8.674+0.000j :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 147-155 Stable Eigenmodes ----------------- Increasing speed further shows that the weave eigenmode becomes stable, making all eigenmodes stable, and thus the total motion is stable. The speed regime where this is true is called the "self-stable" speed range given that stability arises with no active control. The weave steer-roll phase is almost aligned and the caster time constant is becoming very fast. .. GENERATED FROM PYTHON SOURCE LINES 155-156 .. code-block:: Python ax = model.plot_eigenvectors(v=5.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_008.png :alt: Eigenvalue: -0.323+0.000j, Eigenvalue: -0.775+4.465j, Eigenvalue: -0.775-4.465j, Eigenvalue: -14.078+0.000j :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 157-160 .. code-block:: Python times = np.linspace(0.0, 5.0, num=501) ax = model.plot_mode_simulations(times, v=5.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_009.png :alt: Eigenvalue: -0.323+0.000j, Eigenvalue: -0.323+0.000j, Eigenvalue: -0.775+4.465j, Eigenvalue: -0.775+4.465j, Eigenvalue: -0.775-4.465j, Eigenvalue: -0.775-4.465j, Eigenvalue: -14.078+0.000j, Eigenvalue: -14.078+0.000j :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 161-167 High Speed, Unstable Capsize ---------------------------- If the speed is increased further, the system becomes unstable due to the capsize mode. The weave steer and roll are mostly aligned in phase but the roll dominated capsize shows that the bicycle slowly falls over. .. GENERATED FROM PYTHON SOURCE LINES 167-169 .. code-block:: Python ax = model.plot_eigenvectors(v=8.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_010.png :alt: Eigenvalue: 0.143+0.000j, Eigenvalue: -2.693+8.460j, Eigenvalue: -2.693-8.460j, Eigenvalue: -20.279+0.000j :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_010.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 170-172 .. code-block:: Python ax = model.plot_mode_simulations(times, v=8.0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_011.png :alt: Eigenvalue: 0.143+0.000j, Eigenvalue: 0.143+0.000j, Eigenvalue: -2.693+8.460j, Eigenvalue: -2.693+8.460j, Eigenvalue: -2.693-8.460j, Eigenvalue: -2.693-8.460j, Eigenvalue: -20.279+0.000j, Eigenvalue: -20.279+0.000j :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_011.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 173-178 Total Motion Simulation ----------------------- The following plot shows the total motion with the same initial conditions used in [Meijaard2007]_ within the stable speed range at 4.6 m/s. .. GENERATED FROM PYTHON SOURCE LINES 178-181 .. code-block:: Python x0 = [0.0, 0.0, 0.5, 0.0] ax = model.plot_simulation(times, x0) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_012.png :alt: plot benchmark :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_012.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 182-183 A constant steer torque puts the model into a turn. .. GENERATED FROM PYTHON SOURCE LINES 183-186 .. code-block:: Python times = np.linspace(0.0, 10.0, num=1001) ax = model.plot_simulation(times, x0, input_func=lambda t, x: [0.0, 1.0]) .. image-sg:: /gallery/examples/images/sphx_glr_plot_benchmark_013.png :alt: plot benchmark :srcset: /gallery/examples/images/sphx_glr_plot_benchmark_013.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.176 seconds) .. _sphx_glr_download_gallery_examples_plot_benchmark.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_benchmark.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_benchmark.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_benchmark.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_