Giter Club home page Giter Club logo

pydy-tutorial-human-standing's Introduction

Introduction

This is the material for a tutorial on analyzing multibody dynamics with scientific Python tools. It was first given as "Simulation and Control of Biomechanical Systems with Python" at the Midwest American Society of Biomechanics Regional meeting on March 4th, 2014 in Akron, Ohio. Modified versions have subsequently been given at PYCON2014, SCIPY2014, SCIPY2015, and SCIPY 2016.

The tutorial covers these main topics:

  • Symbolic derivation of equations of motion for multibody systems.
  • Numerical simulation of the resulting system.
  • 3D visualization of the motion of the system.
  • Optimal feedback control for stabilization.

The attendees will be exposed to various functionality of these Python tools:

The tutorial can be run locally or through the Binder service:

image

Videos

License

All materials herein are licensed under Create Commons Attribution 4.0.

Versions

A new version of the tutorial is typically created each time the tutorial is given to incorporate feedback from the attendees and for software updates. These versions can be downloaded from:

https://github.com/pydy/pydy-tutorial-human-standing/releases

Example Problem

The tutorial will go through the PyDy workflow in small steps. At the end the students should have a working 3-link 2D inverted pendulum model of a human that can be used for balancing studies. The free body diagram of the model is shown below:

image

Installation

Python Packages

To run these notebooks the SciPy Stack is required. To obtain the needed packages, we are recommending users install the Anaconda Scientific Python Distribution which contains most of the necessary software and eases cross platform installation. You should install Anaconda to your home directory. The installation directory can simply be deleted when the tutorial is over if you no longer want the files.

First, download and install Anaconda for your operating system. After Anaconda is installed, update various packages to the latest versions by issuing this command in a terminal:

$ conda update numpy scipy sympy matplotlib notebook ipywidgets

Now install the latest PyDy with:

$ conda install -c conda-forge pydy

MathJax

This is only required if you want to run the tutorial without internet access.

These notebooks make use of the MathJax javascript library to render and display mathematics. By default IPython loads MathJax from the internet (i.e. from a CDN), however, because of potentially questionable internet access at the conference we recommend you install MathJax locally. To do so, type the following in a terminal:

$ conda install mathjax

Web Browser

If you want to see the 3D visualizations you must use a WebGL compliant browser. Visit http://get.webgl.org/ to see if your current browser supports WebGL. If not, you will need to upgrade or install another browser. Visit http://caniuse.com/webgl to choose a suitable browser. We've only confirmed the following:

Linux

Latest versions of Firefox and Chrome work.

Mac OSX

Latest version Firefox works.

Windows

Latest version of Chrome works and IE 11 works.

We know that some OS browser combinations do not work. See pydy/pydy#36 for more details.

Download the tutorial

Either download the latest zipped tutorial materials from:

https://github.com/pydy/pydy-tutorial-human-standing/archive/master.zip

Or download the specific release for your conference from:

https://github.com/pydy/pydy-tutorial-human-standing/releases

and then extract the zip file.

Use

From the terminal, navigate to the extracted tutorial directory, for example:

$ cd /home/username/pydy-tutorial-human-standing

Check the environment

To make sure your software environment is correctly setup, run the check_env.py script in a terminal with:

$ python check_env.py

If no errors are returned, then you've correctly installed the software and can run the tutorial. If errors appear, then install or upgrade the software as needed.

Open a terminal window in the notebooks directory and type:

$ cd notebooks
$ ipython notebook

Your web browser should open and you see a list of all the notebooks and can click to open them and execute.

Notebooks

These are the notebooks for the tutorial.

pydy-tutorial-human-standing's People

Contributors

campanawanna avatar chrisdembia avatar gilbertgede avatar huaweiwang avatar jbm950 avatar jcrist avatar moorepants avatar remcmurry avatar tarzzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydy-tutorial-human-standing's Issues

Quick overview of rigid body dynamics notebook

15 min

  • Vectors, Reference Frames
  • Rotations, direction cosine matrices
  • mass, mass center, Inertia
  • Position, Velocity, Acceleration
  • Forces, Moments
  • Equations of Motion
  • Ordinary differential equations
  • Add in some sympy mechanics commands.

Adjust the tutorial based on the previous feedback

Some things:

  1. We likely don't need to go over the intro to Python notebook at SciPy. I think only one or two people really needed that.
  2. We need to make sure to break up the talking with exercises more. Maybe every 10-15 minutes there should be a small exercise, even if it is just a multiple choice question.

Update content on PyDy.org

We need a little polishing on the website. Would be nice to have a general cleanup. We will share the url to all potential users.

IPython notebook requires CDN connection to Mathjax

I just remembered that internet is required for rendering latex in the notebook. This could be an issue if we have internet connectivity issues.

We could recommend installing mathjax and pointing ipython to it locally, but that is a pain.

The virutalbox install option can have local mathjax easy enough.

