i2c-gps-nav Sonar Support - Code included

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
snowzach
Posts: 8
Joined: Mon Jul 16, 2012 4:19 pm

i2c-gps-nav Sonar Support - Code included

Post by snowzach »

I was tinkering with the code today and added the remaining code to support Sonar from the i2c-gps-nav "coprocessor". Works well for me.

If someone that has access wants to review and commit it, that'd be swell... This is based off of the most current version of i2c-gps-nav. I've added a few line on each of them for context. Hopefully this is easy to understand.

config.h approx line 656 (Will assume we want disabled by default for most folks)

Code: Select all

    /* I2C GPS device made with an independant arduino + GPS device
       including some navigation functions
       contribution from EOSBandi   http://code.google.com/p/i2c-gps-nav/
       You have to use at least I2CGpsNav code r33 */
    //#define I2C_GPS
    // If your I2C GPS board has Sonar support enabled
    //#define I2C_GPS_SONAR


def.h approx line 1451

Code: Select all

#if defined(SRF02) || defined(SRF08) || defined(SRF10) || defined(SRC235) || defined(TINY_GPS_SONAR) || defined(I2C_GPS_SONAR)
  #define SONAR 1
#else
  #define SONAR 0
#endif


def.h approx line 1683

Code: Select all

#define I2C_GPS_WP13                                206
#define I2C_GPS_WP14                                217
#define I2C_GPS_WP15                                228

#define I2C_GPS_SONAR_ALT                       239
///////////////////////////////////////////////////////////////////////////////////////////////////
// End register definition
///////////////////////////////////////////////////////////////////////////////////////////////////


GPS approx line 399

Code: Select all

        //GPS_ground_course
        varptr = (uint8_t *)&GPS_ground_course;
        *varptr++ = i2c_readAck();
        *varptr   = i2c_readNak();

#if defined(I2C_GPS_SONAR)
        i2c_rep_start(I2C_GPS_ADDRESS<<1);
        i2c_write(I2C_GPS_SONAR_ALT);         
        i2c_rep_start((I2C_GPS_ADDRESS<<1)|1);

        varptr = (uint8_t *)&sonarAlt;          // altitude (in cm? maybe)
        *varptr++ = i2c_readAck();
        *varptr   = i2c_readNak();
#endif

        if (!f.GPS_FIX_HOME) {     //If we don't have home set, do not display anything
          GPS_distanceToHome = 0;
          GPS_directionToHome = 0;
        }
Last edited by snowzach on Wed Apr 24, 2013 10:55 pm, edited 2 times in total.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: i2c-gps-nav Sonar Support - Code included

Post by EOSBandi »

Thanks a lot,
I'm so swamped, that sometimes elementary things left out... I'll commit it to _shared.
Regards,
EOS

snowzach
Posts: 8
Joined: Mon Jul 16, 2012 4:19 pm

Re: i2c-gps-nav Sonar Support - Code included

Post by snowzach »

BAHhhhh... Sorry sorry... I just realized a typo... The second i2c_readAck() should have been a i2c_readNak() otherwise it may cause problems...

I revised my post above... This is the section I changed if you already committed it.

Code: Select all

        //GPS_ground_course
        varptr = (uint8_t *)&GPS_ground_course;
        *varptr++ = i2c_readAck();
        *varptr   = i2c_readNak();

#if defined(I2C_GPS_SONAR)
        i2c_rep_start(I2C_GPS_ADDRESS<<1);
        i2c_write(I2C_GPS_SONAR_ALT);         
        i2c_rep_start((I2C_GPS_ADDRESS<<1)|1);

        varptr = (uint8_t *)&sonarAlt;          // altitude (in cm? maybe)
        *varptr++ = i2c_readAck();
        *varptr   = i2c_readNak();
#endif

Mazz1
Posts: 3
Joined: Sat Jun 15, 2013 9:19 pm

Re: i2c-gps-nav Sonar Support - Code included

Post by Mazz1 »

Hello! is this working for altitude hold with sonar? i try it but i cant make it work.
Thank you !!

Mazz1
Posts: 3
Joined: Sat Jun 15, 2013 9:19 pm

Re: i2c-gps-nav Sonar Support - Code included

Post by Mazz1 »

Mazz1 wrote:Hello! is this working for altitude hold with sonar? i try it but i cant make it work.
Thank you !!


Im sorry, this is not the right place to ask. :roll:

Post Reply