Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorials #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Contents:

introduction.rst
installation.rst
tutorials.rst
api.rst


Expand Down
13 changes: 13 additions & 0 deletions docs/src/tutorials.rst
Original file line number Diff line number Diff line change
@@ -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

80 changes: 80 additions & 0 deletions docs/src/tutorials/basic.rst
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8 spaces after commas


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

65 changes: 65 additions & 0 deletions pydy_viz/static/js/SpecRunner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>

<link rel="shortcut icon" type="image/png" href="jasmine/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="jasmine/jasmine.css">
<script type="text/javascript" src="jasmine/jasmine.js"></script>
<script type="text/javascript" src="jasmine/jasmine-html.js"></script>

<!-- blanket.js for test coverage -->

<script type="text/javascript" src="lib/blanket.min.js"></script>
<script type="text/javascript" data-cover-only="canvas/" src="lib/jasmine-blanket.js"></script>

<!-- include source files here... -->
<script type="text/javascript" src="specs/specHelper.js"></script>
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery-ui.js"></script>
<script type="text/javascript" src="lib/three.min.js"></script>
<script type="text/javascript" src="lib/TrackballControls.js"></script>

<script type="text/javascript" src="canvas/initialize.js" data-cover></script>
<script type="text/javascript" src="canvas/addObjects.js" data-cover></script>
<script type="text/javascript" src="canvas/animate.js" data-cover></script>

<!-- include spec files here... -->
<script type="text/javascript" src="specs/canvasSpecs.js"></script>


<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;

var htmlReporter = new jasmine.HtmlReporter();

jasmineEnv.addReporter(htmlReporter);

jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};

var currentWindowOnload = window.onload;

window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};

function execJasmine() {
jasmineEnv.execute();
}

})();
</script>

</head>

<body>
</body>
</html>
20 changes: 20 additions & 0 deletions pydy_viz/static/js/jasmine/MIT.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2008-2011 Pivotal Labs

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading