Can't find source of this error

Hello!

I'm getting an error when I try to compile my code:

RadioReceiverPCB_with_MPU_6050:650: error: 'MPU_DATA' was not declared in this scope
RadioReceiverPCB_with_MPU_6050:650: error: 'data' was not declared in this scope
RadioReceiverPCB_with_MPU_6050:651: error: 'controlState' was not declared in this scope
RadioReceiverPCB_with_MPU_6050:651: error: 'data' was not declared in this scope
RadioReceiverPCB_with_MPU_6050.ino: In function 'void loop()':
RadioReceiverPCB_with_MPU_6050:757: error: 'getRadioInput' cannot be used as a function
RadioReceiverPCB_with_MPU_6050:758: error: 'getMPU_Data' cannot be used as a function
RadioReceiverPCB_with_MPU_6050.ino: In function 'int getMPU_Data(MPU_DATA*)':
RadioReceiverPCB_with_MPU_6050:782: error: 'int getMPU_Data(MPU_DATA*)' redeclared as different kind of symbol
RadioReceiverPCB_with_MPU_6050:650: error: previous declaration of 'int getMPU_Data'
RadioReceiverPCB_with_MPU_6050:798: error: request for member 'aX' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:799: error: request for member 'aY' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:800: error: request for member 'aZ' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:802: error: request for member 'gX' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:803: error: request for member 'gY' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:804: error: request for member 'gZ' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:804: error: 'struct accel_t_gyro_union::<anonymous>' has no member named 'Z_gyro'
RadioReceiverPCB_with_MPU_6050.ino: In function 'int getRadioInput(controlState*)':
RadioReceiverPCB_with_MPU_6050:809: error: 'int getRadioInput(controlState*)' redeclared as different kind of symbol
RadioReceiverPCB_with_MPU_6050:651: error: previous declaration of 'int getRadioInput'
RadioReceiverPCB_with_MPU_6050:813: error: request for member 'check' in 'data', which is of non-class type 'controlState*'

Why isn't MPU_DATA declared?

I will attach my code, since it's probably to big to post.

RadioReceiverPCB_with_MPU_6050.ino (31.3 KB)

The problem here is that of the Arduino IDE being stupid.

One of the first things it does when compiling is to scan your code and build up a list of function prototypes. These are placed near the top of your program. It allows you to be lazy and define your functions in any order.

The problem one is this:

int getMPU_Data(MPU_DATA *data);

This is placed in your code, by the IDE, before the MPU_DATA structure has been defined, and so it doesn't know what it is.

The simple answer is to place all your #defines, structs, and typedefs into a header file and include it at the top of your program with all the others #includes. The prototypes are placed after the includes, so it should know about your typedefs by then.

Thanks for the reply!

However, while this removed the other error, I now get this instead:

RadioReceiverDefine.h:616: error: 'byte' does not name a type
RadioReceiverDefine.h:632: error: 'uint8_t' does not name a type

From some googling I found that putting the #include for my header file last of my includes removed this problem, though giving me another problem:

RadioReceiverPCB_with_MPU_6050.ino: In function 'int getMPU_Data(MPU_DATA*)':
RadioReceiverPCB_with_MPU_6050:154: error: request for member 'aX' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:155: error: request for member 'aY' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:156: error: request for member 'aZ' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:158: error: request for member 'gX' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:159: error: request for member 'gY' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:160: error: request for member 'gZ' in 'data', which is of non-class type 'MPU_DATA*'
RadioReceiverPCB_with_MPU_6050:160: error: 'struct accel_t_gyro_union::<anonymous>' has no member named 'Z_gyro'
RadioReceiverPCB_with_MPU_6050.ino: In function 'int getRadioInput(controlState*)':
RadioReceiverPCB_with_MPU_6050:169: error: request for member 'check' in 'data', which is of non-class type 'controlState*'

That's because when you're working with a pointer you must use the -> syntax not the . syntax:

data->aX = accel_t_gyro.value.x_accel;
data->aY = accel_t_gyro.value.y_accel;
data->aZ = accel_t_gyro.value.z_accel;
... etc ...