Servo Motion control with MPU6050

Hi
Im trying to make a Servo Motion control with MPU6050 only using 2 axes, pitch and roll
but struggling a bit with the code can someone please assist

#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Servo.h"

MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
Servo servo1;
Servo servo2;


int va11;
int va12;

int  prevVa11;
int  prevVa12;


void setup()
{
Wire.begin() ;
Serial.begin(115200) ;
Serial.println("Initialize MPU") ;
mpu.initialize() ;
Serial.println(mpu. testConnection()  ?  "Connected"  :  "Connection failed") ;
servo1.attach(5) ;
servo2.attach(6) ;
}

void loop()
{
mpu.getMotion6 (&ax,  &ay,  &az,  &gx,  &gy,  &gz) ;
va11  =  map (ax,  -17000,  17000,  0,  179) ;
if  (va11  !=  prevVa11)
{
servo1.write (va11) ;
prevVa11  =  va11;
}
va12  =  map (ay,  -17000,  17000,  0,  179) ;
if  (va12  !=  prevVa12)
{
servo2.write (va12) ;
prevVa12  =  va12;
}
delay(500) ;
}

What does your code do now? What did you want it to do?

It will probably be worth putting some Serial,prints in to see what values you're getting for ax, ay, val1 and val2.

Steve

hi
I would like to use the MPU6050 to achieve pitch and roll and send the signal to two servo's

The code is giving me an error

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::I2Cdev()'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::I2Cdev()'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeBytes(unsigned char, unsigned char, unsigned char, unsigned char*)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeByte(unsigned char, unsigned char, unsigned char)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeWords(unsigned char, unsigned char, unsigned char, unsigned int*)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeWord(unsigned char, unsigned char, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readBytes(unsigned char, unsigned char, unsigned char, unsigned char*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readByte(unsigned char, unsigned char, unsigned char*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readBit(unsigned char, unsigned char, unsigned char, unsigned char*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readBits(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeBit(unsigned char, unsigned char, unsigned char, unsigned char)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readTimeout'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeBits(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readWords(unsigned char, unsigned char, unsigned char, unsigned int*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readWord(unsigned char, unsigned char, unsigned int*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readBitW(unsigned char, unsigned char, unsigned char, unsigned int*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::readBitsW(unsigned char, unsigned char, unsigned char, unsigned char, unsigned int*, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeBitW(unsigned char, unsigned char, unsigned char, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

/tmp/833046162/build/libraries/mpu6050_0_0_2/I2Cdev.cpp.o (symbol from plugin): In function `I2Cdev::I2Cdev()':

(.text+0x0): multiple definition of `I2Cdev::writeBitsW(unsigned char, unsigned char, unsigned char, unsigned char, unsigned int)'

/tmp/833046162/build/libraries/seeed_pca9685_0_0_1/I2Cdev.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2: error: ld returned 1 exit status

exit status 1

Try removing the line #include "I2Cdev.h".

Steve