From b72d93ac9cfed1dcf44901332c16b685f1e78fb2 Mon Sep 17 00:00:00 2001 From: Tarun Gaba Date: Mon, 23 Sep 2013 20:40:16 +0530 Subject: [PATCH] WIP --- docs/src/index.rst | 1 + docs/src/tutorials.rst | 13 ++++++ docs/src/tutorials/basic.rst | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 docs/src/tutorials.rst create mode 100644 docs/src/tutorials/basic.rst diff --git a/docs/src/index.rst b/docs/src/index.rst index 843e22e..a781e8b 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -19,6 +19,7 @@ Contents: introduction.rst installation.rst + tutorials.rst api.rst diff --git a/docs/src/tutorials.rst b/docs/src/tutorials.rst new file mode 100644 index 0000000..8fe8d8e --- /dev/null +++ b/docs/src/tutorials.rst @@ -0,0 +1,13 @@ +Tutorials +========= + +There are two types of tutorials in this documentation. +The first one is a basic example for animation. In the basic example, +a simple mass-spring system is animated using SymPy mechanics and PyDyViz. + + +.. toctree:: + :maxdepth: 2 + + tutorials/basic.rst + diff --git a/docs/src/tutorials/basic.rst b/docs/src/tutorials/basic.rst new file mode 100644 index 0000000..dfdb87b --- /dev/null +++ b/docs/src/tutorials/basic.rst @@ -0,0 +1,80 @@ +Basic Tutorial +-------------- + +In this tutorial, we are going to analyze a mass spring damper problem, and animate it using the package. +For this tutorial to work, you have following additional dependency: + + * Scipy_ + +We are going to break this tutorial into three parts, + * Mechanics Part: where we define the system and derive Equations Of Motion. + * Simulation Part: where we numerically solve Equations of Motion(using SciPy). + * Visualization Part: where we actually generate the animations in a browser. + + + +Equation Of Motion Generation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +We will be using SymPy Mechanics module for EoM generation. + +For more details on Mechanics Please refer to SymPy docs and tutorials. + +First we import necessary functionality from SymPy:: + + >>> from sympy.physics.mechanics import * + >>> from sympy import symbols,cos,Eq,sqrt,sin + +Now, we will create some symbols for coordinates, speed, force etc of the mass(bob). + + >>> q = dynamicsymbols('q') # Generalized coordinate + >>> u = dynamicsymbols('u') # Generalized speed + >>> f = dynamicsymbols('f') # Net Force applied to the box + >>> m = symbols('m') # Mass of body + >>> g, k, t, L = symbols('g k t L') # Gravity,spring constant, time and length of unstretched spring + + +Now we create an inertial reference frame, assign an origin, and set origin velocity to zero. + + >>> I = ReferenceFrame('I') # Inertial reference frame + >>> O = Point('O') # Origin point + >>> O.set_vel(I, 0) # Origin's velocity is zero + +Now we define the bob as a Particle. + + >>> P = Point('P') # Center Of Mass of the box + >>> P.set_pos(O, q * I.y) # Set the position of P + >>> P.set_vel(I, u * I.y ) # Set the velocity of P + >>> bob = Particle('bob',P,m) + +We assign forces acting on the Particle. Coordinate axes are defined to be as : + * x-axis: running from left to right, + * y-axis: running from top to bottom, + * z-axis: running from behind the plane to above the plane. + +Following the above notion, Gravity is taken to be in (+I.y) direction, +and force due to spring(F=Kx), in -I.y direction. + + >>> f = m*g* I.y - k*(q)*I.y #Net force on bob. + >>> force = [(P,f)] + +Setting up equation of motion for the body:: + + >>> diff_eq = [q.diff(t) - u] + + + + + +Advanced Tutorial +----------------- + + + + + + + + +.. _Scipy: http://www.scipy.org +