DELHI TECHNOLOGICAL UNIVERSITY
Microprocessors And Microcontrollers (EE 306)
PROJECT REPORT
Collection of Motion Capture data by the use of Arduino
and IMUs (Inertial Measurement Units).
Submitted to: Submitted by:
Dr. Anup Kumar Sagar Ranjan 2K19/EE/211
Sanyam Jain 2K19/EE/219
1|P ag e
CERTIFICATE
I hereby certify that the project entitled “Collection of Motion
Capture data by the use of Arduino and IMUs (Inertial
Measurement Units).” Was submitted to Delhi Technological
University, Delhi, by Sanyam Jain (2K19/EE/219) and Sagar
Ranjan (2K19/EE/211) for the award of the degree of bachelor of
technology, is a record of project work under my supervision. To
the best of my knowledge this work has not been submitted in
part or full for any degree or diploma to this university or
elsewhere.
Dr. Anup Kumar
2|P ag e
CANDIDATE DECLARATION
We, Sagar Ranjan (2K19/EE/211) and Sanyam Jain (2K19/EE/219)
of B. TECH Electrical Engineering, hereby declare that the project
entitled “Collection of Motion Capture data by the use of Arduino
and IMU’s (Inertial Measurement Units).” submitted to Delhi
Technological University, Delhi, in partial fulfilment of the
requirements for the award of degree of Bachelor of Technology
is original and not copied from any source without proper
citation. This work has not previously formed the basis for the
award for any degree, diploma associateship, fellowship or any
other similar title or recognition.
Place - DELHI. CANDIDATE 1 – Sagar Ranjan
Date - 03/05/2022 CANDIDATE 2 – Sanyam Jain
3|P ag e
ACKNOWLEDGEMENT
Presentation, Inspiration, and Motivation have always played a
key role in the success of any venture. Every student's work own
debts to their predecessors, their teachers, professors, comrades,
and their parents. We gratefully acknowledge our deep
indebtedness to all of them.
The present work is an effort of ours to shed some light on the
application of Probability and statistics in the world of Gambling
Mathematics. This work would not have been possible to come to
its present shape without the able guidance of our Professor
Dr. Anup Kumar With a deep sense of gratitude, we acknowledge
the support and guidance provided by our Professor.
At last, we would like to thank our parents to give us moral
support and for their never-ending love and care which motivated
us to complete this project.
4|P ag e
Contents
1. Introduction 6
2. Theory 7
3. MEMS Accelerometer Gyroscope
Magnetometer 8
4. Data structuring for the file usage 10
5. Components Required 12
6. Component Selection 13
7. Connections 15
8. Flow chart 16
9. Code 17
10. Making final 20
11. Using system 21
12. Getting Output 22
13. Future scope 24
14. References 25
5|P ag e
Introduction
Motion capture (mocap for short) is the process of recording the movement
of objects or people. It is used in military, entertainment, sports, medical
applications, and for validation of computer vision and robotics. In
filmmaking and video game development, it refers to recording actions of
human actors, and using that information to animate digital character
models in 2D or 3D computer animation. When it includes face and fingers
or captures subtle expressions, it is often referred to as performance
capture. In many fields, motion capture is sometimes called motion
tracking, but in filmmaking and games, motion tracking usually refers more
to match moving.
This is an Arduino based open motion capture suit. Motion capture is about
getting the orientation of every-body limb or part at real time as accurate as
possible. A simple MEMS IMU device and freely available sensor fusion
algorithms are enough to get a decent result. When we want to get the data
of several devices we need to use a multiplexer. Most of this devices came
with an i2c interface, but their address is fixed in the hardware to overcome
this a system was designed that is flexible enough to be adapted to the
needs of any project that may require the capture of human (and non-
human) movement in fields as vast as Game Design, Animation, Digital
Arts, Electronic Music, Gait analysis or Physical Therapy.
The other systems out there use sensors that are either too old and don’t
have necessary support or the other options available are commercial that
can cost upward of $1000 that is why this system is different from others on
the market
6|P ag e
Theory
An IMU is a sensor suite complete with an accelerometer and gyroscope. A MARG
contains an IMU plus a Magnetometer. All three of these sensors measure the
physical qualities of Earth's fields or orientation due to angular momentum.
Alone, these sensors have faults that the other sensors can make up for. One
problem is when a sensor has an axis aligned with Earth's field which prevents
using trigonometric functions to determine orientation due to tan(90) being
undefined. The fusion of sensors is critical for the accuracy of orientation and for
a complete transformation from the sensor's inertial frame to the Earth frame.
The Madgwick Filter [1] fuses the IMU and the MARG. It does this by using
gradient descent to optimize a Quaternion that orients accelerometer data to a
known reference of gravity. This quaternion is weighted and integrated with the
gyroscope quaternion and previous orientation. This result is normalized and
converted to Euler angles.
A Quaternion is a 4-dimensional number, an extension of the complex plane. It
has a real component and 3 imaginary components. Rather than rotate about 3
axes, the quaternion rotates a certain amount of degrees about a vector. The
math is ridiculously simple (in quaternion form) compared to Euler rotation
matrices.
7|P ag e
MEMS Accelerometer Gyroscope
Magnetometer
The MEMS are very small systems or devices, composed of micro components
ranging from 0.001 mm to 0.1 mm in size. These components are made of silicon,
polymers, metals and/or ceramics, and they are usually combined with a CPU
(Microcontroller) for completing the system. Now we will briefly explain how each
of these Micro-Electro-Mechanical-Systems (MEMS) sensors work.
MEMS Accelerometer
It measures acceleration by measuring
the change in capacitance. Its
microstructure looks something like
this. It has a mass attached to a spring
which is confined to move along one
direction and fixed outer plates. So
when an acceleration in a particular
direction will be applied the mass will move and the capacitance between the
plates and the mass will change. This change in capacitance will be measured, and
processed and it will correspond to a particular acceleration value.
MEMS Gyroscope
The gyroscope measures angular
rate using the Coriolis Effect. When a
mass is moving in a particular
direction with a particular velocity
and when an external angular rate
will be applied as shown with the
green arrow a force will occur, as
shown with the blue-red arrow, which
will cause perpendicular
displacement of the mass. So similar to the accelerometer, this
8|P ag e
displacement will cause a change in capacitance which will be measured,
and processed and it will correspond to a particular angular rate.
MEMS Magnetometer
It measures the earth’s magnetic
field by using Hall Effect or Magneto
Resistive Effect. If we have a
conductive and we set the current to
flow through it, the electrons would
flow straight from one to the other
side of the plate. Now if we bring
some magnetic field near the plate
we would disturb the straight flow and the electrons would deflect to one
side of the plate and the positive poles to the other side of the plate. That
means if we put a meter now between these two sides we will get some
voltage which depends on the magnetic field strength and its direction.
9|P ag e
Data structuring for the file usage
To see the collected Motion capture data we need to arrange the data in form of
a .bhv file. The BVH file format was originally developed by Biovision, a motion
capture services company, as a way to provide motion capture data to their
customers. The name BVH stands for Biovision hierarchical data. This format
mostly replaced an earlier format that they developed. The BVH format is an
excellent all-around format, its only drawback is the lack of a full definition of the
basis pose (this format has only translational offsets of children segments from
their parent, no rotational offset is defined), it also lacks explicit information for
how to draw the segments but that has no bearing on the definition of the
motion.
Here in the first section, all the bones are declared and their position and lengths
are also declared.
Then after the structuring is complete the number of frames is declared.
10 | P a g e
Then the frame time is declared .It is equal to the time difference taken between
the readings. Then the data is arranged in the format that is declared above in the
data structure. The data is arranged in the consecutive manner from root bone to
the most extreme bone. To
capture the position only the
coordinates of the ROOT bone
are taken and for every other
bone the Yaw, Roll and Pitch
are recorded.
The term Yaw, Roll and Pitch
are commonly used in Arial
navigation. Yaw refers to Z
rotation, Roll refers to X rotation and Pitch is referred to Y rotation
11 | P a g e
Components Required
Quantity Value
1 Arduino Mega 2560
1 SD card module
1 I2c mux TCA9548A
4 MPU 9250 (IMU)
1 PERF board
3Meter 6 strand wires
1Meter Single-core wire
12 | P a g e
Component Selection
Microcontroller:
Arduino Mega was chosen as the main
controller as the space required was large
and could not be supported by the other
microcontrollers commonly available out
there. The ATmega2560 has 256 KB of flash
memory for storing code (of which 8 KB is
used for the bootloader), 8 KB of SRAM and
4 KB of EEPROM (which can be read and
written with the EEPROM library).Thus expanding scope for future development.
IMU:
Earlier MPU6250n was selected but it only featured
the accelerometer and gyroscope and a
magnetometer could be added externally through the
auxiliary i2c ports. But the data fusion through the
module was time consuming and produced errors.
Mpu9250 was selected as it has onboard
magnetometer which helps and by pulling the ad0 pin
the I2C address of the board can be changed from 0x68 to 0x69
Multiplexer:
TCA9548A was used in the project as any device when used on I2C
bus mush have different address and in case of MPU9250 on 2
addresses were useable to overcome this we have used 8 channel
multiplexer and by using this we can obtain data from up to 18
sensor at once(2x8 from multiplexer and 2 directly)
13 | P a g e
SD Card module:
We have used a SD card module as SD card
predominately uses SPI protocol to communicate
we use a SD card module as it has inbuilt voltage
regulator that converts 5V signals to 3.3V signals
that are compatible with the SD card
14 | P a g e
CONNECTIONS
The SD card module is connected to the Arduino mega board on pins 51-54 and to
Vcc and GND. The Mux board SDA and SCL lines are connected to pins 20 and 21
respectively. Then two pairs of sensors are connected to each port on the mux
board and in one of the sensors of the pair, AD0 pin should be pulled high.
Figure 1:Arduino Connections
Figure 2:MPU9250 sensors in from of a harness
15 | P a g e
Flow Chart
16 | P a g e
Code
In this project, we made our code in Arduino IDE. To support the hardware
additional libraries were created to make out code readable. The libraries are
hosted on the GitHub link:
https://github.com/SJ1751/MOCAP
The following code was used:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <mpu9250.h>
const int chipSelect = 53;
String filename;
char readdata="a";
int filenum=1;
float vrw[3],tvrw[3];
float vrfa[3],tvrfa[3];
float vrb[3],tvrb[3];
float vrs[3],tvrs[3];
int count=0;
int delt_t=50;
mpu9250 rw,rfa,rb,rs;
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
rw.ini(0x69,1);
rfa.ini(0x68,1);
rb.ini(0x69,2);
17 | P a g e
rs.ini(0x68,2);
/*
testsub1.ini(0x68,1);
testsub2.ini(0x68,2);*/
filename="MOCAP"+String(filenum,DEC)+".bhv";
Serial.print(SD.exists(filename));
while(SD.exists(filename)){
filenum=filenum+1;
filename="MOCAP"+String(filenum,DEC)+".bhv";
}
Serial.println("ENTER r to start reading data into the SDCARD");
}
void loop() {
String dataString;
quatvalget(vrw,vrfa,vrb,vrs);
readdata=Serial.read();
while(readdata=='r'){
quatvalget(tvrw,tvrfa,tvrb,tvrs);
// RunTPose(dataFile);
File dataFile = SD.open(filename, FILE_WRITE);
while(Serial.available() == 0)
{ quatvalget(vrw,vrfa,vrb,vrs);
tposaltered(vrw,vrfa,vrb,vrs,tvrw,tvrfa,tvrb,tvrs);
delt_t = millis()-count;
if(delt_t>100)
{
dataString=datatostring(vrw,vrfa,vrb,vrs);
if (dataFile)
{
dataFile.println(dataString);
Serial.println(dataString);
}
count=millis();
}
}
if(dataFile){
dataFile.close();
}
if(Serial.available()){readdata=Serial.read();}
18 | P a g e
while(readdata=='e')
{
Serial.println("DATA RECORDED SUCCEFULLY");
while(1){}
}
}
/*----------------------------------------------------------------------------------------------------------------------------------------
FUNCTIONS
------------------------------------------------------------------------------------------------------------------------------------------
*/
float subtarction(float x,float t){
float fv;
if (x-t>180){fv=x-t-360;
}
else if(x-t<-180){
fv=x-t+360;
}
else {
fv=x-t;
}
return fv;
}
void tposaltered(float ar1[3],float ar2[3],float ar3[3],float ar4[3],float tar1[3],float tar2[3],float
tar3[3],float tar4[3]){
for(int i=0;i<3;i++){
ar1[i]=subtarction(ar1[i],tar1[i]);
ar2[i]=subtarction(ar2[i],tar2[i]);
ar3[i]=subtarction(ar3[i],tar3[i]);
ar4[i]=subtarction(ar4[i],tar4[i]);
}
}
void quatvalget(float ar1[3],float ar2[3],float ar3[3],float ar4[3]){
rw.getvalues(ar1);
rfa.getvalues(ar2);
rb.getvalues(ar3);
rs.getvalues(ar4);
}
String datatostring(float ar1[3],float ar2[3],float ar3[3],float ar4[3]){
String dataString = "0.000000 0.000000 0.000000 ";
19 | P a g e
dataString += String(ar4[0], 6);dataString += " ";dataString += String(ar4[2], 6);dataString += "
";dataString += String(ar4[1], 6);
dataString += " ";
dataString += String(ar3[0], 6);dataString += " ";dataString += String(ar3[2], 6);dataString += "
";dataString += String(ar3[1], 6);
dataString += " ";
dataString += String(ar2[0], 6);dataString += " ";dataString += String(ar2[2], 6);dataString += "
";dataString += String(ar2[1], 6);
dataString += " ";
dataString += String(ar1[0], 6);dataString += " ";dataString += String(ar1[2], 6);dataString += "
";dataString += String(ar1[1], 6);
return dataString;
}
20 | P a g e
Making final file
We use the SD card recorded data and use an exported. BHV file and save the
data acquired in it and change the number of frames according to the lines
Figure 3:Sample data file received
Figure 4:Edited file
21 | P a g e
Using the system
To use the motion capture rig we have to wear it and define the
various sensors in the code along with their mux port and their
I2C address.
Then when we upload the code on the Arduino mega, It will first
initiate all the sensors and calibrate them.
Then user is advised to move in all the directions so that drift can
be minimized
Then user should get into T Pose as it the
standard pose to calibrate the model
After this in the serial window send ‘r’ and
the data will start recording
The user can do all the movements that
they wish to record
When user wants to terminate the capture
they have to send ‘e’ in the serial window
and the recording will end. It will show a message “Data capture
successful”
Then the data file can be obtained by plugging the SD card into
the computer
22 | P a g e
Getting output
To see the final result we have to into an open source 3d software blender there
we then have to go to file ->import->Motion Capture (.bhv) and browse to the
location of the file and select it.
Figure 5:User(Sanyam Jain) is wearing the Motion capture rig on the arm
23 | P a g e
And after we hit play we can see the recorded data on the screen mimicking the
recorded movements from the user.
24 | P a g e
Future scopes
For future development better and faster Integrating algorithms
can be used
Full integration of file processing can be done so that users will no
longer have to follow the post-processing steps
Better casing can be designed to make the design more modular
and compact.
Input buttons and a screen can be added to make the experience
free to move which was constrained by the USB wire connecting
the Computer and Arduino MEGA.
25 | P a g e
References
1) (Madgwick, An efficient orientation filter for inertial
and inertial/magnetic sensor arrays 2010)
2) Hayes, T. and Horowitz, P., 2010. Student Manual For
The Art Of Electronics. Cambridge: Cambridge
University Press.
3) KeeCap-Open-Motion-Capture-
Suithttps://github.com/nkeeline/KeeCap-Open-
Motion-Capture-Suit
4) M. Margolis, Arduino cookbook. Sebastopol, Calif.:
O'Reilly, 2020.
26 | P a g e