From 78af74ea12b7258aedb782343ad0923e646818e9 Mon Sep 17 00:00:00 2001 From: "Jason K. Moore" Date: Thu, 11 May 2023 09:27:43 +0200 Subject: [PATCH 1/4] Added learning objectives and clarified relation to equations in motion chapter. --- nonholonomic-eom.rst | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/nonholonomic-eom.rst b/nonholonomic-eom.rst index 9751d0ca..3d4b0405 100644 --- a/nonholonomic-eom.rst +++ b/nonholonomic-eom.rst @@ -2,8 +2,6 @@ Equations of Motion with Nonholonomic Constraints ================================================= -.. warning:: This page as not yet been updated for the 2022-2023 course. - .. note:: You can download this example as a Python script: @@ -42,6 +40,18 @@ Equations of Motion with Nonholonomic Constraints **kwargs) me.ReferenceFrame = ReferenceFrame +Learning Objectives +=================== + +After completing this chapter readers will be able to: + +- formulate the :math:`p` dynamical differential equations for a nonholonomic system +- simulate a nonholonomic multibody system +- calculate trajectories of dependent speeds + +Introduction +============ + In chapters, :ref:`Holonomic Constraints` and :ref:`Nonholonomic Constraints`, I introduced two types of constraints: holonomic (configuration) constraints and nonholonomic (motion) constraints. Holonomic constraints are nonlinear @@ -52,9 +62,6 @@ of motion first, as they are slightly easier to deal with. .. [#] They can be linear in the coordinates, but then there is little reason not to solve for the depedendent coordinates and eliminate them. -Nonholonomic Equations of Motion -================================ - Nonholonomic constraint equations are linear in both the independent and dependent generalized speeds (see Sec. :ref:`Snakeboard`). We have shown that you can explicitly solve for the dependent generalized speeds :math:`\bar{u}_r` @@ -73,7 +80,15 @@ and :math:`u_r` can be solved for as so: .. math:: :label: eq-dep-speeds-solve - \bar{u}_r = -\mathbf{M}_n(\bar{q}, t)^{-1}\bar{g}_n(\bar{u}_s, \bar{q}, t) \\ + \bar{u}_r = -\mathbf{M}_n(\bar{q}, t)^{-1}\bar{g}_n(\bar{u}_s, \bar{q}, t) + +which is the same as Eq. :math:numref:`eq-contraint-linear-form-solve` we +originally developed: + +.. math:: + :label: eq-dep-speeds-repeat + + \bar{u}_r = \mathbf{A}_n \bar{u}_s + \bar{b}_n\\ Using Eq. :math:numref:`eq-dep-speeds-solve` equation we can now write our equations of motion as :math:`n` kinematical differential equations and @@ -93,6 +108,11 @@ and these can be written in explicit form: \dot{\bar{q}} = -\mathbf{M}_k(\bar{q}, t)^{-1} \bar{g}_k(\bar{u}_s, \bar{q}, t) \\ \dot{\bar{u}}_s = -\mathbf{M}_d(\bar{q}, t)^{-1} \bar{g}_d(\bar{u}_s, \bar{q}, t) \\ +This leaves us with :math:`n+p` equations of motion, instead of :math:`2n` +equations seen in a holonomic system. Nonholonomic constraints reduce the +number of degrees of freedom and thus fewer dynamical differential equations +are necessary to fully describe the motion. + Snakeboard Equations of Motion ============================== @@ -104,6 +124,7 @@ inertia of the three bodies are the same. .. figure:: figures/motion-snakeboard.svg :align: center + :width: 80% Configuration diagram of a planar Snakeboard model. @@ -150,7 +171,11 @@ expressions we create. urd_zero = {udi: 0 for udi in urd} usd_zero = {udi: 0 for udi in usd} - qd_zero, ur_zero, us_zero, urd_zero, usd_zero + qd_zero, ur_zero, us_zero + +.. jupyter-execute:: + + urd_zero, usd_zero 2. Establish the kinematics --------------------------- @@ -477,19 +502,19 @@ coordinates. We now have :math:`\mathbf{M}_k, \bar{g}_k, \mathbf{M}_d` and :math:`\bar{g}_d` and can proceed to numerical evaluation. +.. todo:: Also show how Fr and Frs can be formed using An. + Simulate the Snakeboard ======================= We now move to numerical evaluation for the simulation. First, create a function that evaluates the matrices of the equations of motion. -.. todo:: lambdify(cse=True) fail for this. Open an issue on SymPy. - .. todo:: sm.Matrix.count_ops() doesn't seem like it exists. Open an issue. .. jupyter-execute:: - eval_kd = sm.lambdify((q, us, p), (Mk, gk, Md, gd)) + eval_kd = sm.lambdify((q, us, p), (Mk, gk, Md, gd), cse=True) Now create a function that evaluates the right hand side of the explicit ordinary differential equations for use with ``solve_ivp()``. @@ -563,7 +588,7 @@ later use in the animation of the motion. .. jupyter-execute:: - t0, tf = 0.0, 10.0 + t0, tf = 0.0, 1.0 .. jupyter-execute:: From b8fdb3c69571fd1c32b093f85bbaf98900762a75 Mon Sep 17 00:00:00 2001 From: "Jason K. Moore" Date: Thu, 11 May 2023 09:27:58 +0200 Subject: [PATCH 2/4] Added notation for all the linear equations for constraints. --- notation.rst | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/notation.rst b/notation.rst index c4402d0b..bdd2b3be 100644 --- a/notation.rst +++ b/notation.rst @@ -90,6 +90,8 @@ Angular and Translational Kinematics Constraints =========== +.. todo:: Add Y_k, kin diff eqs. + :math:`N,M,n,m,p` :math:`N` coordinates, :math:`M` holonomic constraints, :math:`n` generalized coordinates and generalized speeds, :math:`m` nonholonomic @@ -101,6 +103,21 @@ Constraints :math:`\bar{f}_n(u_1, \ldots, u_n, q_1, \ldots, q_n, t) = 0 \textrm{ where } \bar{f}_n \in \mathbb{R}^m`, ``fn`` Vector function of :math:`m` nonholonomic constraint equations among the :math:`n` generalized speeds and generalized coordinates. +:math:`\mathbf{A}_r` + Linear coefficient matrix for :math:`\bar{u}_r` in the nonholonomic + constraint equations. +:math:`\mathbf{A}_s` + Linear coefficient matrix for :math:`\bar{u}_s` in the nonholonomic + constraint equations. +:math:`\bar{b}_{rs}` + Terms not linear in :math:`\bar{u}_s` or :math:`\bar{u}_r` in the + nonholonomic constraint equations. +:math:`\mathbf{A}_n` + Linear coefficient matrix for :math:`\bar{u}_s` in the equation for + :math:`\bar{u}_r=\mathbf{A}_n\bar{u}_s + \bar{b}_n`. +:math:`\bar{b}_n` + Terms not linear in :math:`\bar{u}_s` in the equation for + :math:`\bar{u}_r=\mathbf{A}_n\bar{u}_s + \bar{b}_n`. Mass Distribution ================= @@ -194,6 +211,26 @@ Unconstrained Equations of Motion :math:`\bar{g}_m` Terms not linear in :math:`\dot{\bar{x}}` in the equations of motion. +Equations of Motion with Nonholonomic Constraints +================================================= + +:math:`\bar{f}_n(\bar{u}_s, \bar{u}_r, \bar{q}, t) = 0` + Nonholonomic constraint equations. +:math:`\mathbf{M}_n=\mathbf{A}_r` + Linear coefficient matrix for :math:`\bar{u}_r` in the nonholonomic + constraint equations. +:math:`\bar{g}_n=\mathbf{A}_s\bar{u}_s+\bar{b}_{rs}` + Terms not linear in :math:`\bar{u}_r` in the nonholonomic constraint + equations. +:math:`\dot{\bar{f}}_n(\dot{\bar{u}}_s, \dot{\bar{u}}_r, \bar{u}_s, \bar{u}_r, \bar{q}, t) = 0` + Time derivative of the nonholonomic constraint equations. +:math:`\mathbf{M}_{nd}` + Linear coefficient matrix for :math:`\dot{\bar{u}}_r` in the time + differentiated nonholonomic constraint equations. +:math:`\bar{g}_{nd}` + Terms not linear in :math:`\dot{\bar{u}}_r` in the time differentiated + nonholonomic constraint equations. + .. |notation-scalar| image:: figures/notation-scalar.svg :height: 10px From b6aaf4b32a65c2557e2015658ded2ccb42c926f9 Mon Sep 17 00:00:00 2001 From: "Jason K. Moore" Date: Thu, 11 May 2023 09:30:59 +0200 Subject: [PATCH 3/4] Back to a longer simulation. --- nonholonomic-eom.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nonholonomic-eom.rst b/nonholonomic-eom.rst index 3d4b0405..23100837 100644 --- a/nonholonomic-eom.rst +++ b/nonholonomic-eom.rst @@ -588,7 +588,7 @@ later use in the animation of the motion. .. jupyter-execute:: - t0, tf = 0.0, 1.0 + t0, tf = 0.0, 8.0 .. jupyter-execute:: From 9384e197d8bf9e8b9b70370e118249626f69cbc8 Mon Sep 17 00:00:00 2001 From: "Jason K. Moore" Date: Thu, 11 May 2023 13:38:23 +0200 Subject: [PATCH 4/4] Add cse true to all lambdify calls. --- nonholonomic-eom.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nonholonomic-eom.rst b/nonholonomic-eom.rst index 23100837..6674e5c9 100644 --- a/nonholonomic-eom.rst +++ b/nonholonomic-eom.rst @@ -663,7 +663,7 @@ the points we want to plot given the generalized coordinates. for point in [Co, Cr, Co, Ao, Bo, Bl, Br]: coordinates = coordinates.row_join(point.pos_from(O).to_matrix(N)) - eval_point_coords = sm.lambdify((q, p), coordinates) + eval_point_coords = sm.lambdify((q, p), coordinates, cse=True) eval_point_coords(q0, p_vals) Now create a plot of the initial configuration: @@ -724,7 +724,7 @@ the constraint equations. Here I loop through time to calculate .. jupyter-execute:: x = sm.Matrix([q1, q2, q3, q4, q5, u3, u4, u5]) - eval_ur = sm.lambdify((x, p), ur_sol) + eval_ur = sm.lambdify((x, p), ur_sol, cse=True) ur_vals = [] for xi in xs: