Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An Arduino R3 is being used to collect IMU data from the MPU6050 sensor which is further sent to unity as Quaternion coordinates . As

An Arduino R3 is being used to collect IMU data from the MPU6050 sensor which is further sent to unity as Quaternion coordinates . As wireless connectivity is needed, this has been upgraded to the Arduino 33 IoT which uses the LSM6DS3 sensor onboard. Please alter the the code below to send the IMU data from the new board and sensor to Unity in Quaterion coordinates format.

[Using - Uduino Unity asset, I2cDev , MPU5060 library]

image text in transcribed

#include "Uduino.h" // Include Uduino library at the top of the sketch Uduino uduino("IMU");

#include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" #include "Wire.h"

MPU6050 mpu;

// MPU control/status vars bool dmpReady = false; // set true if DMP init was successful uint8_t devStatus; // return status after each device operation (0 = success, !0 = error) uint16_t packetSize; // expected DMP packet size (default is 42 bytes) uint16_t fifoCount; // count of all bytes currently in FIFO uint8_t fifoBuffer[64]; // FIFO storage buffer

// orientation/motion vars Quaternion q; // [w, x, y, z] quaternion container VectorInt16 aa; // [x, y, z] accel sensor measurements VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements VectorFloat gravity; // [x, y, z] gravity vector float euler[3]; // [psi, theta, phi] Euler angle container float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector

void setup() { Wire.begin(); Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties

Serial.begin(38400);

while (!Serial); // wait for Leonardo enumeration, others continue immediately

mpu.initialize(); devStatus = mpu.dmpInitialize(); mpu.setXGyroOffset(54); //++ mpu.setYGyroOffset(-21); //-- mpu.setZGyroOffset(5);

if (devStatus == 0) { mpu.setDMPEnabled(true); // set our DMP Ready flag so the main loop() function knows it's okay to use it dmpReady = true; // get expected DMP packet size for later comparison packetSize = mpu.dmpGetFIFOPacketSize(); } else { // Error Serial.println("Error!"); } }

void loop() { uduino.update();

if (uduino.isInit()) { if (!dmpReady) { Serial.println("IMU not connected."); delay(10); return; }

int mpuIntStatus = mpu.getIntStatus(); fifoCount = mpu.getFIFOCount();

if ((mpuIntStatus & 0x10) || fifoCount == 1024) { // check if overflow mpu.resetFIFO(); } else if (mpuIntStatus & 0x02) { while (fifoCount

mpu.getFIFOBytes(fifoBuffer, packetSize); fifoCount -= packetSize;

SendQuaternion(); //SendEuler(); //SendYawPitchRoll(); //SendRealAccel(); //SendWorldAccel(); } } }

void SendQuaternion() { mpu.dmpGetQuaternion(&q, fifoBuffer); Serial.print("r/"); Serial.print(q.w, 4); Serial.print("/"); Serial.print(q.x, 4); Serial.print("/"); Serial.print(q.y, 4); Serial.print("/"); Serial.println(q.z, 4); }

BERK DE . 2 A D # N Ito Sih

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions