A Platform For Dynamic Simulation and Control of Movement
A Platform For Dynamic Simulation and Control of Movement
Journal of Biomechanics
journal homepage: www.elsevier.com/locate/jbiomech
www.JBiomech.com
Short Communication
a r t i c l e i n f o abstract
Article history: Numerical simulations play an important role in solving complex engineering problems and have the
Accepted 14 March 2012 potential to revolutionize medical decision making and treatment strategies. In this paper, we combine
the rapid model-based design, control systems and powerful numerical method strengths of MATLAB/
Keywords: Simulink with the simulation and human movement dynamics strengths of OpenSim by developing a
OpenSim and MATLAB interface new interface between the two software tools. OpenSim is integrated with Simulink using the MATLAB
Forward dynamics simulation S-function mechanism, and the interface is demonstrated using both open-loop and closed-loop control
Musculoskeletal model systems. While the open-loop system uses MATLAB/Simulink to separately reproduce the OpenSim
Feedback control Forward Dynamics Tool, the closed-loop system adds the unique feature of feedback control to
Muscle-actuated control
OpenSim, which is necessary for most human movement simulations. An arm model example was
successfully used in both open-loop and closed-loop cases. For the open-loop case, the simulation
reproduced results from the OpenSim Forward Dynamics Tool with root mean square (RMS) differences
of 0.031 for the shoulder elevation angle and 0.061 for the elbow flexion angle. MATLAB’s variable step-
size integrator reduced the time required to generate the forward dynamic simulation from 7.1 s
(OpenSim) to 2.9 s (MATLAB). For the closed-loop case, a proportional–integral–derivative controller
was used to successfully balance a pole on model’s hand despite random force disturbances on the pole.
The new interface presented here not only integrates the OpenSim and MATLAB/Simulink software
tools, but also will allow neuroscientists, physiologists, biomechanists, and physical therapists to adapt
and generate new solutions as treatments for musculoskeletal conditions.
& 2012 Elsevier Ltd. All rights reserved.
0021-9290/$ - see front matter & 2012 Elsevier Ltd. All rights reserved.
http://dx.doi.org/10.1016/j.jbiomech.2012.03.016
1518 M. Mansouri, J.A. Reinbolt / Journal of Biomechanics 45 (2012) 1517–1521
2010) and predicting surgical outcomes (Fox et al., 2009; Reinbolt uses the well-documented S-function API (application programming interface) to
interact with the Simulink engine (Fig. 2). An S-function is a computer language
et al., 2009). Although users can extend OpenSim by writing their
description of a Simulink block written in MATLAB, FORTRAN, C, or Cþþ language
own plug-ins in Cþþ, this software lacks the robust design and (we chose Cþþ to have easy access to all OpenSim Cþþ methods and dynamically
control components which are needed for real-time changes to linked libraries) and compiled as a MEX-file, a dynamically linked subroutine
input controls. On the contrary, MATLAB/Simulink (The Math automatically loaded and executed by MATLAB/Simulink. This interaction is very
Works, Inc., Natick, MA) as a powerful mathematical computing similar to the interaction that takes place between the engine and built-in
Simulink blocks.
and control software is a natural choice to complement OpenSim, The S-function interface uses OpenSim’s underlying Simbody dynamics engine
but it has limited resources (e.g., muscle moment arms) for and MATLAB integrators to generate the forward dynamics simulation of an
simulations of biomechanical systems (Hohne, 2000; Lim et al., OpenSim model (Fig. 1, red dotted rectangle). The user can easily change Simulink
2003). Our goal was to develop and disseminate a free interface configuration parameters (e.g., integration solver, error tolerance) to suit the
requirements of the problem at hand.
between OpenSim and MATLAB/Simulink that combines their
relevant strengths, such as rapid model-based design, control
systems, numerical simulation, and human movement dynamics 2.3. Open-loop model application
and simulation.
We created a generic open-loop Simulink model (Fig. 3a) that loads and executes
the OpenSim-based S-function described above. The interface works with any
2. Methods OpenSim model by defining block parameters for a particular simulation (Fig. 3b).
To demonstrate the open-loop characteristics and compare how well the
S-function in MATLAB/Simulink agrees with the Forward Dynamics Tool in
We start by defining the basic elements of a forward dynamics simulation of a
OpenSim, we used a simple human arm model with 2 degrees of freedom
musculoskeletal model and describe how it works in OpenSim. We then explain
(shoulder elevation and elbow flexion) and 6 muscle-tendon actuators (triceps
the basic concepts underlying the new S-function (system function) interface
brachii long head, triceps brachii lateral head, triceps brachii medial head, biceps
between OpenSim and MATLAB/Simulink. Finally, we demonstrate its application
brachii long head, biceps brachii short head, and brachialis) to simulate an elbow
in both open-loop and closed-loop control systems using a model of a human arm.
flexion movement over 1 s. The motions resulting from the OpenSim and Simulink
simulations of elbow flexion were directly compared.
2.1. Forward dynamics simulation of a musculoskeletal model
Fig. 1. Flowchart illustrating components of forward dynamics in OpenSim and MATLAB/Simulink. Simulink (large blue rectangle) is used instead of the OpenSim Forward
Dynamics Tool. The OpenSim transformations (orange rounded rectangles) between a neural command and state derivatives (e.g., joint accelerations) involve
musculotendon dynamics, musculoskeletal geometry, and multibody dynamics. Input files (green diagonal corner rectangles) are required by OpenSim for the model,
controls (if applicable), initial states, and external loads. The new S-function interface (red dotted rectangle) takes a controls file or Simulink input signal and uses OpenSim
to computes state derivatives subsequently integrated by MATLAB integrators instead of OpenSim integrators. (For interpretation of the references to color in this figure
legend, the reader is referred to the web version of this article.)
M. Mansouri, J.A. Reinbolt / Journal of Biomechanics 45 (2012) 1517–1521 1519
Fig. 2. Overview of the new S-function interface: (a) The interface links the rapid model-based design and control systems strengths of MATLAB/Simulink with the
numerical simulation and human movement dynamics strengths of OpenSim. (b) Flowchart illustrating stages for each Simulink simulation. (c) OpenSim v1.9 (higher
versions not shown) methods called during each simulation stage.
Fig. 3. Overview of an open-loop model application for arm flexion. (a) The Simulink graphical editor window shows input controls (U), the new S-function interface
(middle), and the output states (Y). (b) The custom Simulink block parameter dialog box shows every input parameter required (or optional) by the OpenSim Forward
Dynamics Tool to perform a simulation. The parameter names are identical to those implemented in OpenSim to enable a straightforward transition to the new interface.
(c) The output states may be displayed using a State Selector and Scope within the graphical editor or they may be loaded as a motion file in OpenSim to visualize the
simulated movement.
1520 M. Mansouri, J.A. Reinbolt / Journal of Biomechanics 45 (2012) 1517–1521
Fig. 4. Example closed-loop Simulink model extending the open-loop case with control of a human arm balancing a pole. The desired pole angle was zero and used to
compute a pole angle error. The proportional-integral-derivative (PID) controller, along with the muscle gain matrix was used to compute control correction signals for
each of the six muscles to balance the pole, despite random force disturbances exerted on the pole.
Fig. 5. Closed-loop simulation of balancing a pole despite random force disturbances. (a) A PID controlled human arm model balancing a pole (five time frame series from
0.25 s to 0.55 s shown). (b) Random force disturbances were exerted on the pole. (c) The pole angle measured from vertical remained small.
3. Results 4. Discussion
The new interface between OpenSim and MATLAB/Simulink The new S-function interface combines the numerical simulation
allows rapid model-based design and numerical simulation of and human movement dynamics strengths of OpenSim with the
human movement using both open-loop (Fig. 3) and closed-loop robust design, powerful math, and control system strengths of
(Figs. 4 and 5) control systems. MATLAB. This integrated platform has promise for better under-
For the open-loop case, the Simulink generated shoulder standing movement control and the potential to improve treatment
angle matched the OpenSim generated angle within a 0.031 root planning.
mean square (RMS) difference. The RMS difference for the elbow The S-function interface and control systems software developed
flexion angle was 0.061. Using the OpenSim integrator error in this study had some limitations. First, the compatible versions of
tolerance of 1e-3, the computation time was 7.1 s (computational OpenSim (v2.3.1), MATLAB (v7.13.0), and Simulink (v7.7) were
speed was assessed on a 3.2 GHz Intels Xeons workstation with based on those available at the time of the S-function interface
3.00 GB of RAM). However, it took 2.9 s to generate the same development. Thus, generating the newer versions of the interface
forward dynamics simulation of the arm model using the new may be needed as future versions of these software packages may
interface. improve computational efficiency and add new features. However,
For the closed-loop case, the PID controller successfully the current version of the interface, which is compatible with all
rejected random force disturbances ranging between 730 N versions of OpenSim (v1.9–v2.3.1), seems to be sufficient as it
(Fig. 5b) and balanced the pole with a maximum pole angle error contains all of the previous OpenSim features and the new contact
from vertical of 1.191 (Fig. 5c). Using the MATLAB integrator with modeling capability. Second, the PID control was a simple, classical
the same error tolerance as the open-loop case, the computation approach among the many available closed-loop control systems.
time for the closed-loop system was 5.9 s. However, by applying the muscle gain in our closed-loop controller
M. Mansouri, J.A. Reinbolt / Journal of Biomechanics 45 (2012) 1517–1521 1521
which was designed based on the muscle maximum isometric force, supported by a subaward from the NIH Roadmap for Medical
we made the control signal or muscle excitation to act analogous Research U54 GM072970.
(but not identical) to the human neural command minimizes
muscular effort. Whereas the controller development is not a focus
of this study, the new interface allows custom, complex controllers References
to be developed, tested, and refined.
Despite these limitations, the interface allows users to access any Andrews, B.J., Davoodi, R., Kamnik, R., Bajd, T., 1998. Control of FES in paraplegia:
OpenSim model within MATLAB/Simulink and perform forward modeling voluntary arm forces. Biomedical Materials Engineering 8, 241–251.
Barker, T.M., Kirtley, C., Ratanapinunchai, J., 1997. Calculation of multi-segment rigid
dynamics simulations. OpenSim-required input data files such as
body joint dynamics using MATLAB. Proceedings of the Institution of Mechanical
controls, initial states, and external forces can be provided by a Engineers Part H—Journal of Engineering in Medicine 211, 483–487.
Simulink signal, a MATLAB workspace variable, or a data file. This Damsgaard, M., Rasmussen, J., Christensen, S.T., Surma, E., de Zee, M., 2006.
flexibility adds the unique ability of real-time changes to input Analysis of musculoskeletal systems in the AnyBody modeling system.
Simulation Modelling Practice and Theory 14, 1100–1111.
controls (feedback control) which is necessary to study musculos- Davoodi, R., Loeb, G.E., 2002. A software tool for faster development of complex
keletal conditions. For example, gait abnormalities commonly models of musculoskeletal systems and sensorimotor controllers in Simulink
observed in children with cerebral palsy are typically treated by (TM). Journal of Applied Biomechanics 18, 357–365.
Davoodi, R., Urata, C., Hauschild, M., Khachani, M., Loeb, G.E., 2007. Model-based
surgically altering muscle functions. Unfortunately, this treatment
development of neural prostheses for movement. IEEE Transactions on
strategy does not consistently result in improved outcomes. Patient- Biomedical Engineering 54, 1909–1918.
specific simulations using feedback control have utility to determine de Zee, M., Hansen, L., Wong, C., Rasmussen, J., Simonsen, E.B., 2007. A generic
the potential efficacy of surgical correction. detailed rigid-body lumbar spine model. Journal of Biomechanics 40, 1219–1227.
Delp, S.L., Anderson, F.C., Arnold, A.S., Loan, P., Habib, A., John, C.T., Guendelman, E.,
Although our interface shares some similarities with other Thelen, D.G., 2007. OpenSim: open-source software to create and analyze
interfaces, this work is fundamentally different from previous work dynamic simulations of movement. IEEE Transactions on Biomedical Engineer-
focused on functional electrical stimulation (Davoodi and Loeb, ing 54, 1940–1950.
Delp, S.L., Loan, J.P., 1995. A graphics-based software system to develop and
2002) and finite element analysis (Rasmussen and Ozen, 2007). analyze models of musculoskeletal structures. Computers in Biology and
Others linked their simulation software (MSMS) with MATLAB Medicine 25, 21–34.
(Davoodi et al., 2007; Hauschild et al., 2007); however, their package Delp, S.L., Loan, J.P., Hoy, M.G., Zajac, F.E., Topp, E.L., Rosen, J.M., 1990. An interactive
uses the SimMechanics toolbox for simulating musculoskeletal graphics-based model of the lower extremity to study orthopaedic surgical
procedures. IEEE Transactions on Biomedical Engineering 37, 757–767.
dynamics. In our case, we built on the freely available Simbody Fox, M.D., Delp, S.L., 2010. Contributions of muscles and passive dynamics to swing
dynamics engine and OpenSim software. The users also should not initiation over a range of walking speeds. Journal of Biomechanics 43, 1450–1455.
confuse the developed interface with OpenSim’s built-in capability Fox, M.D., Reinbolt, J.A., Ounpuu, S., Delp, S.L., 2009. Mechanisms of improved knee
flexion after rectus femoris transfer surgery. Journal of Biomechanics 42, 614–619.
of running the OpenSim Forward Dynamics Tool using the MATLAB Hamner, S.R., Seth, A., Delp, S.L., 2010. Muscle contributions to propulsion and
command line feature, which only runs OpenSim tool from the support during running. Journal of Biomechanics 43, 2709–2716.
system command line using the OpenSim integrator. On the con- Hauschild, M., Davoodi, R., Loeb, G.E., 2007. A virtual reality environment for
designing and fitting neural prosthetic limbs. IEEE Transactions on Neural
trary, our tool uses Simbody dynamics engine and MATLAB inte-
Systems and Rehabilitation Engineering 15, 9–15.
grators to create a new platform for forward dynamics as a Simulink Hohne, G., 2000. Computer aided development of biomechanical pilot models.
block and to add the potential of extending the tool and applying it Aerospace Science and Technology 4, 57–69.
in closed-loop control systems. Holzbaur, K.R., Murray, W.M., Delp, S.L., 2005. A model of the upper extremity for
simulating musculoskeletal surgery and analyzing neuromuscular control.
The potential to use OpenSim and MATLAB/Simulink to study Annals of Biomedical Engineering 33, 829–840.
and improve treatments for musculoskeletal conditions is excit- Jacobs, J.J., Andersson, G.B.J., Bell, J.E., Weinstein, S.L., Dormans, J.P., Gnatz, S.M.,
ing. This project not only integrates software tools, but also allows Lane, N., Puzas, J.E., Clair, E.W., Yelin, E.H., 2008. The burden of musculoske-
letal diseases. Bone and Joint Decade.
integration of neuroscientists, biomechanists, and physical thera-
Kepple, T.M., Siegel, K.L., Stanhope, S.J., 1997. Relative contributions of the lower
pists to adapt and generate new solutions as treatments for extremity joint moments to forward progression and support during gait. Gait
musculoskeletal conditions. All of the source code, Simulink and Posture 6, 1–8.
model examples, and user documentation related to this work Lemay, M.A., Crago, P.E., 1996. A dynamic model for simulating movements of the
elbow, forearm, an wrist. Journal of Biomechanics 29, 1319–1330.
will be available on a SimTK.org project dedicated to the interface Lim, C.L., Jones, N.B., Spurgeon, S.K., Scott, J.J.A., 2003. Modelling of knee joint
(https://simtk.org/home/opensim_matlab). muscles during the swing phase of gait—a forward dynamics approach using
MATLAB/Simulink. Simulation Modelling Practice and Theory 11, 91–107.
Otoole, R.V., Jaramaz, B., Digioia, A.M., Visnic, C.D., Reid, R.H., 1995. Biomechanics
Conflict of interest statement for preoperative planning and surgical simulations in orthopedics. Computers
in Biology and Medicine 25, 183–191.
Rasmussen, J., Ozen, M., 2007. AnyBody–ANSYS interface: CAE Technology for the
We do not have any financial or personal relationships with human body. CADFEM Medical.
other people or organizations that could inappropriately influence Reinbolt, J.A., Fox, M.D., Schwartz, M.H., Delp, S.L., 2009. Predicting outcomes of
rectus femoris transfer surgery. Gait and Posture 30, 100–105.
our manuscript. Thelen, D.G., Anderson, F.C., 2006. Using computed muscle control to generate
forward dynamic simulations of human walking from experimental data.
Journal of Biomechanics 39, 1107–1115.
Acknowledgments Thelen, D.G., Anderson, F.C., Delp, S.L., 2003. Generating dynamic simulations of
movement using computed muscle control. Journal of Biomechanics 36, 321–328.
Vasavada, A.N., Li, S., Delp, S.L., 1998. Influence of muscle morphometry and
The authors are grateful to Ajay Seth, Ayman Habib, and Scott moment arms on the moment-generating capacity of human neck muscles.
Delp for their helpful conversations and input. This work was Spine 23, 412–422.