So many errors after trying to inherit MPU6050 code example into my own class - OOP

Ok so basically I have an MPU6050 unit and I wanna use this exampe however I wanna turn it into a class with methods I can just call. As you can see theres already a class called MPU6050 but I wanna have that class include all these variables and have additional methods such as a setupMPU() method thats just

void MPU::setupMPU(){
    Wire.begin();
    Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
    
    Serial.begin(115200);
    while (!Serial); 
    
    // initialize device
    Serial.println(F("Initializing I2C devices..."));
    initialize();

    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

    // wait for ready
    Serial.println(F("\nSend any character to begin DMP programming and demo: "));
    while (Serial.available() && Serial.read()); // empty buffer
    while (!Serial.available());                 // wait for data
    while (Serial.available() && Serial.read()); // empty buffer again

    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
    devStatus = dmpInitialize();

    // supply your own gyro offsets here, scaled for min sensitivity
    setXGyroOffset(220);
    setYGyroOffset(76);
    setZGyroOffset(-85);
    setZAccelOffset(1788); // 1688 factory default for my test chip

    // make sure it worked (returns 0 if so)
    if (devStatus == 0) {
        // Calibration Time: generate offsets and calibrate our MPU6050
        CalibrateAccel(6);
        CalibrateGyro(6);
        PrintActiveOffsets();
        // turn on the DMP, now that it's ready
        Serial.println(F("Enabling DMP..."));
        setDMPEnabled(true);
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = dmpGetFIFOPacketSize();
    } else {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }
}

Trying to make my header file look look like this, notice that my class inherits from the main class

#ifndef MPU_H
#define MPU_H

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"
#include <Arduino.h>


class MPU : public MPU6050 {
  private:
    // 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
    VectorFloat gravity;    // [x, y, z]            gravity vector
    float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
    

  public:
    void setupMPU();  // Wakes up MPU and gets it ready for reading data.
    void setData();  // Sets yaw pitch and roll
};


#endif

However after doing this the code throws too many errors and most of them are like "this method was previously declared" kinda errors and I honestly have no clue why its like that. in my sketch i only include "mpu.h" which is my header file. All the other includes are in the header itself

