Problem compiling APM_Compass_Test

referring to the ArduCoper Wiki under the section Optional Magnetometer i an trying to compile the suggested test sketch called APM_Compass_Test.pde.

I get the following error :-
APM_Compass_test.cpp:13:37: error: AP_Math.h: No such file or directory
APM_Compass_test.cpp: In function 'void setup()':
APM_Compass_test:26: error: 'class APM_Compass_Class' has no member named 'SetOrientation'
APM_Compass_test:26: error: 'APM_COMPASS_COMPONENTS_UP_PINS_FORWARD' was not declared in this scope
APM_Compass_test:27: error: 'class APM_Compass_Class' has no member named 'SetOffsets'
APM_Compass_test:28: error: 'class APM_Compass_Class' has no member named 'SetDeclination'
APM_Compass_test.cpp: At global scope:
APM_Compass_test_orig:10: error: redefinition of 'long unsigned int timer'
APM_Compass_test:17: error: 'long unsigned int timer' previously declared here
APM_Compass_test.cpp: In function 'void setup()':
APM_Compass_test_orig:12: error: redefinition of 'void setup()'
APM_Compass_test:20: error: 'void setup()' previously defined here
APM_Compass_test.cpp: In function 'void loop()':
APM_Compass_test_orig:21: error: redefinition of 'void loop()'
APM_Compass_test:34: error: 'void loop()' previously defined here

I have had no problems compiling and uploading flight software to my working quad but now i am playing around with the DIYDrones magnetometer i have fitted.

Any help would be greatly appreciated.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • Yes and thanks for the response. I am looking at the Heli and I am glad you had responded.You would not believe the devilishly weird includes I was thinking of adding. LOL
  • The Heli.h still seems to have a reference to APM_Compass.h

    In file included from ArducopterNG.cpp:216:
    /Heli.h:45:89: error: APM_Compass.h: No such file or directory  Since the library is not included with the RC2 It does not compile.

  • Hey Randy,
    That makes perfect sense thankyou. Unfortunately my magnetometer worked today once with the compass test sketch but then it stop showing changing numbers and a reboot did not fix it, i wasnt 100% happy about the voltage change soldering i had done so i opted to cut it off and use the sparkfun one with a voltage modifier.

    One question tho, now that i have to fix the mag. to the frame can you offer any advice as to its orientation, it looks like y should be place in the same plane as the APM and to confirm are the GPS plugs at the front i.e. mag. y axis should point towards the gps plugs end of the APM. Can it be mounted anywhere on the frame or sould it be near the pivot point of the quad??
  • Hi Randy,
    Thanks for the information.
    Heres the thing, say i point the end of the board north and see y go to 500 and 180 degrees y goes to -500 that i understand. Are you saying that were ever i choose to stop rotating and put the board down the y number should be between -100 and 100. So i could be -5 and i could use that as a number but equally it could be 54 depending on where i stop the rotation and note the numbers, this doesn;t sound very accurate or am i missing the bigger picture here :).
  • Cheers Sebastian,
    Is it right tho that the numbers go up and down?? Have i got to try and make a note of the biggest in each axis (im assume thats what the 3 offsets refer to)??
  • my arduino ide lives in the arducopter directory:

    the libraries do point to:

    use subversion for checkout.
    can you follow this?
  • Ok.
    I used tortoise to download the whole svn from
    and set arduino preferences to the dir that contains arducopter, arducopterNG and libraries and then open the APM_Compass_Test from within the libraries folder and hey all compiled ok and magnetometer readings look clear now.
    Do i just keep spinning the quad in 3d until i get the biggest numbers in the offset or do i have to specifically start the program with the board facing north not too clear on the instructions there.
    Again thanks for any help on this.
  • Thanks Robert.
    The doesn't contain a library called AP_Math or a file called AP_Math so where should the build come from to get the APM_Compass_Test from the wiki working??
    Should it be from the trunk under Auducopter??
  • ok got a bit further. I had renamed the old APM_Compass_Test.pde to APM_Compass_Test_orig.pde and also saved APM_Compass_Test.pde in this directory so in effect i had 2 .pde files seems the compiler is very fussy about this.

    I now get the following error only :-
    APM_Compass_test.cpp.o:(.bss.APM_Compass+0x0): multiple definition of `APM_Compass'
    APM_Compass\APM_Compass.cpp.o:C:\Arducopter\arduino\libraries\APM_Compass/APM_Compass.cpp:57: first defined here

    Where am i supposed to put the file downloaded from the Wiki cos i have tried it everywhere.
    When i load the alpha flight code i see the arduino program has pulled in all the libraries to and i can see them as tabs at the top but when i load the APM_Compass_Test.pde i see no libraries included at the top.
    I thought i understood this Arduino environment but totally confused now :(
    Any help please.
  • do a search for AP_Math.h in your arduino directory.
    if it's not there, then you have an incomplete installation.

This reply was deleted.


Chris Anderson liked Zara Mae Pickering's profile
May 21
Azjeg liked Azjeg's profile
Apr 27
Benewake LiDAR liked Benewake LiDAR's profile
Apr 12
Gremsy liked Gremsy's profile
Mar 12