SMALL - espritmodel.com SMALL - Telemetry SMALL - Radio
Reply
Thread Tools
Old Sep 11, 2013, 04:43 AM
Makers gonna make...
pawelsky's Avatar
Polska
Joined Jan 2012
1,949 Posts
Discussion
DJI NAZA GPS communication protocol - NazaDecoder Arduino library

I'm trying to understand how the communication protocol looks like between NAZA GPS and the flight controller.

From what I can see it is a serial communication at 115200 baud and that binary messages are sent in the following format:

55 AA XX YY <payload> ZZ ZZ

where XX is the length of the message, YY is the ID and ZZ ZZ seems to be checksum.

I can see that three types of messages are sent:
ID 10 which contains GPS data, sent every 250ms (refer to post #15 for more details)
ID 20 which contains compass data, sent every 30ms (refer to post #62 for more details)
ID 30 which contains GPS module version numbers, sent every 2s (refer to post#120 for more details)

If you know any more details - please share in this thread. I'll be updating this first post with new information.

Attached you will find the pinout. GND is the pin marked with 1 and a triangle (see yellow arrow on the picture).
Make sure you do the connection right or you will fry your GPS..

The connector is Molex SL Variant C (2.54 pitch). Variant G will work as well, after removing the clip with a sharp knife.

If you don't want to make the extension cable yourself you can contact irun4fundotca who offers them for $12 shipped anywhere (example picture attached)

Attached you will also find an Arduino library (called NazaDecoder) that contains functions for decoding data coming from Naza. Usage example and connection diagram can be found inside the library zip file.

The library gives you and option to disable attitude (pitch/roll) sensing (e.g. when you experience a conflict with another library that also uses the interrupt or on a board that does not support the interrupt used) by uncommenting the define in NazaDecoderLib.h file:
Code:
// Uncomment the line below if you want to disable attitude (pitch/roll) sensing. This may be useful when you experience a conflict with another library that also uses the interrupt
// or on a board that does not support the interrupt used. Note that for Teensy boards attitude sensing will be disabled by default.
#define ATTITUDE_SENSING_DISABLED
Note that for Teensy boards the attitude sensing is disabled by default regardless of whether the above define is commented out or not.

Using the NazaDecoder library I've prepared adapters for 2 popular OSDs
- RemzibiOSD
- MinimOSD

There are also external projects that use (modified versions) of this library:
- minnazaosd
- bagaosd
- nazatofrsky

NazaDecoder library changelog
------------------------------
Version 20141130
[FIX] added msgLen checking to protect against exceeding the message buffer (which could cause the decoder to stop working properly)
[FIX] changed the name of the message buffer from gpsPayload to payload as it is not only GPS related (cosmetic change)

Version 20141109
[NEW] added a define (ATTITUDE_SENSING_DISABLED) that allows disabling attitude (pitch/roll) sensing. This may be useful when you experience a conflict with another library that also uses the interrupt or on a board that does not support the interrupt used.
[NEW] attitude sensing is by default disabled for Teensy boards

Version 20140921
[FIX] fixed inverted east/west heading

Version 20140628
[NEW] added Vertical Speed Indicator (a.k.a. climb speed) and vdop
[NEW] speed is now reported in m/s instead of knots
[FIX] Corrected decoding of day number (note that for time between 16:00 and 23:59 the hour returned from GPS module is actually 00:00 - 7:59).
[NEW] aligned function names with NazaCanDecoder library (getAlt -> getGpsAlt, getVsi -> getGpsVsi, getHeading ->getHeadingNc) and updated the examples

Version 20140123
[NEW] added in-flight compass calibration. Do a full 360 degrees yaw while flying to calculate the calibration data.

Version 20140118
[NEW] added date and time
[FIX] corrected decoding of compass heading

Version 20131230
[NEW] added checksum checking to reject invalid data from GPS
[NEW] added course over ground and hdop
[NEW] added DGPS fix and fix type enum
[FIX] removed unused motorsArmed method from header
[FIX] corrected keywords file

Version 20131010
[FIX] corrected decoding of the fix type field (was not XORed with mask)

Version 20131009
initial version of the library
pawelsky is online now Find More Posts by pawelsky
Last edited by pawelsky; Nov 29, 2014 at 07:48 PM.
Reply With Quote
Sign up now
to remove ads between posts
Old Sep 13, 2013, 06:09 PM
SirEdward
blimppilot@ph's Avatar
Philippines, NCR, Pateros
Joined Apr 2004
677 Posts
subd
blimppilot@ph is offline Find More Posts by blimppilot@ph
Reply With Quote
Old Sep 16, 2013, 03:01 AM
Multicopter Nut
ThePara's Avatar
Romania, Bucharest
Joined Dec 2011
404 Posts
I have a malfunctioning Naza GPS unit on my bench now, but my dear friends at DJI elected to erase every marking on every chip, except for the HMC mag. I'm kind of poking in the dark there.
ThePara is offline Find More Posts by ThePara
Reply With Quote
Old Sep 16, 2013, 03:15 AM
Registered User
Frank.T's Avatar
Nederland, NH, Amsterdam
Joined Jul 2010
992 Posts
There are plenty pictures on the web where you can see the used GPS.
It is a ublox 6

Just google on Naza GPS
Frank.T is offline Find More Posts by Frank.T
Reply With Quote
Old Sep 25, 2013, 03:44 PM
Makers gonna make...
pawelsky's Avatar
Polska
Joined Jan 2012
1,949 Posts
Made some progress with decoding the Naza GPS messages and using an Arduino board I'm now able to display LAT, LON, altitude, number of satellites.
I think I'm also getting fix type, horizontal and vertical accuracy estimate, but I'm not that sure about these.
pawelsky is online now Find More Posts by pawelsky
Reply With Quote
Old Sep 25, 2013, 03:46 PM
Registered User
Frank.T's Avatar
Nederland, NH, Amsterdam
Joined Jul 2010
992 Posts
Great job! Keep us posted.
Frank.T is offline Find More Posts by Frank.T
Reply With Quote
Old Sep 25, 2013, 04:41 PM
Registered User
Joined Sep 2011
127 Posts
I think I've seen this application before, is it the UBlox centre application?

NAZA GPS HACK (0 min 47 sec)
DaveyWavey is offline Find More Posts by DaveyWavey
Reply With Quote
Old Sep 25, 2013, 04:46 PM
Makers gonna make...
pawelsky's Avatar
Polska
Joined Jan 2012
1,949 Posts
Quote:
Originally Posted by DaveyWavey View Post
I think I've seen this application before, is it the UBlox centre application?
Yes
pawelsky is online now Find More Posts by pawelsky
Reply With Quote
Old Sep 25, 2013, 06:59 PM
SirEdward
blimppilot@ph's Avatar
Philippines, NCR, Pateros
Joined Apr 2004
677 Posts
Quote:
Originally Posted by pawelsky View Post
Made some progress with decoding the Naza GPS messages and using an Arduino board I'm now able to display LAT, LON, altitude, number of satellites.
I think I'm also getting fix type, horizontal and vertical accuracy estimate, but I'm not that sure about these.
is this info coming straight from the expansion port?
i hope you could share it with us i have some arduino laying around
blimppilot@ph is offline Find More Posts by blimppilot@ph
Reply With Quote
Old Sep 25, 2013, 07:08 PM
Makers gonna make...
pawelsky's Avatar
Polska
Joined Jan 2012
1,949 Posts
Quote:
Originally Posted by blimppilot@ph View Post
is this info coming straight from the expansion port?
Yes, so no need to hack into the GPS module and solder wires to the ublox chip.
pawelsky is online now Find More Posts by pawelsky
Reply With Quote
Old Sep 25, 2013, 07:23 PM
Yep, Naza-controlled Tricopter
tonyestep's Avatar
St. Louis
Joined Apr 2002
1,455 Posts
Splendid work. This could turn out to be helpful to a lot of people.
tonyestep is offline Find More Posts by tonyestep
Reply With Quote
Old Sep 26, 2013, 02:04 AM
SirEdward
blimppilot@ph's Avatar
Philippines, NCR, Pateros
Joined Apr 2004
677 Posts
Quote:
Originally Posted by pawelsky View Post
Yes, so no need to hack into the GPS module and solder wires to the ublox chip.

Great news. I hope we could make great osd out of this.
blimppilot@ph is offline Find More Posts by blimppilot@ph
Reply With Quote
Old Sep 26, 2013, 02:23 AM
SirEdward
blimppilot@ph's Avatar
Philippines, NCR, Pateros
Joined Apr 2004
677 Posts
Additionally we might be able to use after market gps and compass with better performance
blimppilot@ph is offline Find More Posts by blimppilot@ph
Reply With Quote
Old Sep 26, 2013, 04:24 AM
Makers gonna make...
pawelsky's Avatar
Polska
Joined Jan 2012
1,949 Posts
Quote:
Originally Posted by blimppilot@ph View Post
Additionally we might be able to use after market gps and compass with better performance
Won't be that easy, as the communication goes both ways (I'm only interested in what is coming from the module). Also I find the performance pretty good so don't think it needs to be improved.
pawelsky is online now Find More Posts by pawelsky
Reply With Quote
Old Sep 26, 2013, 05:02 AM
Makers gonna make...
pawelsky's Avatar
Polska
Joined Jan 2012
1,949 Posts
Message 0x10

OK, so here is what I've found so far.

The 0x10 message contains GPS data. Here is the structure of the message, fields marked with XX I'm not sure about yet. The others will be described below.

55 AA 10 3A DT DT DT DT LO LO LO LO LA LA LA LA AL AL AL AL HA HA HA HA VA VA VA VA XX XX XX XX NV NV NV NV EV EV EV EV DV DV DV DV PD PD VD VD ND ND ED ED NS XX FT XX SF XX XX XM SN SN CS CS

The payload is XORed with a mask that changes over time (see below for more details).

Values in the message are stored in little endian.

HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x10 for GPS message)
BYTE 4: lenght of the payload (0x3A or 58 decimal for 0x10 message)

PAYLOAD
--------------
BYTE 5-8 (DT): date and time, see details below
BYTE 9-12 (LO): longitude (x10^7, degree decimal)
BYTE 13-16 (LA): latitude (x10^7, degree decimal)
BYTE 17-20 (AL): altitude (in milimeters)
BYTE 21-24 (HA): horizontal accuracy estimate (see uBlox NAV-POSLLH message for details)
BYTE 25-28 (VA): vertical accuracy estimate (see uBlox NAV-POSLLH message for details)
BYTE 29-32: ??? (seems to be always 0)
BYTE 33-36 (NV): NED north velocity (see uBlox NAV-VELNED message for details)
BYTE 37-40 (EV): NED east velocity (see uBlox NAV-VELNED message for details)
BYTE 41-44 (DV): NED down velocity (see uBlox NAV-VELNED message for details)
BYTE 45-46 (PD): position DOP (see uBlox NAV-DOP message for details)
BYTE 47-48 (VD): vertical DOP (see uBlox NAV-DOP message for details)
BYTE 49-50 (ND): northing DOP (see uBlox NAV-DOP message for details)
BYTE 51-52 (ED): easting DOP (see uBlox NAV-DOP message for details)
BYTE 53 (NS): number of satellites (not XORed)
BYTE 54: ??? (not XORed, seems to be always 0)
BYTE 55 (FT): fix type (0 - no lock, 2 - 2D lock, 3 - 3D lock, not sure if other values can be expected - see uBlox NAV-SOL message for details)
BYTE 56: ??? (seems to be always 0)
BYTE 57 (SF): fix status flags (see uBlox NAV-SOL message for details)
BYTE 58-59: ??? (seems to be always 0)
BYTE 60 (XM): not sure yet, but I use it as the XOR mask
BYTE 61-62 (SN): sequence number (not XORed), once there is a lock - increases with every message. When the lock is lost later LSB and MSB are swapped with every message.

CHECKSUM
-----------------
BYTE 63-64 (CS): checksum, calculated the same way as for uBlox binary messages


XOR mask
---------------
All bytes of the payload except 53rd (NS), 54th, 61st (SN LSB) and 62nd (SN MSB) are XORed with a mask. Mask is calculated based on the value of byte 53rd (NS) and 61st (SN LSB).

If we index bits from LSB to MSB as 0-7 we have:
mask[0] = 53rdByte[0] xor 61stByte[4]
mask[1] = 53rdByte[1] xor 61stByte[5]
mask[2] = 53rdByte[2] xor 61stByte[6]
mask[3] = 53rdByte[3] xor 61stByte[7] xor 53rdByte[0];
mask[4] = 53rdByte[1];
mask[5] = 53rdByte[2];
mask[6] = 53rdByte[3];
mask[7] = 53rdByte[0] xor 61stByte[4];

To simplify calculations any of the unknown bytes that when XORer seem to be always 0 (29-32, 56, 58-60) can be used as XOR mask (based on the fact that 0 XOR mask == mask). In the library I use byte 60.

Date and time format
----------------------------
Date (Year, Month, Day) and time (Hour, Minute, Second) are stored as little endian 32bit unsigned integer, the meaning of particular bits is as follows:

YYYYYYYMMMMDDDDDHHHHMMMMMMSSSSSS

NOTE 1: to get the day value correct you must add 1 when hour is > 7
NOTE 2: for the time between 16:00 and 23:59 the hour will be returned as 0-7 and there seems to be no way to differentiate between 00:00 - 07:59 and 16:00 - 23:59.

You wil find the uBlox binary messages specification in this document. It also contains checksum calculation algorithm.

If you can find out the meaning of the XX bytes - please share in this thread.
pawelsky is online now Find More Posts by pawelsky
Last edited by pawelsky; Nov 12, 2014 at 12:28 PM. Reason: Added notes about date/time decoding
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion Powerlab 8 Communication Protocol Question pilotError FMA Direct 7 Jun 09, 2012 11:16 PM
Discussion 10Hz GPS V4 Expander Module wiring/communication protocol erwinkendo DIY Electronics 1 Sep 10, 2010 08:55 AM
Discussion A new protocol for communication between rc subcomponents Alan Hopper DIY Electronics 7 Aug 05, 2009 01:30 PM
Discussion MileHighWings publishes USB v.4 communication protocol bluesky123 Chit Chat 0 Jun 24, 2007 01:10 PM
Question Mpx mc4000, mc3030, evo - communication protocol kolmanl Radios 2 Jan 07, 2003 07:43 PM