D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:176:6: note: 'setExternalFrameSync' was previously declared here
 void MPU6050::setExternalFrameSync(uint8_t sync) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:176:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:460:14: warning: 'setDLPFMode' violates the C++ One Definition Rule  [-Wodr]
         void setDLPFMode(uint8_t bandwidth);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:219:6: note: implicit this pointer type mismatch
 void MPU6050::setDLPFMode(uint8_t mode) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:219:6: note: 'setDLPFMode' was previously declared here
 void MPU6050::setDLPFMode(uint8_t mode) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:219:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:464:14: warning: 'setFullScaleGyroRange' violates the C++ One Definition Rule  [-Wodr]
         void setFullScaleGyroRange(uint8_t range);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:254:6: note: implicit this pointer type mismatch
 void MPU6050::setFullScaleGyroRange(uint8_t range) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:254:6: note: 'setFullScaleGyroRange' was previously declared here
 void MPU6050::setFullScaleGyroRange(uint8_t range) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:254:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:816:14: warning: 'writeProgMemoryBlock' violates the C++ One Definition Rule  [-Wodr]
         bool writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0, bool verify=true);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3161:6: note: implicit this pointer type mismatch
 bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3161:6: note: 'writeProgMemoryBlock' was previously declared here
 bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3161:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:815:14: warning: 'writeMemoryBlock' violates the C++ One Definition Rule  [-Wodr]
         bool writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0, bool verify=true, bool useProgMem=false);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3085:6: note: implicit this pointer type mismatch
 bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3085:6: note: 'writeMemoryBlock' was previously declared here
 bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3085:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:823:14: warning: 'setDMPConfig1' violates the C++ One Definition Rule  [-Wodr]
         void setDMPConfig1(uint8_t config);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3250:6: note: implicit this pointer type mismatch
 void MPU6050::setDMPConfig1(uint8_t config) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3250:6: note: 'setDMPConfig1' was previously declared here
 void MPU6050::setDMPConfig1(uint8_t config) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3250:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:827:14: warning: 'setDMPConfig2' violates the C++ One Definition Rule  [-Wodr]
         void setDMPConfig2(uint8_t config);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3260:6: note: implicit this pointer type mismatch
 void MPU6050::setDMPConfig2(uint8_t config) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3260:6: note: 'setDMPConfig2' was previously declared here
 void MPU6050::setDMPConfig2(uint8_t config) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3260:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:734:14: warning: 'setOTPBankValid' violates the C++ One Definition Rule  [-Wodr]
         void setOTPBankValid(bool enabled);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2835:6: note: implicit this pointer type mismatch
 void MPU6050::setOTPBankValid(bool enabled) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2835:6: note: 'setOTPBankValid' was previously declared here
 void MPU6050::setOTPBankValid(bool enabled) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2835:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:497:14: warning: 'setMotionDetectionThreshold' violates the C++ One Definition Rule  [-Wodr]
         void setMotionDetectionThreshold(uint8_t threshold);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:532:6: note: implicit this pointer type mismatch
 void MPU6050::setMotionDetectionThreshold(uint8_t threshold) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:532:6: note: 'setMotionDetectionThreshold' was previously declared here
 void MPU6050::setMotionDetectionThreshold(uint8_t threshold) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:532:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:505:14: warning: 'setZeroMotionDetectionThreshold' violates the C++ One Definition Rule  [-Wodr]
         void setZeroMotionDetectionThreshold(uint8_t threshold);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:602:6: note: implicit this pointer type mismatch
 void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:602:6: note: 'setZeroMotionDetectionThreshold' was previously declared here
 void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:602:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:501:14: warning: 'setMotionDetectionDuration' violates the C++ One Definition Rule  [-Wodr]
         void setMotionDetectionDuration(uint8_t duration);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:562:6: note: implicit this pointer type mismatch
 void MPU6050::setMotionDetectionDuration(uint8_t duration) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:562:6: note: 'setMotionDetectionDuration' was previously declared here
 void MPU6050::setMotionDetectionDuration(uint8_t duration) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:562:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:509:14: warning: 'setZeroMotionDetectionDuration' violates the C++ One Definition Rule  [-Wodr]
         void setZeroMotionDetectionDuration(uint8_t duration);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:633:6: note: implicit this pointer type mismatch
 void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:633:6: note: 'setZeroMotionDetectionDuration' was previously declared here
 void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:633:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:682:14: warning: 'setFIFOEnabled' violates the C++ One Definition Rule  [-Wodr]
         void setFIFOEnabled(bool enabled);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2352:6: note: implicit this pointer type mismatch
 void MPU6050::setFIFOEnabled(bool enabled) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2352:6: note: 'setFIFOEnabled' was previously declared here
 void MPU6050::setFIFOEnabled(bool enabled) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2352:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:803:14: warning: 'resetDMP' violates the C++ One Definition Rule  [-Wodr]
         void resetDMP();
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3026:6: note: implicit this pointer type mismatch
 void MPU6050::resetDMP() {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3026:6: note: 'resetDMP' was previously declared here
 void MPU6050::resetDMP() {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3026:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:802:14: warning: 'setDMPEnabled' violates the C++ One Definition Rule  [-Wodr]
         void setDMPEnabled(bool enabled);
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3023:6: note: implicit this pointer type mismatch
 void MPU6050::setDMPEnabled(bool enabled) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3023:6: note: 'setDMPEnabled' was previously declared here
 void MPU6050::setDMPEnabled(bool enabled) {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:3023:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:686:14: warning: 'resetFIFO' violates the C++ One Definition Rule  [-Wodr]
         void resetFIFO();
              ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2392:6: note: implicit this pointer type mismatch
 void MPU6050::resetFIFO() {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2392:6: note: 'resetFIFO' was previously declared here
 void MPU6050::resetFIFO() {
      ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:2392:6: note: code may be misoptimized unless -fno-strict-aliasing is used
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:618:17: warning: 'getIntStatus' violates the C++ One Definition Rule  [-Wodr]
         uint8_t getIntStatus();
                 ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:1688:9: note: implicit this pointer type mismatch
 uint8_t MPU6050::getIntStatus() {
         ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.h:441:7: note: type 'struct MPU6050' itself violates the C++ One Definition Rule
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:441:7: note: the incompatible type is defined here
 class MPU6050 {
       ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:1688:9: note: 'getIntStatus' was previously declared here
 uint8_t MPU6050::getIntStatus() {
         ^
D:\Folders\Documents\Arduino\libraries\MPU6050\src\MPU6050.cpp:1688:9: note: code may be misoptimized unless -fno-strict-aliasing is used
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.


I realize now that most of these are warnings that i got when the example worked before without the OOP however theres an error at the end there not allowing me to complie which I didnt get before and I cant trace where it happens

Dont double post. Keep everything under the same discussion

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.