项目作者: ChrisZonghaoLi

项目描述 :
Motion Tracking Using Magnetometer Based On Ellipsoid Fitting Algorithm
高级语言: C
项目地址: git://github.com/ChrisZonghaoLi/Motion_Tracking_Using_Magnetometer.git


Human Body Motion Tracking Using Magnetometer & Ellipsoid Fitting Algorithm

1. Introduction

Tracking human body motion has multiple applications in robotics, fitness, and medical
fields. The purpose of this project is to obtain magnetometer (sensor) data and improve its
reliability for accurately modeling the human body motion. Spatial tracking is achieved by
using a low cost inertial measurement unit (IMU), which is the integration of an
accelerometer, a gyroscope, and a magnetometer. Inevitably, the magnetometer readings
cannot be accurate due to hard iron and soft iron errors. Hard iron errors are created by
ferromagnetic materials that have a fixed spatial relationship with the magnetometer in the
IMU, while soft iron errors are created by ferromagnetic materials that have a variable spatial
relationship with the IMU. This project focusses on optimizing the spatial tracking algorithms
and calibration methods for a magnetometer to compensate these errors.

2. Ellipsoid Fitting Algorithm

You are welcome to read more details on this from either the papers inside the folder “papers”,
or check out a condensed derivation of it from my report on my site: www.zonghaoli.com/capstone_project

3. A Short Tutorial on Software/Hardware Setups

How to install gcc and openocd successfully?

  1. 1. Install git by running:
  2. sudo apt-get install git-all
  3. 2. Clone the repository from Github to your local
  4. 3. Go to the folder gcc4mbed
  5. 4. Do gcc installation. Run:
  6. ./linux_install
  7. If the operation system is 64-bit but the 32-bit binary files are going to execute/compile, run:
  8. sudo dpkg --add-architecture i386
  9. sudo apt-get update
  10. sudo apt-get install build-essential g++
  11. sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
  12. 5. If the installation is failed, go to "../Motion_Tracking_Using_Magnetometer/gcc4mbed/code/MPU9250AHARS" and open the file "makefile" to correct:
  13. *******************************
  14. PROJECT := MPU9250AHRS --> MPU9250AHARS
  15. *******************************
  16. 6. Now compile the makefile. Run:
  17. make
  18. then go back to gcc4mbed do:
  19. ./linux_install
  20. again and this time it should work properly and gcc should be installed
  21. 7. Now we need to install openocd. First install hidapi. Run:
  22. git clone https://github.com/signal11/hidapi.git
  23. sudo apt-get install aptitude
  24. sudo aptitude install pkg-config libusb-1.0-0-dev libudev-dev libfox-1.6-dev autotools-dev autoconf automake libtool
  25. cd hidapi
  26. ./bootstrap
  27. ./configure --prefix=/usr
  28. make
  29. sudo make install
  30. 8. Install Openocd. Go to the website "https://sourceforge.net/projects/openocd/files/latest/download?source=files" and download the openocd, unzip it by running:
  31. tar xf openocd-0.9.0.tar.bz2
  32. Run:
  33. apt-get build-dep openocd
  34. cd openocd-0.9.0/
  35. ./configure --enable-aice --enable-amtjtagaccel --enable-armjtagew --enable-cmsis-dap --enable-dummy \
  36. --enable-ftdi --enable-gw16012 --enable-jlink --enable-jtag_vpi --enable-opendous \
  37. --enable-openjtag_ftdi --enable-osbdm --enable-legacy-ft2232_libftdi --enable-parport \
  38. --disable-parport-ppdev --enable-parport-giveio --enable-presto_libftdi --enable-remote-bitbang \
  39. --enable-rlink --enable-stlink --enable-ti-icdi --enable-ulink --enable-usb-blaster-2 \
  40. --enable-usb_blaster_libftdi --enable-usbprog --enable-vsllink
  41. make
  42. sudo make install
  43. 9. Now we are good to run the board! First power up the board by connecting it to usb.
  44. 10. In one terminal, start openocd by running:
  45. sudo openocd -f /usr/local/share/openocd/scripts/board/st_nucleo_f4.cfg
  46. 11. In ANOTHER terminal, go to "../Motion_Tracking_Using_Magnetometer/gcc4mbed/gcc-arm-none-eabi/bin", run:
  47. ./arm-none-eabi-gdb
  48. You will see something like this in terminal:
  49. (gdb)
  50. 12. In gdb, type:
  51. (gdb) file ../Motion_Tracking_Using_Magnetometer/gcc4mbed/code/MPU9250AHARS/NUCLEO_F401RE/MPU9250AHARS.elf
  52. (gdb) target remote :3333
  53. (gdb) load
  54. (gdb) monitor arm semihosting enable
  55. (gdb) monitor reset
  56. (gdb) continue
  57. 13. Now, open ONE MORE NEW TERMINAL and do the following (just test to see if you can retrieve info from the sensor):
  58. - in the tools directory (you will have this directory once all 1-8 steps are finished correctly) you will find two scripts: acm_reset.sh and watch.py
  59. - for this software the baud rate is 9600 - important to use correct baud rate
  60. in tools.
  61. Run:
  62. sudo ./acm_reset.sh
  63. sudo ./watch.py /dev/ttyACM0 9600
  64. 14. If everything goes well, you will see something like this:
  65. reset cdc_acm kernel module after unplugging SEGGER devices
  66. 523760 deg/s
  67. mx = -326.062531 my = -32.385883 mz = 185.895309 mG
  68. temperature = 30.099350 C
  69. q0 = 0.684724
  70. q1 = 0.016172
  71. q2 = -0.013028
  72. q3 = 0.728506
  73. Yaw, Pitch, Roll: 79.745132 -2.372995 0.181496
  74. average rate = 666.065247
  75. ax = 2.014160 ay = 2.563477 az = 994.995117 mg
  76. gx = 0.045873 gy = -0.024192 gz = 0.115313 deg/s
  77. mx = -324.497986 my = -24.563194 mz = 190.422913 mG
  78. temperature = 30.111332 C
  79. ...

Required python packages:

  1. 1. Download pyQtGraph from http://www.pyqtgraph.org/
  2. 2. sudo apt-get install python python-numpy python-opengl python-qt4 libqt4-opengl python-qt4-gl
  3. 3. sudo apt-get install python-pip
  4. 4. pip install pyserial
  5. You also need to install Pygame for the animation of the "stickman"
  6. https://www.pygame.org/download.shtml

To enable serial port on bluetooth communication:

  1. ~$ sudo hcitool scan
  2. Scanning ...
  3. 00:02:C7:7D:F5:17 HC-06
  4. ~$ sudo rfcomm bind /dev/rfcomm0 <Device MAC address> 1
  5. ~$ ls -l /dev/rfcomm0
  6. crw-rw---- 1 root dialout 216, 0 2008-12-14 23:15 /dev/rfcomm0

4. Acknowledgements

The author here would like to thank Vipul Vishnoi and Bernie Wu for the excellent teamwork,
Dr. Thomas Johnson (http://www.mtl.ok.ubc.ca/) for the supervision, and the technical supports
from Kinectic Reality (http://www.kineticreality.com/), who is also our industrial collaborator.
This project was placed 2nd among 47 groups in the final capstone project competition in 2017.

5. Video Demo

You are also welcome to take a look at the video on this project: https://www.youtube.com/watch?v=61_5dSP1mHw&t=