Monday, 15 October 2012

Navit GPS on Raspberry Pi

I've got a USB GPS dongle working with my Raspberry Pi, so I started exploring mapping software that I could run on it if I were to mount the RPi in my car with a little screen - the simple low resolution screens used for reverse parking cameras sold on eBay for under £20 look perfect.

Two options came up, GpsDrive and Navit - both of which recommend map data from Open StreetMap. Of these only Navit is available in the Debian/Raspian repository, so I tried that first.

$ sudo apt-get install gpsd gpsd-clients navit


Since Navit is a graphical tool, you'll either need to run with a screen attached, or ssh in with X forwarding and display Navit on your computer. I did the later, there is hardly any GPS signal where our TV is, and I don't yet have any other suitable screen.

Assuming gpsd is working and you're getting a good location from the GPS, when running Navit for the first time you get a black screen with a little green circle for your location - since it doesn't come with any useful maps pre-loaded.

Installing a Map

I followed the wiki links to the Navit Planet Extractor website, drilled down through the menu of pre-defined areas, picked Scotland, and waited for the map file to download. I then copied this to my RPi, and put it in a maps folder with a more meaningful name:

$ mkdir maps
$ mv osm_bbox_-8.1,54.5,-0.1,61.4.bin maps/osm_Scotland.bin

Referring to their Navit configuration instructions, I need to start by creating a configuration file based on the template provided, and then added the new map to it:

$ cp /etc/navit/navit.xml ~/.navit/navit.xml
$ sudo apt-get install emacs
$ emacs ~/.navit/navit.xml


Scanning the example configuration you come to a OpenStreetMap example entry:

                <!-- Mapset template for openstreetmaps -->
                <mapset enabled="no">
                        <map type="binfile" enabled="yes" data="/media/mmc2/MapsNavit/osm_europe.bin"/>
                </mapset>


So I copied that, switched it to enabled="yes", and pointed it at my new Scotland map file:


                <!-- Mapset template for openstreetmaps -->
                <mapset enabled="yes">
                        <map type="binfile" enabled="yes" data="/home/pi/maps/osm_Scotland.bin"/>
                </mapset>



I also disabled the sample map. Next time I ran Navit, I saw this at the terminal, and a map on screen:

navit:main_real:Using config file '/home/pi/.navit/navit.xml'

Navit on Raspberry Pi showing Dundee using OpenStreetMap
Using the arrow keys moves the map. Pressing enter brings up a menu, again use the cursor keys to move, and escape goes back. Selecting the menu "Settings",  "Maps", I could check it was looking at my new file. You can also control various things like orient the map North via the GUI, and switch the display mode (e.g. bright or for night driving). The proper way to shutdown Navit seems to be selecting the menu "Actions", "Quit".

Since this Scotland map was only 126MB, I decided to download the entire British Isles. Using the mouse on the Navit Planet Extractor website I picked bottom left (49.5, -11.2) and top right (61.1, 3.0), giving a 441MB file instead.

There is in fact a Navit world map available, at the time of writing 9.2GB in size (which would fit fine on a 16GB SDHC card if I really wanted to use it).

Building Navit from SVN

At this point I wondered if I could build Navit on the Raspberry Pi (see Navit on Linux instructions) from their SVN repository (recommended on their website), as the Raspbian package is already quite dated. Getting the build dependencies the easy way failed:

$ sudo apt-get build-dep navit
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: You must put some 'source' URIs in your sources.list

Seems a little configuration is needed perhaps? Having played with apt-rdepends, this seems to work instead - perhaps overkill:

$ sudo apt-get install subversion espeak cmake freeglut3-dev imagemagick libdbus-1-dev libdbus-glib-1-dev libdevil-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgarmin-dev libglc-dev libgps-dev libgtk2.0-dev libimlib2-dev libpq-dev libqt4-dev libqtwebkit-dev librsvg2-bin libsdl-image1.2-dev libspeechd-dev libxml2-dev ttf-liberation

And now the build - the output from cmake looked good, make itself took half an hour on the RPi:

pi@raspberrypi ~ $ mkdir repositories
pi@raspberrypi ~ $ cd repositories
pi@raspberrypi ~/repositories $ sudo apt-get install cmake subversion build-essentials
pi@raspberrypi ~/repositories $ svn co https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit/ navit
pi@raspberrypi ~/repositories $ cd navit
pi@raspberrypi ~/repositories/navit $ mkdir build
pi@raspberrypi ~/repositories/navit $ cd build
pi@raspberrypi ~/repositories/navit/build $ cmake ..
pi@raspberrypi ~/repositories/navit/build $ time make

The docs tell you to run this in place. We also have to update this configuration file as discussed above to use the new map:

pi@raspberrypi ~/repositories/navit/build $ cd navit/
pi@raspberrypi ~/repositories/navit/build/navit $ emacs navit.xml
pi@raspberrypi ~/repositories/navit/build/navit $ ./navit
Running from source directory
vehicle_gpsd:vehicle_gpsd_try_open:Trying to connect to localhost:default
vehicle_gpsd:vehicle_gpsd_try_open:Connected to gpsd fd=5 evwatch=0x1c6f30
navit:vehicle_ref:refcount 2
navit:vehicle_unref:refcount 1
navit:main_real:Using config file '/home/pi/repositories/navit/build/navit/navit.xml'
...

Summary

Playing with the Scotland map the draw times and route planning seemed fine, and the Raspberry Pi didn't seem short of RAM - so this would probably work in a car. Of course, there are a few hurdles to jump - first of all, waiting for my little in car monitor to arrive from Hong Kong, and then configuring Navit for a low resolution screen (or reusing an existing Navit OSD). It would also be fun to setup Navit's speech processing too (using espeak), which would mean adding a speaker as well. Finally unless I go for a touch screen, I'd need a keyboard or mouse to actually control Navit (although without this the default tracking mode would still be useful). I have a plan for that...

Update

See my next post on using a TomTom Bluetooth Remote with a Raspberry Pi, including remapping the buttons.

15 comments:

  1. Thanks for the useful information!

    ReplyDelete
  2. Pretty nifty stuff you have here, writing a program for your Navit and Raspberry Pi! I have to agree with you, though. The Raspberry Pi is definitely one of the best platforms to use if you want to build your own carputer. Aside from the size (it is pretty small, so it’s easy to fit anywhere inside the car), it can also be integrated into any auto electronic car part.

    ReplyDelete
    Replies
    1. I've tried the Raspberry Pi in the car via a 12V to 5V DC:DC step-down unit, together with a little 12V LCD car reversing monitor. I need to sort out the boot up sequence so that it will launch directly into Navit full screen, and then road test it - my plan for a future blog post.

      Delete
  3. Thanks for posting this. I'm getting started with Navit and Raspberry Pi and this has been very useful. I found that disabling the sample map is required because Navit only loads one mapset. I couldn't see my local map because the sample map was the only map loaded. Also "sudo apt-get install cmake subversion build-essentials" should be "sudo apt-get install cmake subversion build-essential" and it wasn't necessary since all of those were already installed by your apt-get install above that. Thanks!

    ReplyDelete
  4. Thanks for posting this, I found it to be really helpful in getting to grips with the way the Pi works. However, can you confirm if this will work on Xbian? I have the LXDE desktop environment installed, so I can't really see a problem with it, but it would be helpful if anyone could confirm it works on Xbian.

    ReplyDelete
  5. Nice info!
    Did you try running Navit directly on the framebuffer of your car monitor or do you run it from within X ?

    Im trying to get Navit running on a small tft (ITDB02-2.8) via framebuffer (https://github.com/notro/fbtft/) but no success yet.

    Regards,
    John

    ReplyDelete
    Replies
    1. I only every tried via X (running full screen).

      Delete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. I managed to break the 12V power supply in my car while trying to add a cable for the mini-screen and Raspberry Pi, so haven't taken this any further :(

      Delete
  7. How to use other GPS navigation softwares like GosMore?

    I am asking this because I heard Navit does not have bicycle routing.

    ReplyDelete
  8. Where do we put the code for the Mapset template for openstreetmaps? I am kinda confused in that bit.

    ReplyDelete
    Replies
    1. I was editing the file ~/.navit/navit.xml (where ~ or tidle means your home directory, and .navit is a folder starting with a dot meaning it is hidden by default on Linux). This is a simple human readable XML file which you can edit using emacs or another text editor.

      Delete
  9. Does GosMore include cycle routing?

    ReplyDelete
  10. Sorry, I meant does Navit include cycle routing?

    ReplyDelete