API¶
gait2de¶
- algait2de.gait2de.evaluate_autolev_rhs(
- generalized_coordinates,
- generalized_speeds,
- specified_quantities,
- constants,
This function takes the current values of the coordinates, speeds, and specifieds and returns the derivatives of the speeds, i.e. the accelerations.
q’’ = f(q’, q, u)
- Parameters:
generalized_coordinates (ndarray of floats, shape(9,)) – Trunk translation (x, y) and the joint angles.
generalized_speeds (ndarray of floats, shape(9,)) – Trunk translation rate and the joint rates.
specified_quantities (ndarray of floats, shape(9,)) – Trunk horizontal and vertical force and the joint torques.
constants (dictionary) – A dictionary of floats with keys that match the Autolev constants’ names.
- Returns:
generalized_accelerations (ndarray, shape(9,)) – Trunk translation acceleration and the joint angular accelerations.
ground_reaction_forces (ndarray, shape(6,)) – The right and left ground reaction forces.
stick_figure_coordinates (ndarray, shape(20,)) – The x and y coordinates of the important points.
Notes
Generalized Coordinates
q1: x hip translation wrt ground
q2: y hip translation wrt ground
q3: trunk z rotation wrt ground
q4: right thigh z rotation wrt trunk
q5: right shank z rotation wrt right thigh
q6: right foot z rotation wrt right shank
q7: left thigh z rotation wrt trunk
q8: left shank z rotation wrt left thigh
q9: left foot z rotation wrt left shank
Specified Inputs
t1: x force applied to trunk mass center
t2: y force applied to trunk mass center
t3: tor- que between ground and trunk
t4: tor- que between right thigh and trunk
t5: tor- que between right thigh and right shank
t6: tor- que between right foot and right shank
t7: tor- que between left thigh and trunk
t8: tor- que between left thigh and left shank
t9: tor- que between left foot and left shank
GRFs
grf1: right horizontal
grf2: right vertical
grf3: right moment
grf4: left horizontal
grf5: left vertical
grf6: left moment
derive¶
- class pygait2d.derive.Symbolics(
- kanes_method: KanesMethod,
- dyn_diff_eqs: MutableDenseMatrix,
- constants: list,
- specifieds: list,
- inertial_frame: ReferenceFrame,
- origin: Point,
- segments: list,
- viz_frames: list = None,
- muscles: list = None,
- controller_repl: dict = None,
Storage for all of the SymPy and SymPy Mechanics objects.
- Parameters:
kanes_method (KanesMethod) – A
KanesMethodobject in which the equations of motion have been derived.dyn_diff_eqs (Matrix) – Kane’s Fr + Fr* expression.
constants (list of Symbol) – Constants in the equations of motion.
specifieds (list of Function(t), optional) – Specifed variables in the equations of motion.
inertial_frame (ReferenceFrame) – An inertial reference frame representing the Earth and the direction of the uniform gravitational field.
origin (Point) – A point fixed in the ground reference frame used for calculating translational velocities.
segments (list of Segment) – All of the segment objects that make up the human.
viz_frames (list of VisualizationFrame, optional)
muscles (list of MusculotendonDeGroote2016, optional) – All of the musculotendon actuators in the human.
controller_repl (dictionary)
- activations¶
Muscle activation state variables.
- Type:
list of Function(t), optional
- coordinates¶
The generalized coordinates of the system.
- Type:
list of Function(t)
- excitations¶
Specified muscle excitation input variables.
- Type:
list of Function(t), optional
- mus_diff_eqs¶
- Type:
sm.Matrix = None
- speeds¶
The generalized speeds of the system.
- Type:
list of Function(t)
- states¶
- Type:
list of Function(t)
- ground_reaction_forces¶
Force vectors acting on the right and left foot toe and heel points.
- Type:
dictionary
- property ground_reaction_forces¶
Returns a dictionary the ground reaction force vectors expressed in the inertial reference frame acting on the heel and toe of each foot. Keys are
'Right Foot heel', 'Right Foot toe', 'Left Foot heel', 'Left Foot toe'.
- property joint_angles¶
qb, qc, qd, qe, qf, qg
- property joint_torques¶
Tb, Tc, Td, Te, Tf, Tg
- pygait2d.derive.derive_equations_of_motion(
- seat_force=False,
- gait_cycle_control=False,
- include_muscles=False,
- prevent_ground_penetration=True,
- treadmill=False,
- hand_of_god=True,
- stiffness_exp=3,
- passive_torques=False,
Returns the equations of motion for the planar walking model along with all of the constants, coordinates, speeds, joint torques, visualization frames, inertial reference frame, and origin point.
- Parameters:
seat_force (boolean, optional, default=False) – If true, a contact force will be added to the hip joint to represent a surface higher than the ground to sit on.
gait_cycle_control (boolean, optional, default=False) – If true, the specified forces and torques are replaced with a full state feeback controller summed with the forces and torques.
include_muscles (boolean, optional, default=False) – If true, muscle actuators will be included in addition to the joint torque actuators.
prevent_ground_penetration (boolean, optional) – If true, the ground force will be added to all joint centers as well as the feet to prevent the model from penetrating the ground at all. This matches the behavior of the Autolev model. Otherwise, the force will only be applied to the feet bottoms.
treadmill (boolean, optional) – If true, a time varying treadmill speed will be included in the contact force calculation.
hand_of_god (boolean, optional) – If true, a two component specified force acting on the mass center of the torso and a torque acting on the torso will be included.
stiffness_exp (float, optional) – Exponent of the contact force stiffness force.
passive_torques (boolean, optional) – If true, a nonlinear passive torque function is added.
- Returns:
symbolics – Contains all symbolic model components, see
Symbolics.- Return type:
Notes
Order of time varying variables:
coordinates: qax, qay, qa, qb, qc, qd, qe, qf, qg
speeds: uax, uay, ua, ub, uc, ud, ue, uf, ug
specifieds: [Fax, Fay, Ta], Tb, Tc, Td, Te, Tf, Tg, [v]
[Fax, Fay, Ta] and [v] are included only if
hand_of_godandtreadmillare true, respectively.
segment¶
- class pygait2d.segment.BodySegment(
- label,
- description,
- parent_reference_frame,
- origin_joint,
- joint_description,
- inertial_frame,
- passive_torque=False,
Represents a 2D rigid body which has a rotation joint (origin joint) and an attachment joint (joint).
- Parameters:
label (string) – A short label for the segment, like ‘A’.
description (string) – A short description of the segment, like ‘Trunk’.
parent_reference_frame (sympy.physics.vector.ReferenceFrame) – The parent reference frame for this segment.
origin_joint (sympy.physics.vector.Point) – The point where this segment is connected to its parent.
joint_description (string) – A short description of a new joint point, e.g. ‘knee’, for this segemt to attach to its child segment.
inertial_frame (sympy.physics.mechanics.ReferenceFrame) – The global inertial reference frame of the system. This is used to apply gravity to the segment (in the negative y direction of this frame).
- pygait2d.segment.contact_force(
- point,
- ground,
- origin,
- belt_speed=0,
- stiffness_exp=3,
Returns a contact force vector acting on the given point made of friction along the contact surface and elastic force in the vertical direction.
- Parameters:
point (sympy.physics.mechanics.Point) – The point which the contact force should be computed for.
ground (sympy.physics.mechanics.ReferenceFrame) – A reference frame which represents the inerital ground in 2D space. The x axis defines the ground line and positive y is up.
origin (sympy.physics.mechanics.Point) – An origin point located on the ground line.
belt_speed (sympifiable, i.e. Symbol, Function(), number, etc.) – A variable or value that represents the possibly time varying belt speed for treadmill walking.
stiffness_exp (float, optional) – Expoent of the stiffness force.
- Returns:
force – The contact force between the point and the ground.
- Return type:
sympy.physics.mechanics.Vector
simulate¶
- pygait2d.simulate.load_constants(constants, path)[source]¶
Parses a yaml file and builds an ordered dictionary that maps SymPy symbols to floats.
- pygait2d.simulate.map_values_to_autolev_symbols(constants)[source]¶
Returns a dictionary mapping the autoleve symbol names to the ones used in Python model.
- Parameters:
constants (dictionary) – Maps python symbol names to floats.
- Returns:
d – Maps autolev symbol names to floats.
- Return type:
dictionary
utils¶
- class pygait2d.utils.ExtensorPathway(
- origin,
- insertion,
- axis_point,
- axis,
- parent_axis,
- child_axis,
- parent_shank_direction,
- parent_shank_normal,
- child_shank_direction,
- child_shank_normal,
- radius,
- coordinate,
- property attachments¶
The pair of points defining a pathway’s ends.
- property extension_velocity¶
Extension velocity of the pathway. Arc length of circle is the only thing that changes when the elbow flexes and extends.
- property length¶
Length of the pathway. Length of two fixed length line segments and a changing arc length of a circle.
- pygait2d.utils.animate(
- scene,
- fig,
- times,
- xs,
- rs,
- ps,
- file_path=None,
Returns a matplotlib animation of the model.
- Parameters:
scene (Scene3D) – A scene preconstructed from
plot().times (array_like, shape(N,)) – Monotonically increasing time with equally spaced time intervals.
xs (array_like, shape(N, n)) – State trajectories corresponding to the n Symbolics.states.
rs (array_like, shape(N, q)) – Input trajectories corresponding to the q Symbolics.specifieds.
ps (array_like, shape(r,)) – Constant parameters corresponding to the r Symbolics.constants.
file_path (string, optional) – If a path to a movie file is provided, the animation will be saved to file. See matplotlib’s
FuncAnimation.save().
- pygait2d.utils.load_sympy_matrix(filename)[source]¶
Loads a matrix from file created with save_sympy_matrix.
- pygait2d.utils.plot(sym, times, x, r, p, follow=None)[source]¶
Returns a symmeplot generated matplotlib figure of the model’s configuration.
- Parameters:
sym (Symbolics) – Data class that holds the symbolic dynamics model.
times (array_like, shape(N,)) – Monotonically increasing time.
x (array_like, shape(n,)) – State values ordered as Symbolics.states.
r (array_like, shape(,)) – Specified values ordered as Symbolics.specifieds.
p (array_like, shape(,)) – Constant values ordered as Symbolics.constants.
follow (Point, optional) – If a point is provided then the plot origin will align with the x location of this point. This purpose of this is mostly for having the animation follow a point.
- Returns:
scene (Scene3D) – symmeplot scene.
fig (Figure)
ax (Axes)