{"id":3283,"date":"2022-12-24T05:55:37","date_gmt":"2022-12-24T13:55:37","guid":{"rendered":"https:\/\/www.donluc.com\/?p=3283"},"modified":"2022-12-24T05:55:37","modified_gmt":"2022-12-24T13:55:37","slug":"project-25-movement-quaternion-mk06","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=3283","title":{"rendered":"Project #25 &#8211; Movement &#8211; Quaternion &#8211; Mk06"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-3283-1\" width=\"720\" height=\"480\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02W.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02W.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02W.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>#DonLucElectronics #DonLuc #SparkFunRedBoard #Movement #MPU9150 #9DOF #Quaternion #Magnetometer #Accelerometer #Gyroscope #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02a.png\" alt=\"Quaternion\" width=\"720\" height=\"478\" class=\"alignnone size-full wp-image-3285\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02a-300x199.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02b.png\" alt=\"Quaternion\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3286\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02b-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02c.png\" alt=\"Quaternion\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3287\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/12\/DL2211Mk02c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>Quaternion<\/strong><\/p>\n<p>In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. Hamilton defined a quaternion as the quotient of two directed lines in a three-dimensional space, as the quotient of two vectors. Multiplication of quaternions is noncommutative.<\/p>\n<p>Quaternions are used in pure mathematics, but also have practical uses in applied mathematics, particularly for calculations involving three-dimensional rotations, such as in three-dimensional computer graphics, computer vision, and crystallographic texture analysis. They can be used alongside other methods of rotation, such as Euler angles and rotation matrices, or as an alternative to them, depending on the application.<\/p>\n<p><strong>SparkFun 9 Degrees of Freedom Breakout &#8211; MPU-9150<\/strong><\/p>\n<p>The SparkFun 9DOF MPU-9150 is the world\u2019s first 9-axis MotionTracking MEMS device designed for the low power, low cost, and high performance requirements of consumer electronics equipment including smartphones, tablets and wearable sensors. And guess what? You get to play with it.<\/p>\n<p>This breakout board makes it easy to prototype with the InvenSense MPU-9150 by breaking out all the pins you need to standard 0.1&#8243; spaced headers. The board also provides I2C pullup resistors and a solder jumper to switch the I2C address of the device.<\/p>\n<p>The MPU-9150 is a System in Package (SiP) that combines two chips: the MPU-6050, which contains a 3-axis gyroscope, 3-axis accelerometer, and an onboard Digital Motion Processor&#x2122; (DMP&#x2122;) capable of processing complex MotionFusion algorithms; and the AK8975, a 3-axis digital compass. The part\u2019s integrated 6-axis MotionFusion algorithms access all internal sensors to gather a full set of sensor data.<\/p>\n<p><strong>DL2211Mk02<\/strong><\/p>\n<p>1 x SparkFun RedBoard Qwiic<br \/>\n1 x SparkFun 9 Degrees of Freedom Breakout &#8211; MPU-9150<br \/>\n1 x SparkFun Cerberus USB Cable<\/p>\n<p><strong>SparkFun RedBoard Qwiic<\/strong><\/p>\n<p>SDA &#8211; Analog A4<br \/>\nSCL &#8211; Analog A5<br \/>\nVIN &#8211; +3.3V<br \/>\nGND &#8211; GND<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>DL2211Mk02p.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/* ***** Don Luc Electronics \u00a9 *****\r\nSoftware Version Information\r\nProject #25 - Movement - Quaternion - Mk06\r\n25-06\r\nDL2211Mk02p.ino\r\n1 x SparkFun RedBoard Qwiic\r\n1 1 x SparkFun 9 Degrees of Freedom Breakout - MPU-9150\r\n1 x SparkFun Cerberus USB Cable\r\n*\/\r\n\r\n\/\/ Include the Library Code\r\n\/\/ Two Wire Interface (TWI\/I2C)\r\n#include &lt;Wire.h&gt;\r\n\/\/ I2CDev I2C utilities\r\n#include &quot;I2Cdev.h&quot;\r\n\/\/ MPU9150Lib 9-axis fusion\r\n#include &quot;MPU9150Lib.h&quot;\r\n\/\/ CalLib magnetometer and accelerometer calibration\r\n#include &quot;CalLib.h&quot;\r\n\/\/ Motion Driver InvenSense Embedded SDK v5.1\r\n#include &lt;dmpKey.h&gt;\r\n#include &lt;dmpmap.h&gt;\r\n#include &lt;inv_mpu.h&gt;\r\n#include &lt;inv_mpu_dmp_motion_driver.h&gt;\r\n\/\/ EEPROM Magnetometer and Accelerometer data is stored\r\n#include &lt;EEPROM.h&gt;\r\n\r\n\/\/ the MPU object\r\nMPU9150Lib MPU;\r\n\/\/  MPU_UPDATE_RATE defines the rate (in Hz)\r\n\/\/ at which the MPU updates the sensor data and DMP output\r\n#define MPU_UPDATE_RATE  (20)\r\n\/\/  MAG_UPDATE_RATE defines the rate (in Hz) at which the\r\n\/\/ MPU updates the magnetometer data\r\n\/\/  MAG_UPDATE_RATE should be less than or equal to the MPU_UPDATE_RATE\r\n#define MAG_UPDATE_RATE  (10)\r\n\/\/  MPU_MAG_MIX defines the influence that the magnetometer has on the yaw output.\r\n\/\/  The magnetometer itself is quite noisy so some mixing with the gyro yaw can help\r\n\/\/  significantly. Some example values are defined below:\r\n\/\/ Just use gyro yaw\r\n#define  MPU_MAG_MIX_GYRO_ONLY          0\r\n\/\/ Just use magnetometer and no gyro yaw\r\n#define  MPU_MAG_MIX_MAG_ONLY           1\r\n\/\/ A good mix value \r\n#define  MPU_MAG_MIX_GYRO_AND_MAG       10\r\n\/\/ mainly gyros with a bit of mag correction\r\n#define  MPU_MAG_MIX_GYRO_AND_SOME_MAG  50\r\n\/\/  MPU_LPF_RATE is the low pas filter rate and can be between 5 and 188Hz\r\n#define MPU_LPF_RATE   5\r\n\r\n\/\/ This is our earth frame gravity vector - quaternions and vectors\r\nMPUQuaternion gravity;                                     \r\n\r\n\/\/  SERIAL_PORT_SPEED defines the speed to use for the debug serial port\r\n#define  SERIAL_PORT_SPEED  115200\r\n\r\n\/\/ Software Version Information\r\nString sver = &quot;25-06&quot;;\r\n\r\nvoid loop() {\r\n\r\n  \/\/ MPU\r\n  isMPU();\r\n  \r\n}\r\n<\/pre>\n<p><strong>getMPU.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ MPU\r\n\/\/ Setup MPU\r\nvoid isSetupMPU() {\r\n\r\n  \/\/ MPU\r\n  MPU.init(MPU_UPDATE_RATE, MPU_MAG_MIX_GYRO_AND_MAG, MAG_UPDATE_RATE, MPU_LPF_RATE);     \/\/ start the MPU\r\n\r\n  \/\/ Set up the initial gravity vector for quaternion rotation\r\n  \/\/ Max value down the z axis\r\n  gravity[QUAT_W] = 0;\r\n  gravity[QUAT_X] = 0;\r\n  gravity[QUAT_Y] = 0;\r\n  gravity[QUAT_Z] = SENSOR_RANGE;\r\n  \r\n}\r\n\/\/ MPU\r\nvoid isMPU() {\r\n\r\n  \/\/ Quaternion\r\n  \/\/ This is our body frame gravity vector\r\n  MPUQuaternion rotatedGravity;\r\n  \/\/ This is the conjugate of the fused quaternion\r\n  MPUQuaternion fusedConjugate;\r\n  \/\/ Used in the rotation\r\n  MPUQuaternion qTemp;\r\n  \/\/ The accelerations\r\n  MPUVector3 result;\r\n\r\n  \/\/ Get the latest data\r\n  if (MPU.read()) {\r\n    \r\n    \/\/ Need this for the rotation\r\n    MPUQuaternionConjugate(MPU.m_fusedQuaternion, fusedConjugate);\r\n    \r\n    \/\/ Rotate the gravity vector into the body frame\r\n    MPUQuaternionMultiply(gravity, MPU.m_fusedQuaternion, qTemp);\r\n    MPUQuaternionMultiply(fusedConjugate, qTemp, rotatedGravity);\r\n    \r\n    \/\/ Now subtract rotated gravity from the body accels to get real accelerations.\r\n    \/\/ Note that signs are reversed to get +ve acceleration results\r\n    \/\/ in the conventional axes.\r\n    result[VEC3_X] = -(MPU.m_calAccel[VEC3_X] - rotatedGravity[QUAT_X]);\r\n    result[VEC3_Y] = -(MPU.m_calAccel[VEC3_Y] - rotatedGravity[QUAT_Y]);\r\n    result[VEC3_Z] = -(MPU.m_calAccel[VEC3_Z] - rotatedGravity[QUAT_Z]);\r\n    \r\n    \/\/ print the residual accelerations\r\n    MPU.printVector(result);\r\n    Serial.println();\r\n    \r\n  }\r\n\r\n}\r\n<\/pre>\n<p><strong>setup.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Setup\r\nvoid setup() {\r\n\r\n  \/\/ Serial\r\n  Serial.begin(SERIAL_PORT_SPEED);\r\n  Serial.println(&quot;Accel9150 starting&quot;);\r\n  \r\n  \/\/ Give display time to power on\r\n  delay(100);\r\n  \r\n  \/\/ Set up I2C bus\r\n  Wire.begin();\r\n\r\n  \/\/ Setup MPU\r\n  isSetupMPU();\r\n\r\n}\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<p><strong>People can contact us:<\/strong> https:\/\/www.donluc.com\/?page_id=1927<\/p>\n<p><strong>Technology Experience<\/strong><\/p>\n<ul>\n<li>Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc&#8230;)<\/li>\n<li>IoT<\/li>\n<li>Wireless (Radio Frequency, Bluetooth, WiFi, Etc&#8230;)<\/li>\n<li>Robotics<\/li>\n<li>Camera and Video Capture Receiver Stationary, Wheel\/Tank and Underwater Vehicle<\/li>\n<li>Unmanned Vehicles Terrestrial and Marine<\/li>\n<li>Machine Learning<\/li>\n<li>RTOS<\/li>\n<li>Research &#038; Development (R &#038; D)<\/li>\n<\/ul>\n<p><strong>Instructor and E-Mentor<\/strong><\/p>\n<ul>\n<li>IoT<\/li>\n<li>PIC Microcontrollers<\/li>\n<li>Arduino<\/li>\n<li>Raspberry Pi<\/li>\n<li>Espressif<\/li>\n<li>Robotics<\/li>\n<\/ul>\n<p><strong>Follow Us<\/strong><\/p>\n<p><strong>Luc Paquin \u2013 Curriculum Vitae &#8211; 2023<\/strong><br \/>\nhttps:\/\/www.donluc.com\/luc\/<\/p>\n<p><strong>Web:<\/strong> https:\/\/www.donluc.com\/<br \/>\n<strong>Facebook:<\/strong> https:\/\/www.facebook.com\/neosteam.labs.9\/<br \/>\n<strong>YouTube:<\/strong> https:\/\/www.youtube.com\/channel\/UC5eRjrGn1CqkkGfZy0jxEdA<br \/>\n<strong>Twitter:<\/strong> https:\/\/twitter.com\/labs_steam<br \/>\n<strong>Pinterest:<\/strong> https:\/\/www.pinterest.com\/NeoSteamLabs\/<br \/>\n<strong>Instagram:<\/strong> https:\/\/www.instagram.com\/neosteamlabs\/<\/p>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212; #DonLucElectronics #DonLuc #SparkFunRedBoard #Movement #MPU9150 #9DOF #Quaternion #Magnetometer #Accelerometer #Gyroscope #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; Quaternion In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. Hamilton defined &#8230; <a title=\"Project #25 &#8211; Movement &#8211; Quaternion &#8211; Mk06\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=3283\" aria-label=\"Read more about Project #25 &#8211; Movement &#8211; Quaternion &#8211; Mk06\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[240,50,49,59,5,58,10,43],"tags":[251,6,102,4,19,85,252,246,24,249,9,27,255,109,33,34],"class_list":["post-3283","post","type-post","status-publish","format-standard","hentry","category-movement","category-arduino","category-consultant","category-fritzing","category-microcontrollers","category-arduino-programming","category-projects","category-sparkfun","tag-accelerometer","tag-arduino","tag-components","tag-consultant","tag-electronics","tag-fritzing","tag-gyroscope","tag-magnetometer","tag-microcontroller","tag-movement","tag-programming","tag-projects-2","tag-quaternion","tag-sparkfun","tag-technology","tag-video-blog"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3283"}],"version-history":[{"count":2,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3283\/revisions"}],"predecessor-version":[{"id":3289,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3283\/revisions\/3289"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}