I2Cdevlib Forums

# limon

Members

10

## Posts posted by limon

1. ### DMP polling (no interrupt/FIFO)

Limon, I can't exactly answer your PI equation, that part of the project is my group members' responsibility.

Our instructor has told us to use a PI controller for each motor independently.

If you look at a lot of the open source quadcopter projects, they implement a PID for roll/pitch/yaw and these correction values get put into a motor control loop.  The idea that our instructor wants us to implement is take the new motor values, as inputs to a motor PI loop using an RPM detection algorithm that we came up with.

Basically the following is comprised of PID for r p and y. Our goal is to add a PI at the end of the set of equations below to improve reaction time of the motors.

motorCommand[FRONT_LEFT]  = throttle - motorAxisCommandPitch + motorAxisCommandRoll - (YAW_DIRECTION * motorAxisCommandYaw);
motorCommand[FRONT_RIGHT] = throttle - motorAxisCommandPitch - motorAxisCommandRoll + (YAW_DIRECTION * motorAxisCommandYaw);
motorCommand[REAR_RIGHT]  = throttle + motorAxisCommandPitch - motorAxisCommandRoll - (YAW_DIRECTION * motorAxisCommandYaw);
motorCommand[REAR_LEFT]   = throttle + motorAxisCommandPitch + motorAxisCommandRoll + (YAW_DIRECTION * motorAxisCommandYaw);

The equations you wrote here are clear for me. And how are you going to use PI controller at the end?

Am I right? :

for example you have calculated the new value for front left motor. His new rate shoul be 1500 (motorCommand[FRONT_LEFT]). Now he has rate of 1400 (oldRate[FRONT_LEFT]).

After this you are going to use PI controller instead of the direct setting motor rate:

motorCommand[FRONT_LEFT] = .........; //1500

front_left_motor.setRate(motorCommand[FRONT_LEFT]); //was

front_left_motor.setRate( pi_controller.update(motorCommand[FRONT_LEFT] - oldValue[FRONT_LEFT], deltaTime)  );

Something like that? If no, please explain to me, it is vefy interesting :-)

2. ### Arduino, DMP example with delay(6) at loop hangs

Is your DMP working at 100Hz or 200Hz?

I did not touched anything in the libs, so I think it works at 100Hz.

Every loop (if I delete my delay(6)) takes about 10 msecs.

3. ### Arduino, DMP example with delay(6) at loop hangs

Hi to all again!

It semms I fixed this "bug". But there is no understanding of the reason:

old:

```        // read a packet from FIFO
mpu.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;
```

new:

```    while (fifoCount >= packetSize){
// read a packet from FIFO
mpu.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;
}
```

now, I never see fifo overflows at all. Program never hangs. But... why it hanged??? I'v spend 5 hours of "debugging" and testing...

4. ### Arduino, DMP example with delay(6) at loop hangs

Hello!

I am kindly asking for help with my small question:

I am writing some algorithm, which must work one time in one loop iteration. It takes him ~ 5-7 msec to proceed every loop().

I noticed, that my program hangs sometimes. Very rarely: ~ after 10 - 30 minutes of working.

Than I went to DMP example, added delay(6) at the end of a loop.... And the same result: sometimes it hangs (after 10 - 30 minutes of working).

I added Serial.println in the loop, where the program waits for interrupt, because it is the only one loop. Like this:

```    while (!mpuInterrupt && fifoCount < packetSize) {
Serial.println("Waiting...");
}
```

And there is no "Waiting..." messages, when it hangs.

Here is a full code of "my" MPU DMP example. It is the same as standart exampe, except two of three lines. I also added the loop period counting and printed it with YPR data.

Also I tried it with two different MPU-6050...

Sory for my English :-)

5. ### DMP polling (no interrupt/FIFO)

Hello, edorphy!

I understand, why do you need PID contollers to control pitch and roll. But why do you need PI controller? Could you explain please in a simple way? :-)

6. ### Why should I wait for MPU interrupt (sometimes very long!!!)

Well, if it works for you... then I guess you can read it using (mpu.dmpGetXXXXXXXX) every time you want, but be sure to read it at a faster frecuency than DMP is running, or fifo will overflow.

Anyway, I haven't checked how does this (mpu.dmpGetXXXXXXXX) function work, so I am only speculating.

Besides, this long wait you mention has never happened to me. Are you sure that INT pin is connected where it should be connected?

Here is how I connected MPU to my Arduino UNO:

Is it right?

And what frequency has DMP?

7. ### Why should I wait for MPU interrupt (sometimes very long!!!)

Hello all!

I am running MPU 6050 example.

Every time after burning arduino i see this in the com port monitor:

Initializing I2C devices...

Testing device connections...
MPU6050 connection successful

Send any character to begin DMP programming and demo:
Initializing DMP...
Enabling DMP...
Enabling interrupt detection (Arduino external interrupt 0)...
DMP ready! Waiting for first interrupt...

And this waiting can last VERY long...

When I delete this while loop:

```    while (!mpuInterrupt && fifoCount < packetSize) {
// other program behavior stuff here
// .
// .
// .
// if you are really paranoid you can frequently test in between other
// stuff to see if mpuInterrupt is true, and if so, "break;" from the
// while() loop to immediately process the MPU data
// .
// .
// .
}
```

Everything works OK... No waiting at all, and I see data immediately.

This is the question. Must I wait for interrupt or I can read data from MPU (mpu.dmpGetXXXXXXXX) every time I need?

8. ### Arduino. Multiple definition of some function MPU6050::XXXXXX

Maybe, instead of putting the includes in sensor.h, try to put them all in sensor.cpp

Put all the includes in the arduino project, not in sensor.h. Its only 2 or 3 lines...

I tried to do this, and had another error in Sensor.h:

sensor.h:18: error: 'MPU6050' does not name a type

Because sensor.h don't know about MPU libraries...

In sensor.cpp, you are including sensor.h, is it necessary? I mean, you are including it from the arduino project and from that file, maybe that's the cause?

As I understand, if I write a class A, i should create two files: A.h & A.cpp. A.cpp must include A.h...

Anyway, if I comment the string #include "sensor.h" in sensor.cpp, i get this errors:

sensor.cpp:4: error: 'Sensor' has not been declared

Btw you can download my test project and compile it with different includes...

Thank you for your help and suggestions!!!

9. ### PID

Hello, Diego!

Here you can find one of the PID realizations
https://github.com/MegaPirateNG/ardupilot-mpng/tree/mpng-3.0.1-r3/libraries/AC_PID

also, there is a storing PID values to the EEPROM, but you can delete it :-)

And filtering... There is no need to use only Kalman.

Here you can find some other filters
https://github.com/MegaPirateNG/ardupilot-mpng/tree/mpng-3.0.1-r3/libraries/Filter

Hope it helps you.

Maybe you can help me with my noobish question?
http://www.i2cdevlib.com/forums/topic/110-arduino-multiple-definition-of-some-function-mpu6050xxxxxx/

Because my math is OK. But my skill in Arduino is poor :-)

10. ### Arduino. Multiple definition of some function MPU6050::XXXXXX

Hello, dear pro MPU users! :-)

I have no problem to compile the example for Arduino. This is good :-)

But I can't move all the initializations and all the serial output into new class, I called Sensor.

I'v created Sensor.h, Sensor.cpp

In the sensor.h:

```#ifndef SENSOR_H
#define SENSOR_H

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050.h" // not necessary if using MotionApps include file
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif

class Sensor{
public:
static Sensor & getInstance(){
static Sensor instance;
return instance;
}

bool init();

bool getYpr(float & y, float & p, float r);

protected:
MPU6050 _mpu;
..................................
......................
...........

```
In the main project:
```#include "Wire.h"
#include "sensor.h"

void setup() {
Sensor::getInstance().init();
}

void loop() {
float y,p,r;
Sensor::getInstance().getYpr(y,p,r);
}

```

And I have a lot of errors like this:

testMPU.cpp.o: In function `MPU6050::dmpGetAccel(long*, unsigned char const*)':

/MPU6050_6Axis_MotionApps20.h:533: multiple definition of `MPU6050::dmpGetAccel(long*, unsigned char const*)'
sensor.cpp.o:/MPU6050_6Axis_MotionApps20.h:533: first defined here
.............

I'v found some information, that this may be caused by including "MPU6050.h", but I don't do it!

I can't attach archives here. So, here is a link to a dropbox with my test project:

https://dl.dropboxusercontent.com/u/51786067/testMPU.rar

Hope, my question is not very stupid :-)
Thanks!

×