Raiden38
Posts: 3
Joined: Fri May 15, 2015 10:32 am
Delivery Date: 15 May 2015

Re: Editing the Nav Stored Locations via SD Card

Wed Apr 20, 2016 9:02 pm

Hi everyone!

Did someone figured this out? Would someone be kind enough to build a PHP function, that would output the 3 values (9,10,11) from the x and y coordinates (1,2)?

I'm currently building a repository for charge station that we will import to our leafs but i'm missing those 3 numbers.

Thanks so much!

User avatar
TimeHorse
Gold Member
Posts: 999
Joined: Thu May 13, 2010 4:40 am
Delivery Date: 02 Nov 2011

Re: Editing the Nav Stored Locations via SD Card

Sun Sep 04, 2016 8:09 pm

I can't remember what fields stored the grid data but I believe those are the fields the last two posters were struggling with so here again is my explanatory post. Specifically, grid_data is field 9, x is field 10, and y is field 11, IIRC:
TimeHorse wrote:Update: I think I have the equation for converting between the Map Data Grid, X and Y and longitude and latitude and rather than making anyone else suffer, let me spell it out here for all to see. This information wasn't meant to be proprietary, it was meant to be free as in speech, but in this case also free as in beer!

The Grid Data collectively stores a 25-bit number for the longitude (x) and a 25-bit number for the latitude (y). The North American Nissan LEAF maps only distend over a range from 172W to 52W Longitude and from 0N to 80N in Latitude. The North Pole is not part of the map, and neither is Iceland or Europe or the Prime Meridian. Thus one third of the Earth by Longitude (120 degrees or 432,000 arc-seconds) and almost half by Latitude (80 degrees or 288,000 arc-seconds). The mapping between x, y and Longitude, Latitude is a linear function mapping the 25-bit values to their degree, minute, second mapping, respectively, as follows:

Code: Select all

x = (longitude + 172)*65,536 + 15,728,640
y = latitude*98,304 + 16,777,216

longitude = (x - 15,728,640)/65,536 - 172
latitude = (y - 16,777,216)/98,304
This is clearer if hexadecimal is used:

Code: Select all

x = (longitude + 172)*0x10000 + 0x0f00000
y = latitude*0x18000 + 0x1000000

longitude = (x - 0x0f00000)/0x10000 - 172
latitude = (y - 0x1000000)/0x18000
Of course, that assumes you have x and y as the properly formatted, unsigned, 25-bit values. To get those you have to do quite a bit of jiggery-pokery. Specifically, the Data Grid is a negative, 32-bit value. I find it easier treat the grid data as an unsigned 32-bit value in my calculations so for instance -2,147,452,928 (-0x7fff8800) becomes 2,147,514,368 (0x80007800), specifically:

Code: Select all

u = (grid_data & 0x7FFFFFFF) + 0x80000000
grid_data = -(-u & 0x7FFFFFFF)
It has to be done this way to preserve the sign, otherwise the grid_data will lose the upper bits.

That resolved, I've observed that, starting from 0x80000000 as bit zero and 0x00000001 as bit 31, bits 1, 12, 13, 28 and 29 are never used. In other words, 0x400C000C is a mask for all the bits never used in the grid data. Likewise, 0 and 18 are always set (bit 0 means the number is always negative), in other words 0x80002000 is a mask for the always-on bits. Ignoring bits 0, 1 and 18 for the moment, what's clear with bits 12, 13, 28 and 29 is that they don't enter into the calculation of position. What you effectively have when you ignore those bits is:

Code: Select all

yyyyyyyyyyyy00yyxxxxxxxxxxxx00xx
for the format of the upper register of the x and y components, xh and yh, where each letter represents a bit in u starting with bit 0. The conversion is thus:

Code: Select all