This shouldn't be an issue on the Akron machines either, I don't expect internet connectivity issues at the university.

n07_simulation.ipynb

I am getting this error on n07_simulation.ipynb, n08_simulation.ipynb and n09_simulation.ipynb:

right_hand_side(x0, 0.0, args)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-25-a7cae5bebf3b> in <module>()
----> 1 right_hand_side(x0, 0.0, args)

/gpfs/home/kirk/anaconda/envs/robotics/lib/python2.7/site-packages/pydy-0.2.1-py2.7.egg/pydy/codegen/code.pyc in evaluate_ode(x, t, args)
    471         # computation time.
    472 
--> 473         segmented = [np.array([args['constants'][c] for c in constants]),
    474                      x[:len(coordinates)],
    475                      x[len(coordinates):]]

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
conda list
# packages in environment at /gpfs/home/kirk/anaconda/envs/robotics:
#
basemap                   1.0.7                np19py27_0  
cairo                     1.12.2                        2  
cython                    0.21                     py27_0  
dateutil                  2.1                      py27_2  
freetype                  2.4.10                        0  
geos                      3.3.3                         0  
ipython                   2.2.0                    py27_0  
ipython-notebook          2.2.0                    py27_0  
jinja2                    2.7.3                    py27_1  
libpng                    1.5.13                        1  
libsodium                 0.4.5                         0  
markupsafe                0.23                     py27_0  
matplotlib                1.4.0                np19py27_0  
nose                      1.3.4                    py27_0  
numpy                     1.9.0                    py27_0  
openssl                   1.0.1h                        1  
pandas                    0.14.1               np19py27_0  
pixman                    0.26.2                        0  
py2cairo                  1.10.0                   py27_1  
pyparsing                 2.0.1                    py27_0  
pyqt                      4.10.4                   py27_0  
python                    2.7.8                         1  
pytz                      2014.7                   py27_0  
pyzmq                     14.3.1                   py27_0  
qt                        4.8.5                         0  
readline                  6.2                           2  
requests                  2.4.3                    py27_0  
scipy                     0.14.0               np19py27_0  
setuptools                5.8                      py27_0  
sip                       4.15.5                   py27_0  
six                       1.8.0                    py27_0  
sqlite                    3.8.4.1                       0  
ssl_match_hostname        3.4.0.2                  py27_0  
sympy                     0.7.5                    py27_0  
system                    5.8                           1  
theano                    0.6.0                np19py27_0  
tk                        8.5.15                        0  
tornado                   4.0.2                    py27_0  
zeromq                    4.0.4                         0  
zlib                      1.2.7                         0  

Simulation Notebook

use pydy-code-gen to generate numeric right hand side, odeint, + matplotlib plot of state trajectories

specify realistic numerical parameters and the initial conditions.

  • Create working notebook
  • Polish

Problem definition notebook

5 min

Should give a complete description of the inverted pendulum, all variables, etc.

  • Really nice figure of problem.
  • Create notebook.
  • Polish.

Make the first PyDy release.

Make a PyDy package that includes sympy.physics.mechanics, pydy-viz, and pydy-code-gen.

Release to PyPi and ensure it installs in Anaconda based environments (at least, can check more too) on all three main OS's.

See https://github.com/PythonDynamics/PyDy, ideally this will pip install everything that is needed. We will need to make 0.1.0 releases of pydy-viz and pydy-code-gen too.

Sign up for gitter

Aaron said he'll be on gitter during our tutorials to give help if needed.

Decide on a problem idea

I'm not sure if this is the best place to discuss the project idea, but I wanted to share ideas somewhere.

I like the 2d 2dof arm idea, especially considering that @moorepants will be giving that biomechanics tutorial. It's extendable, and maybe for the tutorial, it'd be good to have it all set up so people can continue adding on to a base model. Also, @moorepants has a N-link inverted pendulum balancing notebook already. So they could start with the cursive, then naturally add more links and do that balancing, or then in the biomechanics session, you could add muscles maybe. You could add helical springs and dampers to the joints and then model a long chain (a kid on a swing). I guess there's only a little time, so maybe people would only have time for the cursive.

Anyway, the audience sounds like they might have broad interests, and so the 2d arm makes sense, because it allows so many different extensions.

Equations of Motion Notebook

10 min

Use Kanesmethod, but maybe can should Lagranges too. Talk about relationship to dp/dt = F and dH/dt = T.

  • Create working notebook
  • Polish

Feedback from practice tutorial

  • The repetitive exercises get old quick (Jason's dumb idea...)
  • It would be nice to have more exploratory exercises.
  • Add in passive joint stiffnesses and damping so that the model doesn't flop around.
  • Maybe make some more cylinders so that the viz looks more human.
  • Only do the two link pendulum instead of three.
  • If time at end, let everyone try to create the one link pendulum on their own.
  • Give more time for Python intro at MASB.
  • No need to split kinematics notebook between Obinna and Jason, Obinna will do the whole thing next time.
  • Kinematics notebook took 40 minutes instead of 25.
  • We finished in 3 hours but by skipping all the repetive exercises.
  • Writing the controller function at the end was a good exercise that wasn't repetitive.
  • Add more time for the Python intro for MASB (an maybe less time for PyCon).
  • May need a simpler problem for PyCon if the audience is varied.
  • Feel free to jump in further and faster for MASB instead of going over the basics in dynamics.
  • Make initial values in the simulation realistic values (make knee bend correct way, etc).
  • Explain about objects early on so people know that captial letter functions create objects that have methods and attributes.
  • We should ask at the beginning what people know: dynamics, programming, etc to get a feel about what we can skip and what we can't.

Possible better exercises:

  • Play around with simulation parameters (constants, initial conditions) to get different simulations.
  • Explore different controllers: reduced K matrix, play with Q and R weightings.
  • Create a nose for the person in the visualization.

Rename repository

@pydy/pydy-developers I'd like to rename this repo to something like pydy-standing-tutorial and then continue to use branches and tags for the various versions that we give at different places with the HEAD of master being the most generic version.

Any suggestions on names for the repo? Is this fine?

Github will redirect (maybe indefinitely) so it shouldn't break links.

Kinetics Notebook

15 mins

All forces: joint torques and gravity

  • Create working notebook
  • Polish

Create Python Intro Notebooks

These will be the first notebooks. Should be short and sweet, showing just enough Python, NumPy, SciPy, SymPy, and IPython needed to do our examples. These should not include anything from sympy.physics.mechanics as that intro will come later.

  • {10 min} Intro to Python and IPython notebook (only shown at ASB)
  • {10 min} Intro to basic NumPy + SciPy odeint + basic matplotlib plotting
  • {10 min} Intro to SymPy
  • Polish

Installation instructions

We need to write up the installation instructions. There are of course many ways to do this. These are the two methods that I'd like to have in place, because I think it will be the easiest for folks new to Python:

  • Anaconda based install (default) [this can be from the web or form a USB stick we have at PyCon)
  • Note in installation instructions that you must use python 2.7

Optional

  • Install from OS package manager and then update SymPy and install PyDy with pip. This will give us "old" versions of numpy/scipy though. Can do a PPA install. There are also the new pip whl files that may install numpy and scipy from binary format.
  • Is it possible to install our own packages to sagemath cloud or wakari.io? If so, these would probably work in all cases except for PyDyViz. This would require solid interet connection, but could be a backup.
  • Have USB's with virutal box instances with all software installed. User must have virutal box installed.

Update for PyDy 0.3.0

Main changes:

  • Visualizations now embed into the notebook.
  • Make sure check_env.py works for the new software.
  • Update calls to Scene so that they only use the display_ipython method.

Intro to PyDy notebook

This will include:

  • sympy.physics.mechanics (reference frames, vectors)
  • code gen + odeint
  • pydy viz

This can possible be combined with #13 and we can explain dynamics with some pydy commands.

Control Notebook

use the kane's method linearize command or even do it manually with diff(). Then use scipy.linalg.continuous_are to get the optimal gain matrix (full state feedback). We can give them starting values for R and Q and then they can adjust.

Simulate with the feedback function and then visualize.

  • Create working notebook

Create USB sticks for PYCON

We need backups ready in case downloads don't work.

The USB stick(s) should contain:

  • 32 and 64 bit Anaconda installer for Windows, Mac, and Linux.
  • SymPy 0.7.5 source code.
  • pydy-code-gen 0.1.0 source code.
  • pydy-viz 0.1.0 source code.
  • Mathjax

We also need installation instructions for the USB stick as they will have to use either: python setup.py install or pip install -e /path/to/package.

There will be USB sticks available at PyCon. We need to get them either the nigh of April 8th or early the first thing on the 9th.

Kinematics Notebook

20 mins

This should do all the symbolic kinematics needed for the EoM generation.

  • Create working notebook.
  • Polish

Get PyDy.org back online!

(either fix Luke's server or create a new site with github pages + sphinx, for example, and move content over).

  • Fix Luke's server issues.
  • Upload spam free content.

Visualization Notebook

Setup shapes and viz frames.

We should stick to the basic mapping of rigidbody to vizframe and single shape. keep it simple.

  • Create working notebook
  • Fix colors to match the diagram.
  • Polish
  • Hide exercise solutions.

Update the viewing branch

@tarzzz created this PR #56 that needs to be updated so that we can allow people to view the inputs and outputs of the notebooks. I'm curious to know if the visualization can be embedded so that they display on nbviewer (that would be awesome!). We still need to keep the master branch with all the outputs hidden.

Ask Aaron to make a new SymPy release

Get Aaron to make a new SymPy release with updates from us by about February 20th or so. We've got several patches in master, especially for notebook printing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.