Shop OBEX P1 Docs P2 Docs Learn Events
ObEx V2Xe Compass code has a bug — Parallax Forums

ObEx V2Xe Compass code has a bug

bulkheadbulkhead Posts: 405
edited 2008-12-24 22:01 in Propeller 1
The V2Xe object here: obex.parallax.com/objects/157/ has a bug with the float to integer conversion that causes it to give the incorrect compass angle (0 to 359) for 5 angles (out of the 360). This bug was extremely hard to find (because it only appeared to affect 5 angles). I've attached a working version of the code which just uses
FloatMath.spin

to do the conversion instead (the original code is commented out).

Could this file be uploaded onto the ObEx to replace the original? I'm sure it would save someone a lot of time in the future.

Also, it seems like it would be a good idea for users to be able to "subscribe" to certain objects so they can be notified when newer versions come out. In this case, some of the users who made up the 271 downloads of the object may need their compasses to be able to report those extra 5 angles.

Search keywords: V2XE V2XE_Cog_1.0.spin digital compass modulue vector 2xe
Also, note to prospective users: this object requires 2 cogs and isn't optimized at all, but it does work. www.sparkfun.com/commerce/product_info.php?products_id=236

Post Edited (bulkhead) : 12/24/2008 9:17:02 PM GMT

Comments

  • JonathanJonathan Posts: 1,023
    edited 2008-12-24 19:07
    Bulkhead,

    It is I who am responsible for the bug. I'll have to take a look and see if I posted the proper version, as I had many attempts at the math, or if my final version was bugged too, which it prolly is.

    Can you tell me which 5 angles didn't work? Funny I never noticed it, but then if brains were lard I couldn't grease too big a pan, if you know what I mean.

    Many thanks for bringing this up, and if nothing else I assume I can modify and repost the working version, with credit to you for finding the bug. I'll try to fix the integer version, as I'd like it to work without needing the floatmath, but the integer version had me pulling out my hair.

    Sorry my bug stole some of your life! [noparse]:)[/noparse]

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • bulkheadbulkhead Posts: 405
    edited 2008-12-24 19:45
    Jonathan,

    Thanks for writing the code in the first place; even though I spent some time searching for the bug it has still saved me more time than writing my own object.

    Looking closer, the bug appears to be with the:
    if ( something > 128)
    


    it should be:
    if (something => 128)
    



    I think there are two lines that need to be fixed. I tested this afterwards and found that for some reason your conversion gives better data than the FloatMath.spin conversion does; I tried with both FRound() and FTrunc() too.
  • JonathanJonathan Posts: 1,023
    edited 2008-12-24 20:30
    Glad to hear that in spite of the bug it saved you some time! [noparse]:)[/noparse]

    I'll look into it tomorrow and let you know. Are you saying that you find no errors if the code is changed as above, or that you *think* that is the error? I wonder why it would work better without the floating math? I only avoided it to save a cog and make it a little faster.

    BTW, how do you like the compass? I like it a lot, however it does occasionally fail to calibrate correctly, and it can be quite sensitive to local magnetic interference. OTOH, it does better than advertised it terms of tilt error.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • bulkheadbulkhead Posts: 405
    edited 2008-12-24 21:13
    I tested it and that does fix the bug. I don't think FloatMath.spin requires an extra cog, but nevertheless, your float to int conversion (with "=> 128") appears to work slightly better.

    The compass does have more resolution than the Parallax one, but I think it may be affected by tilt more ( I haven't tested them side by side though, it just appears that way). I have noticed that occasionally on power on the compass will just return "0". I've found both compasses to be quite inaccurate for some reason, so I calibrate them manually using a protractor to take measurements and generate a lookup table in a spreadsheet. This inaccuracy may be due to local magnetic fields/ferromagnetic materials, but never the less, everything works out after using the lookup table.
  • JonathanJonathan Posts: 1,023
    edited 2008-12-24 22:01
    Bulkhead,

    I'm not where I can check, but I'm getting the feeling that somehow that bug snuck into the version I put on the OBEX, but that the one I am using for my 'bot is correct. I think I would ahve noticed, as I have played with the 'bot a lot. As soon as I can I'll check and repost to the OBEX. Is the code you posted up above the non buggy version?

    Have you looked at the "proper" way of calibrating the v2xe? Rotating it over 30 seconds or so? I have a routine for doing this if you want it. I just calibrate the 'bot whenever I am using it in a new location. It seems to correct for local conditions pretty well.

    I also have another routine for determining if it is faster to turn left or right to reach a desired heading if you would like it. Handy if you are guiding a 'bot using the compass.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Sign In or Register to comment.