xh = ((u & 0xFFF0) >> 2) | (u & 0x0003)
yh = (((u >> 16) & 0xFFF0) >> 2) | ((u >> 16) & 0x3

u = ((yh & 0x3FFC) << 18) | ((yh & 0x0003) << 16) | ((xh & 0x3FFC) << 2) | (xh & 0x0003)
where << means bitwise shift left, >> means bitwise shift right, & means bitwise and and | means bitwise or.

Finally we have the Map Data X and Y components, which are each 11-bit, unsigned values, meaning they go from 0 to 2047; at 2048 the increment the high portion and go back to 0. We'll call these map X and Y points xl and yl respectively.Therefore:

Code: Select all

x = (xh << 11) | xl
y = (yh << 11) | yl

xh = x >> 11
xl = x & 0x7FF
yh = y >> 11
yl = y & 0x7FF
And from x and y you can now compute longitude and latitude as a floating-point number similar to the way its stored in the NavTech app. I've found this calculation to be accurate within 1 arc-second, the resolution of the longitude and latitude floating-point values, which represents about 30m (100 ft) of accuracy in latitude and less in longitude (by a factor of the cosine of the latitude). Ideally, this should be within a half a degree which would be within rounding error. Currently, the error represents as much as one arc-second difference between the Grid Data Longitude and Latitude and the stored Longitude and Latitude.

Anyway, that's the total skinny you've been waiting for. Hope this helps any would-be developer.

Edit: Fixed equation for u in terms of xh and yh thanks to kcarmich.
RIP CO2 Fre, 27 months, 42,282 mi & 11 bars.
unAmerican Job & Nissan's Rapid Depreciation cost $20,000!
5 hours on the road daily w/o Charge at Work on 100%.

Long Live CO2 Fre, Maxed 2013 SL, 20,000 mi/yr lease.
http://aecn.timehorse.com/

CentralTransPoint
Posts: 5
Joined: Sun Dec 20, 2015 2:37 pm
Delivery Date: 20 Dec 2015

Re: Editing the Nav Stored Locations via SD Card

Wed Nov 09, 2016 1:50 pm

I have discovered the exact formula several months ago independently.
It is slightly simpler than TimeHorse algorithm.
I integrated it into my windows-application (developed with C#) and well tested for the points located in Europe.
I can extract the translation formulas later and place here for free using, if it is necessary for someone. It will be two lines only.
Last edited by CentralTransPoint on Thu Nov 10, 2016 12:48 am, edited 1 time in total.

Raiden38
Posts: 3
Joined: Fri May 15, 2015 10:32 am
Delivery Date: 15 May 2015

Re: Editing the Nav Stored Locations via SD Card

Wed Nov 09, 2016 2:08 pm

Would be so awesome and useful, thanks so much!!

CentralTransPoint
Posts: 5
Joined: Sun Dec 20, 2015 2:37 pm
Delivery Date: 20 Dec 2015

Re: Editing the Nav Stored Locations via SD Card

Sat Nov 12, 2016 5:30 pm

Hello!

The algorithm is the following:

Code: Select all

      public static void CalculateSpecialFields(String latitude, String longitude, out String field09, out String field10, out String field11)
      {
         Int32 i1 = Round(Decimal.Parse(latitude) * 48 * 2048);
         Int32 i2 = Round((Decimal.Parse(longitude) * 32 + 4992) * 2048);
         String s1 = "1" + Convert.ToString(i1, 2).PadLeft(24, '0').Insert(11, "00");
         String s2 = "1" + Convert.ToString(i2, 2).PadLeft(24, '0').Insert(11, "00");
         field09 = Convert.ToInt32(s1.Substring(0, 16) + s2.Substring(0, 16), 2).ToString();
         field11 = Convert.ToInt32(s1.Substring(16, 11), 2).ToString();
         field10 = Convert.ToInt32(s2.Substring(16, 11), 2).ToString();
      }

      public static Int32 Round(Decimal val)
      {
         return (Int32)Math.Round(val, MidpointRounding.AwayFromZero);
      }


I arrangeed it in several items to make it more readable.

The latitude and longitude are input parameters.
The field09, field10 and field11 are result values.

I also noticed the following thing. It is not so important, but only some observation :)
It is not necessary to write down any values into the field01 and field02. The Nissan navigation system will write some values to these fields by oneself. But as see, these values are not used by the navigation system at all. Furthermore the field01 and field02 values calculated by the navigation system are slightly differ from the original latitude and longitude which we use for the field09, field10 and field11 calculation. The difference is varied from 0 to 30 metres.
We can skip this difference and this feature at all, because the only field09, field10 and field11 (not field01 and field02) values are used within the navigation system for points displaying on the screen and for routes constructing.
It is easy to make sure of that. Find the point by the latitude and longitude values (which we use in the above algorithm) on the google maps and compare it position with the same point position in the Nissan navigation system. You will see, that the positions are equal in both places, though the field01 and field02 fo the point can differ from the latitude and longitude even to 30 metres sometimes.

I hope my formula is clear and understandable. Any questions are welcome!

Please pardom for my English. It is not my native language :)
Last edited by CentralTransPoint on Wed Nov 23, 2016 2:28 am, edited 3 times in total.

Raiden38
Posts: 3
Joined: Fri May 15, 2015 10:32 am
Delivery Date: 15 May 2015

Re: Editing the Nav Stored Locations via SD Card

Mon Nov 14, 2016 8:03 am

CentralTransPoint wrote:Hello!

The algorithm is the following:

Code: Select all

      public static void CalculateSpecialFields(String latitude, String longitude, out String field09, out String field10, out String field11)
      {
         Int32 i1 = Round(Decimal.Parse(latitude) * 48 * 2048);
         Int32 i2 = Round((Decimal.Parse(longitude) * 32 + 896) * 2048);
         String s1 = "1" + Convert.ToString(i1, 2).PadLeft(24, '0').Insert(11, "00");
         String s2 = "11" + Convert.ToString(i2, 2).PadLeft(23, '0').Insert(10, "00");
         field09 = Convert.ToInt32(s1.Substring(0, 16) + s2.Substring(0, 16), 2).ToString();
         field11 = Convert.ToInt32(s1.Substring(16, 11), 2).ToString();
         field10 = Convert.ToInt32(s2.Substring(16, 11), 2).ToString();
      }

      public static Int32 Round(Decimal val)
      {
         return (Int32)Math.Round(val, MidpointRounding.AwayFromZero);
      }



Hi! Thanks so much for this! Only problem is that I need to convert it to PHP for use on a webpage.

I'm trying to use the follow exemple:
Lat: 45,652778
Long: -72,561944

so if I get it right: (Which I am probably sure I don't)

i1 = 4487851
i2 = -2861056
s1 = 100000000000000004487851
s2 = -11000000000000002861056.
field09 = Makes no sense with all those 0 from PadLeft
field10= Makes no sense with all those 0 from PadLeft
field11 = Makes no sense with all those 0 from PadLeft

The actual result imported from Nissan GPS give:

field09 = -1573672526
field10 = 30
field11 = 699

These number are not even the calculation, my understand is that, except for the i1 and i2 calculation, the number does not changes, it's only data conversion, to fix the format (adding zeros)..

Thanks!

User avatar
SalisburySam
Gold Member
Posts: 198
Joined: Thu Sep 27, 2012 11:01 am
Delivery Date: 24 Feb 2012
Leaf Number: 018156
Location: Salisbury, NC

Re: Editing the Nav Stored Locations via SD Card

Mon Nov 14, 2016 4:18 pm

I'm surprised to find an entire thread of folks who actually use and wish to improve the Nav. After viewing the outdated data and totally unintuitive Nav app on my 2012SL, I gave up and haven't looked back. Thank goodness Waze was invented!
SalisburySam
-------------

2012 SL Super Black
Registered to order: April 20, 2010
Ordered: December 6, 2011
11,900 miles, 10 bars showing, 75% SOH, 49.80 Ahr

CentralTransPoint
Posts: 5
Joined: Sun Dec 20, 2015 2:37 pm
Delivery Date: 20 Dec 2015

Re: Editing the Nav Stored Locations via SD Card

Thu Nov 17, 2016 10:38 am

Raiden38 wrote:Hi! Thanks so much for this! Only problem is that I need to convert it to PHP for use on a webpage.

I'm trying to use the follow exemple:
Lat: 45,652778
Long: -72,561944

so if I get it right: (Which I am probably sure I don't)

i1 = 4487851
i2 = -2861056
s1 = 100000000000000004487851
s2 = -11000000000000002861056.
field09 = Makes no sense with all those 0 from PadLeft
field10= Makes no sense with all those 0 from PadLeft
field11 = Makes no sense with all those 0 from PadLeft

The actual result imported from Nissan GPS give:

field09 = -1573672526
field10 = 30
field11 = 699

These number are not even the calculation, my understand is that, except for the i1 and i2 calculation, the number does not changes, it's only data conversion, to fix the format (adding zeros)..

Thanks!


Hello Raiden38!

I have got some another results with my formulas and your source data.
So,
i1=4487851
i2=-2920412
s1="101000100011001101010101011"
s2="111111111111000100110111000000100100"

But in any case, as I see, my formulas work wrong with coordinates which are less than zero.
As I said before I tested my program with points located in Europe. So my formulas do not take into account negative coordinates.
If it is not so hard for you, please input some test coordinates within your Nissan navigation system, export points to USB-card and send me exported file. I will try to make my formulas workable with negative coordinates.
Unfortunatelly my Nissan navigation system does not allow me input any coordinates on the Western hemisphere because, the navigation system does not contain any maps for that coordinates. There are only European maps within.

CentralTransPoint
Posts: 5
Joined: Sun Dec 20, 2015 2:37 pm
Delivery Date: 20 Dec 2015

Re: Editing the Nav Stored Locations via SD Card

Wed Nov 23, 2016 2:11 am

Hello!

Thanks a lot to Raiden38 for his file with points. I have changed my formulas. Now they work properly both with East and West points.
I have updated my original message where the formulas are placed.

timpootle
Posts: 1
Joined: Sat Feb 25, 2017 9:24 am
Delivery Date: 25 Mar 2015
Leaf Number: 022427

Re: Editing the Nav Stored Locations via SD Card

Sat Feb 25, 2017 9:28 am

TimeHorse wrote:I finished my python script except for parsing the Grid Data location which others who figured out the algorithm are no longer following this thread. You can see the Python code at https://svn.timehorse.com/public-repos/ ... dresses.py"


Replying to an old thread, but big thanks to TimeHorse for his python function. I am swapping my 24kWh LEAF for a 30kWh model and tidying my address book while I transfer it.

Return to “Accessories / Mods”