biorbd: A C++, Python and MATLAB library to analyze and simulate the human body biomechanics

Biomechanics is at the interface of several fields of science, such as mechanics, human physiology and robotics. Although this transdisciplinarity encourages the emergence of new ideas, the variety of data to analyze simultaneously can be overwhelming. Commonly biomechanical datasets are composed of skin markers trajectories (termed as markers), contact forces, electromyography (EMG) signal, inertial measurement units (IMU) kinematics, etc., which by nature are not straightforward to combine. It is at their meeting point—the body movement— that biorbd steps in; bio standing for biomechanics and rbd for rigid body dynamics. biorbd is a feature-based development library that targets the manipulation of biomechanical data in a comprehensive and accessible manner. For a given musculoskeletal model, it provides functions for inverse flow—i.e., from markers to EMG—and direct flow—i.e., from EMG to markers.


Summary
Biomechanics is at the interface of several fields of science, such as mechanics, human physiology and robotics. Although this transdisciplinarity encourages the emergence of new ideas, the variety of data to analyze simultaneously can be overwhelming. Commonly biomechanical datasets are composed of skin markers trajectories (termed as markers), contact forces, electromyography (EMG) signal, inertial measurement units (IMU) kinematics, etc., which by nature are not straightforward to combine. It is at their meeting point-the body movementthat biorbd steps in; bio standing for biomechanics and rbd for rigid body dynamics. biorbd is a feature-based development library that targets the manipulation of biomechanical data in a comprehensive and accessible manner. For a given musculoskeletal model, it provides functions for inverse flow-i.e., from markers to EMG-and direct flow-i.e., from EMG to markers.
Since biomechanics often requires computationally expensive or real-time computations, the core of biorbd is written in C++. Although this language provides fast computations, it lacks the flexibility of higher-level languages. To meet the needs of the biomechanics community, Python and MATLAB binders are provided with biorbd. As a result, biorbd can elegantly be implemented to common workflows of researchers without compromising the required speed.
Finally, biomechanical data are often multidimensional and almost always time-dependent which can be challenging to visualize. To help with that, bioviz , a Python visualizer, was purposely designed. This visualizer allows animating the model, record videos, and, for models that include muscles, plot muscular outputs against various features of the movement.

A biorbd overview, the inverse and direct flow
Biomechanical analyses are usually based on one (or a mixture) of the inverse or direct flow (Kainz et al., 2016). Briefly, the former uses measurements from a movement (e.g., markers) and infers its cause, while the latter assumes control (e.g., EMG) and outputs the resulting kinematics.

Inverse flow
Inverse kinematics: Estimates the generalized coordinates (q)-i.e., the body kinematicsfrom body sensor measurements (e.g., markers, IMU, etc.). The main algorithm implemented is the Extended Kalman Filter (Fohanno et al., 2010) which by design facilitates the merging of multiple data sources and takes care of missing data.
Inverse dynamics: Estimates the generalized forces (τ ) producing a given generalized acceleration (q) (the second time derivative of q): whereq is the generalized velocities, M (q) is the mass matrix and N (q,q) are the nonlinear effects.

Direct flow
Muscle activation dynamics: Estimates the muscle activation derivative (α) from the muscle excitation-that is the calcium release in the muscle that triggers the muscle contraction. Multiple activation/excitation dynamics are implemented (e.g., Manal & Buchanan, 2003;Thelen, 2003).
Forward dynamics: Estimates theq from a given τ : All the forward dynamics implemented in RBDL (Felis, 2017) are available.
Forward kinematics: Estimates the model kinematics outputs (e.g., markers, IMU) from a given q, after integrating twiceq.

The dependencies
biorbd takes advantage of efficient back ends, especially the RBDL and CasADi libraries. RBDL, written by Martin Feliz (Felis, 2017), implements Featherstone equations of spatial geometry (Featherstone & Orin, 2000), successfully used in the field of robotics (Diehl et al., 2006;Kurfess, 2018;Macchietto et al., 2009). RBDL provides the computational core for body dynamics. biorbd extends RBDL by giving commonly used biomechanics nomenclature, and by adding biomechanical modules, amongst others. RBDL is based on the highly efficient C++ linear algebra library Eigen (Guennebaud et al., 2010). Although Eigen is flexible and fast enough for most of the common usage, it cannot automatically provide derivatives of functions. Therefore, RBDL was also augmented with the algorithmic differentiation library CasADi (Andersson et al., 2019). CasADi allows computing at low cost the derivatives of almost all the functions in RBDL and biorbd. This is particularly useful when using biorbd in a gradient-based optimization setting.

Statement of need
OpenSim (Seth et al., 2018) and Anybody (Damsgaard et al., 2006) are state-of-the-art biomechanics software that provides similar analysis flows with advanced user interface. Anyb ody being a closed and proprietary software, the reason to create another library for the opensource community is self-explanatory. Conversely, OpenSim is open-source and well established in the biomechanics community.
Nevertheless, in line with the idea that simulation software in biomechanics should be validated in multiple ways (Hicks et al., 2015), providing similar tools but different in their approach allows the community to cross-validate the different implementation of the algorithms. For instance, two papers (Kim et al., 2018;Trinler et al., 2019) recently compared the outputs of Anybody and OpenSim and came to different results. Although the authors provided plausible explanations for these differences, due to the closed-source nature of Anybody, they had to assume that the implementation of the algorithms are flawless in both software. However, since a direct comparison between the actual codes is impossible, this is not verifiable. Having multiple open source software that produces similar ends by different means is a quality assurance for the end users: "Do not put all your eggs in one basket." To the best of our knowledge, there is no other open-source software that provides a complete direct and inverse flow in biomechanics. Therefore, in our opinion, biorbd and OpenSim are complementary.