Converting Biomechanical Models from OpenSim to MuJoCo
CConverting Biomechanical Models from OpenSim to MuJoCo
Aleksi Ikkala, Perttu H¨am¨al¨ainen
Abstract — OpenSim is a widely used biomechanics simulatorwith several anatomically accurate human musculo-skeletalmodels. While OpenSim provides useful tools to analyse humanmovement, it is not fast enough to be routinely used foremerging research directions, e.g., learning and simulatingmotor control through deep neural networks and Reinforce-ment Learning (RL). We propose a framework for convertingOpenSim models to MuJoCo, the de facto simulator in machinelearning research, which itself lacks accurate musculo-skeletalhuman models. We show that with a few simple approximationsof anatomical details, an OpenSim model can be automaticallyconverted to a MuJoCo version that runs up to 600 times faster.We also demonstrate an approach to computationally optimizeMuJoCo model parameters so that forward simulations of bothsimulators produce similar results.
I. INTRODUCTIONOpenSim ([1], [2]) is a physics simulator extensively usedby biomechanics researchers. This community of researchershave also created many human and animal musculo-skeletalmodels, often based on cadaver studies. The unparalleledanatomical accuracy of various models have been validatedin several papers (for instance, [3], [4]).Although OpenSim models excel in accuracy, the simula-tor lacks in speed: a forward simulation of a movement thatlasts a few seconds can take minutes to run on a complexmodel comprised of tens of muscles and joints. Therefore,running OpenSim models on another physics simulator mightprovide enough speed-up to use these anatomically accuratemodels for e.g. machine learning or animation research.MuJoCo is a fast and accurate simulator oft-used inmachine learning research [5], which itself doesn’t havebiomechanical models that compare with the accuracy ofOpenSim models. Furthermore, the correspondence betweenOpenSim and MuJoCo model definitions, in terms of build-ing blocks of the models and their configurations, is highenough to warrant attempts at creating an automatic modelconverter (see MuJoCo discussion forum for multiple threadson the subject). However, to the best of authors’ knowledge,there are no MuJoCo converted models publicly available,nor is there a converter that works with reasonably complexOpenSim models. We present a new converter that is publiclyavailable at https://github.com/aikkala/O2MConverter and isable to process complex OpenSim models.II. MATERIAL AND METHODSIn our experiments we used a complex OpenSim modelcomprised of a fixed torso and dynamic shoulder and arm [3].
This work has been supported by Academy of Finland grant 299358.A. Ikkala and P. H¨am¨al¨ainen are with the Computer ScienceDepartment of Aalto University, Espoo, Finland (correspondence to [email protected] ). The model has seven degrees of freedom, including shoulderrotation and elevation, elbow flexion, forearm rotation, andwrist flexion and deviation, but we locked wrist flexionand deviation to improve OpenSim simulation stability. Themodel is actuated by 50 muscles that cover all the remainingfive degrees of freedom.We used OpenSim 4.0 and MuJoCo 2.0 and their Pythonbindings to run the experiments, all on the same laptopequipped with an Intel i7-8850H processor and 32GB RAM.
A. Model Conversion
Converting OpenSim models to MuJoCo is relativelystraightforward: both software use an XML based modeldefinition, and the model parts – bodies, joints, musculo-tendon units – are largely equivalent. In fact, building anequivalent skeletal model in MuJoCo is only a matter ofdisassembling the bodies and joints of an OpenSim modeland re-configuring them into a MuJoCo model.However, there are some anatomical details that are diffi-cult to model exactly in MuJoCo and must be approximatedto some extent. For instance, in OpenSim forces acting onjoints can be defined in a piecewise linear manner (called
Co-ordinateLimitForce ), which is cumbersome to model exactlyin MuJoCo. OpenSim also offers more flexibility over theanatomical modelling of a musculo-tendon unit (MTU), andparticularly problematic are OpenSim’s dynamically movingMTU path points whose locations change as a functionof a specified joint coordinate value (
MovingPathPoint and
ConditionalPathPoint ). All these approximations cause inac-curacies in the converted model, which can be mitigated tosome extent by optimizing the converted model’s parameters.
B. Optimization
In order to optimize the converted model’s parameters, wegenerated a 100 sets of muscle activations. These activationswere modelled as slow frequency (max 1 Hz) sine waveswith varying phases, sampled at a frequency of 500 Hz. Toincrease OpenSim simulation stability, the muscle activationsets had a duration of 1 second, and only a third of muscleswere active in a set.These muscle activations were then used as controls inboth OpenSim and MuJoCo forward dynamics simulations– with a simulation timestep of 2 milliseconds in bothsimulators – to generate trajectories. OpenSim’s forwarddynamics failed to run for 3 sets of muscle activations,and thus we used a subset of 78 trajectories for optimizingthe parameters, and a subset of 19 trajectories to estimatejoint errors before and after parameter optimization. Theparameters that we optimized were: damping and joint limit a r X i v : . [ q - b i o . Q M ] A ug ig. 1. Mean absolute error in radians for each joint over 19 test trajectories. softness for each non-locked degree of freedom, dampingand stiffness for each tendon, and scale (roughly equivalentto strength) of each muscle (160 parameters in total).The converted model’s parameters were optimized with aPython implementation of CMA-ES [7], [8], a popular black-box optimization algorithm. We used squared differenceof joint positions between OpenSim and MuJoCo forwardsimulations, summed over all seven degrees of freedom andall training trajectories, as the objective to be minimized.We also augmented the objective with a small cost term todiscourage unrealistically high parameter values.It is important to note that even smallest differences be-tween the models can make their trajectories diverge signifi-cantly over time. To alleviate the divergence, we augmentedthe controls with corrective control signals. These correctivesignals were optimized separately for each test set run byminimizing the sum of squared joint position differences,while simultaneously penalising for large corrective signalvalues using L2 loss. The corrective signals were sampled at10 Hz and modelled as cubic splines.III. RESULTSTo estimate the accuracy of the converted model, we com-pare the mean absolute errors for each joint over trajectoriesin the test set, before and after parameter optimization; seeFig. 1. See Fig. 2 for mean absolute difference between ref-erence muscle activations and optimized muscle activationsover test set runs.A video example of OpenSim reference movement along-side with the converted model’s replicated movements, withand without parameter and muscle activation optimization,is available at https://youtu.be/Nz3R6-1l3lU .In addition to estimating accuracy of the converted model,we also compared the efficiency of both simulators by calcu-lating average run time over all 97 forward simulations. OneOpenSim simulation took 15.50 seconds on average, while aMuJoCo simulation ran for 0.025 seconds on average, whichmakes MuJoCo roughly 600 times faster.IV. D ISCUSSION
Fig. 1 and Fig. 2 indicate that divergence of forwardsimulation cannot be prevented simply by optimizing theconverted model’s parameters. Fortunately, OpenSim andMuJoCo simulations can be made almost identical with onlyminor corrections to the muscle activations. This suggeststhat MuJoCo should be able to produce reasonably realistic
Fig. 2. A boxplot depicting mean absolute difference between referenceand optimized muscle activations over 19 test trajectories (outliers notvisualised). Muscle activations are in range [0 , , making the maximumdifference 1.0. results, e.g., in discovering muscle activation sequencesthrough deep reinforcement learning (for example, see [9]).Additionally, MuJoCo simulations are substantially faster,and the converted model does behave in a similar fashion tothe OpenSim model even with only parameter optimization.This might be enough for some use cases, e.g. in animationand machine learning research.Finally, it should be noted, that in addition to accuracyand speed, there’s a third performance metric: stability.In order to ensure OpenSim simulations didn’t crash wehad to lock wrist flexion and deviation, and find suitablestarting positions for joints. Even then 3 out of the 100OpenSim simulations crashed, whereas the MuJoCo modelhad no problems with wrist flexion and deviation or jointstarting positions. This is a major advantage when using suchcomplex biomechanical models for research that requiresmassive amounts of simulations, such as machine learningresearch. R EFERENCES[1] S. Delp, F. Anderson, A. Arnold, P. Loan, A. Habib, C. John, etal., ”OpenSim: Open-source software to create and analyze dynamicsimulations of movement,” in
IEEE Trans. Biomed.Eng. , vol. 54, 2007,pp. 1940-1950.[2] A. Seth et al., ”OpenSim: Simulating musculoskeletal dynamics andneuromuscular control to study human and animal movement,” in
PLoS Comput. Biol. , vol. 14, D. Schneidman, Ed. Public Library ofScience, 2018, pp. e1006223.[3] K. Saul et al., ”Benchmarking of dynamic simulation predictiosn intwo software platforms using an upper limb musculoskeletal model,”in
Comput Methods in Biomech Biomed Engin , vol. 18, Taylor andFrancs Ltd, 2015, pp. 1445-1458.[4] E. Arnold, S. Ward, R. Lieber, S. Delp, ”A model of the lower limbfor analysis of human movement,” in
Ann Biomed Eng , vol. 38, 2010,pp. 269-279.[5] E. Todorov, T. Erez, Y. Tassa, ”MuJoCo: A physics engine for model-based control,” in
IEEE IROS , 2012, pp. 5026-5033.[6] G. Brockman et al., ”OpenAI Gym,” arXiv:1606.01540 , 2016.[7] N. Hansen, S. M¨uller, P. Koumoutsakos, ”Reducing the time com-plexity of the derandomized evolution strategy with covariance matrixadaptation (CMA-ES),” in
Evolutionary Computation , vol. 11, Cam-bridge, MA: MIT Press, 2003, pp. 1-18.[8] N. Hansen, Y. Akimoto, P. Baudis, ”CMA-ES/pycma on Github,”2019.[9] S. Lee, M. Park, K. Lee, J. Lee, ”Scalable muscle-actuated humansimulation and control,” in