OpenSense - Kinematics with IMU Data

OpenSense - Kinematics with IMU Data

Welcome to the OpenSense documentation! To complete this example, you will need to download OpenSim 4.1 or later. If you try the example and software, please send any issues or feedback to opensim@stanford.edu. Note that the functionality has been improved in later versions including the introduction of visualization tools for IMU data in version 4.2.

 

OpenSense is a new workflow for analyzing movement with inertial measurement unit (IMU) data. In the page below, we introduce you to the tool, show you how to get started, and describe how to use the software to compute and analyze gait kinematics through a hands-on example.

What is OpenSense?

OpenSense is a workflow that enables users to compute the motions of body segments based on inertial measurement unit (IMU) data, as shown in the animation below. The OpenSense workflow is summarized in the text and flowchart below. 

Inputs: OpenSim Model and IMU Data

To get started, you will need an OpenSim model that includes the joints and degrees of freedom of interest. In the example below, we provide a model for studying lower-extremity kinematics during gait. There are many more models available through our Model Library. If you are solely interested in joint angles and other kinematic quantities (e.g., normalized muscle lengths and lengthening velocities), the model need not be scaled to the anthropometry of the subject.

You must also input orientations from one or more IMU sensors. We currently support Xsens and APDM file formats. You can create your own file converter to support any other IMU system and we plan to add support for additional sensor manufacturers in the future. We currently assume that sensor fusion and syncing have been performed using a vendor’s or third-party algorithm. Several open-source sensor fusion algorithms are also available on GitHub. 

Registration and Calibration

OpenSense provides an interface to associate and register each IMU sensor with a body segment of an OpenSim model (as an IMU Frame). We provide a basic calibration routine in which the first time step of IMU data is registered to the default pose of the model. You change the registration pose by changing the default coordinate values of the model. You can also write your own calibration procedures in Matlab, Python, etc. to optimize the initial pose of the model for calibration using other data sources (markers, goniometer, etc). Read more about these steps in our User's Guide chapter on the IMU Placer tool.

Computing Inverse Kinematics

An inverse kinematics method is used to compute the set of joint angles at each time step of a motion that minimizes the errors between the experimental IMU orientations and the model’s IMU Frames. The angles can then be used as inputs to other OpenSim tools and analyses or you can visualize these angles in the OpenSim GUI. The OpenSense capabilities are available through the command line and through scripting (Matlab or Python). As of OpenSim 4.2, the calibration and inverse kinematics steps are also available through the OpenSim GUI. The resulting Model and Motion can be loaded, visualized, and analyzed in the OpenSim GUI. Read more about this step in the User's Guide chapter on IMU Inverse Kinematics.

Back to top


How to Setup the OpenSense Tools

The OpenSense workflow is available as of OpenSim 4.1. To get started, you will first need to download and install the latest OpenSim version (minimum version is 4.1). OpenSense can be downloaded from SimTK, with both Windows and Mac builds available.  You can perform the OpenSense workflow on Mac or Windows through:

  • Matlab scripting: To use OpenSense in Matlab, follow the Matlab scripting setup instructions.

  • Python scripting: To use OpenSense in Python, follow the Python scripting setup instructions.

  • Command line: To use OpenSense from the command line, read about the Command Line Utilities

  • GUI: To use OpenSense tools from the application GUI (version 4.2 and later). The setup files are included under the "Models\Rajagopal_OpenSense" folder included with the distribution.

As with OpenSim, the OpenSense tools use XML settings files to specify the details of your workflow. 

 

Back to top


Running OpenSense to Compute Gait Kinematics

Now that you've setup OpenSense, we will show you how to use the software through a hands-on example using example experimental IMU data from a study of lower extremity gait kinematics. The example data, models, scripts, and setup files can be found in your OpenSim resources directory under [Your Documents Directory]/OpenSim/OpenSim 4.1/Code/Matlab/OpenSenseExample.

The basic steps for running an IMU-based OpenSense kinematics analysis are the following;

The flowchart below shows the workflow for the example. We will import the IMU sensor data, calibrate our OpenSim model, compute inverse kinematics, and then visualize the results.  

We use Xsens sensor data in this example, but all the steps for using APDM sensors are identical except for data reading. Read how to import APDM sensor data in the section below. Please note that the data in this example is for illustrative purposes and not intended for research use.

Step One: Collect and Prepare IMU Data

