thecountoftuscany / PyTeapot-Quaternion-Euler-cube-rotation

Visualization of IMU orientation from quaternion or Euler angles with a rotating cube
GNU General Public License v3.0
144 stars 42 forks source link
arduino euler-angles imu imu-data mpu opengl orientation-sensor orientation-visualization pyopengl pyserial python quaternions teapot

+Author: Nishant Elkunchwar

[[./resources/pyteapot-gif.gif]]

This is an easy to understand Python implementation of the often-used 'MPU Teapot' processing code (an example [[https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/examples/MPU6050_DMP6/Processing/MPUTeapot/MPUTeapot.pde][here]]) for visualizing an IMU, but not specific to any particular IMU (like the MPU6060 in the case of 'MPU Teapot'). Note that this project does not do the sensor fusion of each sensor in the IMU to obtain the orientation (for the demo in the above gif, a Madgwick or Mahony filter was used from [[https://github.com/kriswiner/MPU9250/blob/master/quaternionFilters.ino][here]] to obtain the orientation). It is assumed that the user already has obtained the orientation in the form of either the yaw-pitch-roll angles or quaternions and wishes to visualize this real-time on-screen for debugging etc.

** Requirements:

Either quaternion or Euler angles or even both can be received over the serial or udp port. If both are received, the =useQuat= variable defines which one is used to rotate the cube. So for example, all of the following are valid formats for the data received over the serial or udp port:

+BEGIN_EXAMPLE

Both quaternions and Euler angles

w0.09wa-0.12ab-0.09bc0.98cy168.8099yp12.7914pr-11.8401r

Quaternions only

w0.09wa-0.12ab-0.09bc0.98c

Euler angles only

y168.8099yp12.7914pr-11.8401r

+END_EXAMPLE

Each of these must be on separate lines (or should have a '\n' at the end of the string). Other data may also be passed over Serial or Wifi, provided that none of the characters =w=, =a=, =b=, =c=, =y=, =p=, =r= are passed (for example, =somethingw0.09wa-0.12ab-0.09bc0.98cy168.8099yp12.7914pr-11.8401rsomethingelse= is valid but =somedataw0.09wa-0.12ab-0.09bc0.98cy168.8099yp12.7914pr-11.8401ranotherstring= is not since it has the characters =a= and =r=)