Compass Sensor Reading Not From 0-360 degree

I am using compass sensor in APM2 to measure the relative bearing to the waypoint. FYI, I am using compass_test.pde library to measure the angle of the compass. However, the reading is not from 0-360 degree as what I expected when I rotate my rover. It goes something like this; 20 - 80 degree, the value goes down when I turn over 270 degree.... In summary, it does not give the value similar from what I get if I am using compass sensor from my smartphone. Any idea why this is happening?

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

Join diydrones

Email me when people reply –

Replies

  • Hello Aizzat, Can I ask you do you have modified compass_test.pde library? I use the  compass_test.pde, then my compass result signal is from 0-65535(never have negative signal). It's look like the signal come from ADC directly, and more strange thing is it never show up the middle range signal like 400-65000. And interesting is when I use the compass test in APM2 CLI mode, it shows the signal seems alright. I saw all the AP_compass library and the test.pde(in CLI mode used) ,but I couldn't find any different between these two. Have you any idea what's going on?  Really thanks.  

    ps. I also have tried to change set_orientation.

  • My problem solved! What I do is just simply change the orientation of the compass sensor depending on how I place it on my rover. In arduino library, you can simply change it here:

    Simply change compass.set_orientation parameter inside:

    compass.set_orientation(AP_COMPASS_COMPONENTS_UP_PINS_FORWARD);  // set compass's orientation on aircraft.

    For list of parameters, you can find it here, in a file name AP_Compass_HMC5843.h in AP_Compass library:


    // orientations for DIYDrones magnetometer
    #define AP_COMPASS_COMPONENTS_UP_PINS_FORWARD ROTATION_NONE
    #define AP_COMPASS_COMPONENTS_UP_PINS_FORWARD_RIGHT ROTATION_YAW_45
    #define AP_COMPASS_COMPONENTS_UP_PINS_RIGHT ROTATION_YAW_90
    #define AP_COMPASS_COMPONENTS_UP_PINS_BACK_RIGHT ROTATION_YAW_135
    #define AP_COMPASS_COMPONENTS_UP_PINS_BACK ROTATION_YAW_180
    #define AP_COMPASS_COMPONENTS_UP_PINS_BACK_LEFT ROTATION_YAW_225
    #define AP_COMPASS_COMPONENTS_UP_PINS_LEFT ROTATION_YAW_270
    #define AP_COMPASS_COMPONENTS_UP_PINS_FORWARD_LEFT ROTATION_YAW_315
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_FORWARD ROTATION_ROLL_180
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_FORWARD_RIGHT ROTATION_ROLL_180_YAW_45
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_RIGHT ROTATION_ROLL_180_YAW_90
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_BACK_RIGHT ROTATION_ROLL_180_YAW_135
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_BACK ROTATION_PITCH_180
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_BACK_LEFT ROTATION_ROLL_180_YAW_225
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_LEFT ROTATION_ROLL_180_YAW_270
    #define AP_COMPASS_COMPONENTS_DOWN_PINS_FORWARD_LEFT ROTATION_ROLL_180_YAW_315
    #define AP_COMPASS_APM2_SHIELD ROTATION_NONE

    // orientations for Sparkfun magnetometer
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_FORWARD ROTATION_YAW_270
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_FORWARD_RIGHT ROTATION_YAW_315
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_RIGHT ROTATION_NONE
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_BACK_RIGHT ROTATION_YAW_45
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_BACK ROTATION_YAW_90
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_BACK_LEFT ROTATION_YAW_135
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_LEFT ROTATION_YAW_180
    #define AP_COMPASS_SPARKFUN_COMPONENTS_UP_PINS_FORWARD_LEFT ROTATION_YAW_225
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_FORWARD ROTATION_ROLL_180_YAW_90
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_FORWARD_RIGHT ROTATION_ROLL_180_YAW_135
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_RIGHT ROTATION_PITCH_180
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_BACK_RIGHT ROTATION_ROLL_180_YAW_225
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_BACK ROTATION_ROLL_180_YAW_270
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_BACK_LEFT ROTATION_ROLL_180_YAW_315
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_LEFT ROTATION_ROLL_180
    #define AP_COMPASS_SPARKFUN_COMPONENTS_DOWN_PINS_FORWARD_LEFT ROTATION_ROLL_180_YAW_45

  • Any library that i could use to calibrate it?
  • That's precisely what happens when the magnetometer isn't calibrated.

    Hard iron distortion creates an offset (bias, if you prefer) in the readings of each axis. The algorithm that computes compass direction expects there to be 0 bias. The result is that heading ranges between a narrow set of values.

    Simply calibrate the compass for hard iron distortion (I have no idea how one does this with APM2).

This reply was deleted.

Activity