Leaderboard
Popular Content
Showing content with the highest reputation on 05/27/2015 in Posts
-
velocity from acceleration
Johnnydofs reacted to hatt0002 for a topic
Hi, I am currently doing a project in which I need to capture the acceleration of a pivoted rotating wooden beam. From the acceleration, I need to determine the velocity. I am using Jeff's teapot sketch with the mpu6050 and I have managed to also include the acceleration in the teapotPacket to print acceleration in processing. I know that velocity is the first integral of acceleration. Such integral can be expressed as: v = u + AT, where v is the current velocity, u is the velocity before, A is the acceleration and T is a time interval. This is my code for the velocities in the three directions with sampling time of 1ms: vX = uX + (AX)*0.001; //vX = current velocity in the X direction, uX = velocity in the previous iteration, AX = acceleration in the x direc uX = vX; //setting the current velocity as the previous velocity vY = uY + (AY)*0.001; uY = vY; vZ = uZ + (AZ)*0.001; uZ = vZ; If I move the sensor say in the x direction, acceleration in the x direction increases and when I stop the sensor, acceleration becomes negative and converges to zero, as expected. The velocity seems to be calculated and printed right when increasing from zero to a particular value. Now my problem is, that when I stop moving the sensor, velocity does not go back to zero when the sensor is stationary, but it decreases by a small amount only (say it stops decreasing at 0.5m/s. This gets worse when the sensor is moved faster. It seems like the acceleration is read more than the deceleration (decreasing acceleration) and therefore, less negative values for acceleration are captured. Can anybody help me? Thanks, Hatt1 point -
Sketch hanging when interrupt routine called [MPU6050]
Johnnydofs reacted to AlexGodbehere for a topic
Hi all. I'm using an MPU6050 to obtain orientation information for a quadcopter, however when the function that is attached to the interrupt pin is ran (to obtain the orientation data from the FIFO buffer), the sketch crashes. Sometimes, the console prints the first few characters of "Getting Sensor Data!", which is called in the routine. Am I doing anything seriously wrong? Main Sketch: Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)...")); attachInterrupt(0, AP_getSensorData, RISING); // Actually pin 2-(5?) AP_Sensors.cpp: // Library header #include "Sensors_.h" #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" #include "Serial_.h" #include <SFE_BMP180.h> #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif /************************************** * LED DEFINITIONS *************************************/ #define LED_GREEN 9 #define LED_YELLOW 10 #define LED_YELLOW2 11 #define LED_YELLOW3 12 #define LED_RED 13 // Code MPU6050 onboardIMU; extern bool systemError; int ultrasonicAlt; // MPU control/status vars bool dmpReady = false; // set true if DMP init was successful uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU 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 byte error, address; int nDevices; // ================================================================ // === INTERRUPT DETECTION ROUTINE === // ================================================================ volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } bool AP_initSensors() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz) #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif /************************************** * Scan for I2C Devices *************************************/ Serial.println("Scanning I2C Bus..."); nDevices = 0; for (address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); nDevices++; } else if (error == 4) { Serial.print("Unknow error at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("Completed I2C Bus Scan...\n"); Serial.println("Initalising I2C Devices..."); onboardIMU.setSleepEnabled(false); onboardIMU.initialize(); // Try to connect to IMU Devices... Serial.println("Connecting to I2C Devices..."); if (onboardIMU.testConnection()) { Serial.println("IMU Connected!:"); // load and configure the DMP Serial.println(F("Initializing DMP...")); devStatus = onboardIMU.dmpInitialize(); // supply your own gyro offsets here, scaled for min sensitivity onboardIMU.setXGyroOffset(220); onboardIMU.setYGyroOffset(76); onboardIMU.setZGyroOffset(-85); onboardIMU.setZAccelOffset(1788); // 1688 factory default for my test chip // make sure it worked (returns 0 if so) if (devStatus == 0) { // turn on the DMP, now that it's ready Serial.println(F("Enabling DMP...")); onboardIMU.setDMPEnabled(true); // enable Arduino interrupt detection // Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)...")); // attachInterrupt(0, dmpDataReady, RISING); mpuIntStatus = onboardIMU.getIntStatus(); // set our DMP Ready flag so the main loop() function knows it's okay to use it Serial.println(F("DMP ready! Waiting for first interrupt...")); dmpReady = true; // get expected DMP packet size for later comparison packetSize = onboardIMU.dmpGetFIFOPacketSize(); } else { // ERROR! // 1 = initial memory load failed // 2 = DMP configuration updates failed // (if it's going to break, usually the code will be 1) Serial.print(F("DMP Initialization failed (code ")); Serial.print(devStatus); Serial.println(F(")")); } } else { Serial.println("Unable to find any I2C Devices..."); } Serial.println("Initialising Barometric Sensor..."); AP_initBarometricSensor(); } void AP_getSensorData() { Serial.println("Getting Sensor Data!"); // reset interrupt flag and get INT_STATUS byte mpuInterrupt = false; mpuIntStatus = onboardIMU.getIntStatus(); // get current FIFO count fifoCount = onboardIMU.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if ((mpuIntStatus & 0x10) || fifoCount == 1024) { // reset so we can continue cleanly onboardIMU.resetFIFO(); Serial.println(F("FIFO overflow!")); // otherwise, check for DMP data ready interrupt (this should happen frequently) } else if (mpuIntStatus & 0x02) { // wait for correct available data length, should be a VERY short wait while (fifoCount < packetSize) fifoCount = onboardIMU.getFIFOCount(); // read a packet from FIFO onboardIMU.getFIFOBytes(fifoBuffer, packetSize); // track FIFO count here in case there is > 1 packet available // (this lets us immediately read more without waiting for an interrupt) fifoCount -= packetSize; onboardIMU.dmpGetQuaternion(&q, fifoBuffer); onboardIMU.dmpGetGravity(&gravity, &q); onboardIMU.dmpGetYawPitchRoll(ypr, &q, &gravity); } }1 point -
Is there a way to disable gyroscope drift compensation?
Johnnydofs reacted to sharst for a topic
Hello, I'm using I2Cdevlib to read out the fused DMP data from an MPU-6050 breakout board, and I'm absolutely amazed at the amount of precision I get from such a low-cost sensor! I've got one problem though: I attached the sensor to a mobile robot, which sometimes moves in large circles, i.e. the gyroscope will register the same small turn velocity over a long period of time. During these periods, after ~8 seconds the yaw reading of the sensor stabilizes at some point and I don't get rotation updates anymore. From what I gathered from other posts, I assume that the DMP tries to cancel out gyro drift by subtracting any constant gyro reading that it gets from the next readings. I guess what happens is that the DMP thinks my slowly moving robot is actually the gyroscope drifting and tries to compensate. (I can actually see the yaw moving in the opposite direction for a short while when I stop the robot mid-turn.) So my question is: Is there some way I can turn off gyro drift compensation in the DMP? I can take care of slow drifts myself by measuring the gyro drift when I'm completely sure that the robot isn't moving. It would be a pity if I couldn't use this great sensor and library because I can't disable this feature. Thanks a lot for your responses, Simon1 point