Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Python
Albert Ai
August 27, 2015
Contents
1 Introduction
1.1 Modeling a Human Jump . . .
1.2 Symbolic Python for Multibody
and Symbols . . . . . . . . . . .
1.3 Kinematics . . . . . . . . . . .
1.4 Building the body . . . . . . . .
1.5 Kanes Method . . . . . . . . .
1.6 Equation of Motion . . . . . . .
1.7 Impulse - Momentum Method .
. . . . . .
Systems
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . . . . . .
Reference Frames
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
3
3
.
.
.
.
.
.
3
4
4
5
5
7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
11
11
12
13
13
4 References
15
5 Acknowledgement
16
Introduction
There are two variations of the human vertical jump the countermovement
jump, which involves a springing from a standing position to add potential
energy, and the squat jump, which is a simple jump from a squatting position.
This program was written in symbolic python to simulate the squat jump
variation of the human jump.
1.1
A human vertical jump is divided into two phases. In the first phase, the
subject rotates its body into a standing position while retaining a certain
amount of upwards momentum, and in the second, uses the built up momentum to launch itself into the air. The second phase is simple and can be
modeled as upwards projectile motion with any method of linear approximation such as Eulers Method. However, the first phase is a lot more difficult
to the fact it has multiple simultaneous moving components involved.
In the first phase, there are three degrees of freedom to worry about a
rotation at the ankle, knee, and hip. For simplicitys sake, I have modeled the
system as three rotating rigid bodies and a static ankle as a fixed reference
frame, with three joints modeled as ideal torques between the adjacent body
parts. For each joint, the required torque will be determined according to
the starting position of the human body and the mass of the segments at the
starting points.
1.2
The advantage of using a symbolic language such as SymPy for this project is
that it can break a complicated multibody rotating system down to a group
of reference frames with properties assigned to them. With parameters set,
these reference frames can then be modeled using a wide number of existing
simulation modules built into SymPy. There are four reference frames in
the model the torso reference frame, upper leg reference frame, lower leg
reference frame, and a fixed inertial reference frame I chose to represent
the ankle.
1.3
Kinematics
cos(1 ) sin(1 ) 0
Lower leg.dcm = sin(1 ) cos(1 ) 0
0
0
1
I can then rotate the upper leg relative to the lower leg through the knee
flexion angle, 2 . Adding the two angles flips the sign, causing it to rotate
clockwise.
cos(1 + 2 ) sin(1 + 2 ) 0
Upper leg.dcm = sin(1 + 2 ) cos(1 + 2 ) 0
0
0
1
Likewise, the rotation matrix of the torso can be defined with a similar
rotation matrix about the Z direction.
cos(1 + 2 + 3 ) sin(1 + 2 + 3 ) 0
Torso.dcm = sin(1 + 2 + 3 ) cos(1 + 2 + 3 ) 0
0
0
1
1.4
With a method to set the orientation of the 3 limbs created, I need to define
the positions of the various joints and center of masses in their reference
frames. I will use the ankle as a fixed point for the system, such that all
other points in the system will be defined with respect to the ankle. The
knee joint K is then defined with respect to the ankle using a vector that
is equal to the length from the ankle to the knee, L1 in the direction of
4
the lower leg unit vector, iy. To do this, I needed to define a new constant length for the lower leg and to define the point of the knee K and the
other pivot points. This can be easily done with the Point.setpos function,
which returns the reference point along with the vector and can also be used
to express the returned vector with respect to another reference frame. Thus:
Vector of position of Knee in lower leg reference frame = Ll.iy
Vector of lower leg in Sole reference frame = Ll sin(1 )ix + Ll cos(1 )iy
In a similar fashion the hip is defined with respect to the knee.
Vector of position of Hip in Upper leg reference frame = Lu uy Position of
Hip in Sole reference frame = (Llsin(1 ) Lusin(1 + 2 ))ix + (Llcos(1 ) +
Lucos(1 + 2 ))iy
1.5
Kanes Method
n = n
=0:
n n
[1 1 , 2 2 , 3 3 ]
1.6
Equation of Motion
Now I can use the KanesMethod module, a built in function in SymPy for
an automated computation of the first order differential equations. At a
bare minimum for unconstrained systems, KanesMethod in SymPy needs
the generalized coordinates, generalized speeds, the loads, the bodies, and a
Newtonian reference frame.
First, I made a list of the generalized coordinates, i.e. the three joint angles:
coordinates = [1 , 2 , 3 ]
speeds = [1 , 2 , 3 ]
Now I can use KanesMethod to build the object with the inertial reference frame, coordinates, speeds, and kinematical differential equations:
[1 1, 2 2, 3 3]
kane = KanesMethod(inertial frame, coordinates, speeds, kinematical differential equations)
The equations of motion can now be computed using the kanes equations
function, which takes the list of loads and bodies and returns the equations
of motion (i.e. first order ordinary differential equations) in Kanes form:
Fr + Fr = 0
Which is essentially equivalent to the classic Newton Euler form:
F = ma
T = I
With a reliable way of calculating the forces and torques, I can choose
one of several methods to calculate the trajectory of the jump. The method
I chose to calculate the jump for this project was the Impulse-momentum
method, detailed extensively in reference 1
1.7
F dt = P
Applying this formula to the ground contact phase of the jump, starting
from when the jumper is stationary with v = 0 and t = 0 to the instant of
takeoff where a = 0 gives
R
J = (FGRF ) mg)dt = mvi
The impulse due to the resultant force on the jumper may be considered
as two separate impulse:
R t2
t1
FGRF dt
R t2
t1
With the rotation angle and angular velocity of each segment updated
and summed using Kanes method, I have determined the inertia forces of
each segment at the end of the first phase of the movement. With these
values stored, I can use the trapezoidal rule with the trapz function to calculate the vertical velocity in the last second of stage one. At the moment of
takeoff, the ground reaction force is equal to 0, which means the jump will
be the result of throwing the body into the air with a specific velocity. The
maximum height then, is determined using the equation below, which was
calculated at the beginning of the project.
v2
Hmax = 2gt0
This section describes the programming aspect of the squat jump model
2.1
Programming Details
The program was created with Symbolic Python as a core library. The
following is a full list of libraries used.
2.1.1
Libraries Used
wxPython http://www.wxpython.org/ Python bindings to the wxWindows GUI cross-platform toolkit. All GUI files were created using the
simple wxPython builder.
mpmath http://mpmath.org mpmath is a Python library that calculate
real and complex floating-point arithmetic with arbitrary precision
SymPy www.sympy.blogspot.in SymPy is a symbolic language library
in Python
PyDy www.pydy.org Multibody dynamics tool kit package
NumPy www.numpy.org NumPy is the fundamental package for numerical computing with Python
SciPy www.scipy.org Open Source Library of Scientific Tools
10
2.1.2
Active Scripts
1. jumpsim - Simulator Startup Script
2. jumpsimtest - Test to plot angular velocity against time
Core Data Model and Simulation files
1. bodymodel.py - Defines the BodyModel class built using the BodyPart
object
2. bodyjumpforce.py - Builds physical properties to the BodyModel when
kinematic equations are calculated via Kanes Method
3. jumpsimcore.py - Integrates the functions together
4. transmat3.py - Function to impelement rotation matrices
3.1
This is the basic building block of the simulator. A Body part is an object
which has the following properties. (Refer to the kinematics section for more
details)
frame - Reference frame
11
3.2
Body Model
The objects written in BodyModel.py are used to build the model of the
human body, with each segment linked together at the joints.
The BodyModel class in bodymodel.py defines the actual physical model
of the body. BodyModel.py is comprised of objects from the BodyPart class
with physical values assigned to it. Each component within BodyModel
contains the common variables and functions for all the body parts used to
calculate movement.
The following classes are created in BodyModel and constitute the variables in the BodyParts class
1. sole frame
2. lower leg
3. upper leg
4. torso
5. ankle
6. knee
7. hip
1. body parts name contains lower leg, upper leg and torso
2. body joints name contains ankle, knee and hip
3. body part joints
12
3.3
The BodyJumpForce Object calculates the dynamics of the model. This program uses pre-derived calculations from the sympy library sympy.physics.mechanics.
I used scipy.integrate to apply the KanesMethod algorithm to the BodyJumpForce Class.
3.4
This module created a simple GUI I used to experiment with initial angles using the wxpython library. The GUI was created using wxFormBuilder, which
created the UI files gui.py,gui.fbp, formpanelgui.py and formpanelgui.fbp.
The mainwindow.py file contains the MainWindow class which renders
the bodymodel in the wxpane and provides a routine for frame by frame
simulation.
This class is used by the startup script.
The animation scene is rendered by using the playback.py file which implements the feature through the Playback(wx.EvtHandler) class.
13
14
References
1. Analysis of standing vertical jumps using a force platform. Nicholas
P. Linthornea School of Exercise and Sport Science, The University of
Sydney, Sydney, New South Wales, Australia 8 May 2001
2. Kanes Equations for Haptic Display of Multibody Systems, R. Brent
15
Acknowledgement
16