The first step is to collect your data and convert it into a format that you can read into OpenSim and process with the OpenSense workflow.

  1. You must place the sensors on your subject, typically with one sensor per tracked segment. For each IMU sensor, you must keep track of which sensor is placed on which body.

  2. You then must collect calibration data, where the subject is in a known pose (i.e., specify or record each joint angle). You must keep track of the timestamp(s) for the calibration pose. The calibration data will be used by OpenSense to register the IMUs to the OpenSim model. The subject's pose during the calibration data collection must, as closely as possible, match the (editable) default pose defined by the model. You can standardize a simple static pose for each subject by using simple measurement equipment, like a goniometer.

  3. The OpenSense workflow also allows you to perform a heading correction to help orient the model in 3D space during the calibration phase. To do heading correction, you need to specify a base IMU (e.g., the pelvis) and the heading of that IMU (i.e., which axis is pointing forward). So if you are going to perform the heading correction, you will need to also note the base IMU and its heading.

  4. Collect the movement of interest (e.g., gait) with the same IMU placement.

  5. Pre-process your data. IMU sensor systems, like Xsens and APDM, typically provide features that perform sensor fusion, time syncing, and data interpolation for missing entries. The current version of OpenSense assumes that this pre-processing has already been performed and that you are inputting processed rotation matrices. 

For our example, we have eight sensors placed as follows:

 

  • IMUs were placed on the Trunk, Pelvis, and the right and left Thighs, Shanks, and Feet.

  • It is important to note which sensor ID number represents which body on the subject. For example, Xsens sensors will have sensor names such as MT_012005D6_009-001_00B42279 where the section in bold is different for each sensor. In this example, it is noted that sensor MT_012005D6_009-001_00B421E6 is attached to the pelvis. 

  • In our example, the calibration pose is a neutral pose where the hips, knees, and ankles were at (or close) to 0 degrees. The subject is in the calibration pose in the first time step of the data collection.

  • We are using the pelvis as the base IMU. For the pelvis IMU, the z-axis is pointing forward in our calibration.

  • We used the Xsens software to output quaternions for our calibration and gait data.

 

Step Two: Convert IMU Data into OpenSim Format 

Once you have collected and pre-processed your data, you must convert it to OpenSim's file format and associate it with an OpenSim model. Data from IMUs can be in various formats: a single file with numbered sensor names (e.g., APDM) or multiple files with sensor-specific numbering (e.g., Xsens). Upon import, OpenSim will create a single, time synced, Storage (.sto) file format for orientations, converting the rotation matrices into quaternions. 

In this example, we will be using data from an Xsens system that has been pre-processed (e.g., time-syncing and sensor fusion has been performed)  and exported to an Xsens text format. You can find this data in the IMUData folder. Each Xsens sensor is represented by a single text (.txt) file with time histories of the internal sensor data. We assume the data reported by the IMU system to include orientations (in the case of XSens these are assumed to be direction-cosine-matrices).

To read your data, you first need to create a file that lets OpenSense know which sensor is associated with which body segment in the Model. In our example, this file is called myIMUMappings.xml. You can open and edit this file in any text editor. In this settings/XML file you specify the following information:

  • <trial_prefix> This is the common prefix of all the .txt files for a given movement trial. In our example, the prefix is "MT_012005D6_009-001".

  • <ExperimentalSensor name> looks for the string after <trial_prefix> to identify the the specific sensor file. In our example, the first sensor uses the prefix "_00B42268"

  • <name_in_model> is the corresponding name of the sensor in the OpenSim model. In our example, the first sensor is associated with the torso segment of our model.

An example setup file is shown below:

 

Each IMU sensor is represented as a Frame in an OpenSim Model, where a Frame is an orthogonal XYZ coordinate system. When you read in your data, OpenSense will find the appropriate IMU Frame in your model (based on the mappings XML file) or create an IMU Frame, if it doesn't already exist. OpenSense uses a naming convention where we expect the sensor to be named as <bodyname>_imu. For example, the OpenSim model has a right femur body called femur_r, therefore the IMU sensor must be called femur_r_imu.

The IMU reader then creates a storage file with the orientation data for each sensor, where each column in the storage file is named according to the Frame in the corresponding OpenSim model. To read in your data, use the following steps, depending on how you are accessing the OpenSense workflow

Matlab commands to create an orientations file from IMU sensor data

Launch Matlab and set the OpenSimExampleFiles folder as your working directory. Enter the following code to read in the IMU sensor data.

OpenSim is supported by the Mobilize Center , an NIH Biomedical Technology Resource Center (grant P41 EB027060); the Restore Center , an NIH-funded Medical Rehabilitation Research Resource Network Center (grant P2C HD101913); and the Wu Tsai Human Performance Alliance through the Joe and Clara Tsai Foundation. See the People page for a list of the many people who have contributed to the OpenSim project over the years. ©2010-2024 OpenSim. All rights reserved.