A weirdly named site with lots of boring content!

Sat 20 Dec 2008

Garmin Edge 205 GPS Cycle Training Tool

The Garmin Edge (image stolen from www.tramsoft.ch) is a pretty cool little bicycle gadget. It is basically a cycle-mounted GPS receiver. It has no maps - you can't use it to plot a route along the public roads like you can with a car sat nav.

You can however program it with a route which you've planned elsewhere (e.g. Google maps), and you can also record a route which you can download on to your PC. As well as this it's also an accurate speedometer - which is what I was really looking for when I came across it.

To download data to and from the device, I use a program called gpsbabel, which runs under Linux, Windows and Mac OS-X. To download a recording of a route, use:

gpsbabel -t -i garmin -f /dev/ttyUSB0 -o gpx -F /tmp/track.xml

The -t option stands for 'tracks', which is what gpsbabel calls these recordings of GPS data. Next the input device is specified as a garmin, along with its location, which is /dev/ttyUSB0 in this case. After the -o switch come the output options. The gpx format is an XML dialect for recording GPS waypoint data and gpsbabel's preferred format. The XML will be saved to the file /tmp/track.xml.

To confirm the location where your GPS device is connected, use dmesg:

dmesg | grep -i garmin

You should see a line like that below, telling you where under dev it can be found:

[ 9385.880000] usb 1-5: Garmin GPS usb/tty converter now attached to ttyUSB0

There is a problem however, in that we're using Linux's default garmin USB driver, which is problematic at best. On my system, it will often fail many times before it succeeds (throwing out an error that is usually something like "GPS_Packet_Read: Timeout. No data received. A301_Get: Non-Pid_Trk_Data").

A quick way around it is to use a while loop or similar to repeatedly run gpsbabel until it succeeds:

while [ ! -e /tmp/track.xml ] || [ $(stat -c%s "/tmp/track.xml") -lt 500 ]; do gpsbabel -t -i garmin -f /dev/ttyUSB0 -o gpx -F /tmp/track.xml; done;

This repeatedly tries to do the gpsbabel transfer while the file /tmp/track.xml doesn't exist, or is less than 500 bytes in length (it's somewhere around 400 bytes when the transfer has failed).

The less quick way is to disable the built-in driver and use gpsbabel's ability to interface directly with the GPS device, as explained on this page.

Once gpsbabel has downloaded it, the GPX file tells you the time the ride was started, min/max latitude and longitude, then the track information as a series of trkpt elements each one recording the time, latitude, longitude and elevation for that point. As a point is recorded at least once every 10 seconds, a normal ride can easily have several hundred of these trkpt elements.

<gpx version="1.0">
   <bounds minlat="52.446012469" minlon="-2.031685989" maxlat="52.482436448" maxlon="-1.880240338"/>
         <trkpt lat="52.446626695" lon="-1.880240338">
         <trkpt lat="52.446738677" lon="-1.880564885">
         <trkpt lat="52.446766421" lon="-1.880636131">
         <trkpt lat="52.446921738" lon="-1.881017424">
         <trkpt lat="52.446957277" lon="-1.881097052">


12:22 pm, Friday, 8 May 09

OK so using the gpsbabel USB driver isn't so hard, and it works properly unlike the distribution version! Thing is you need to compile gpsbabel with libusb support. To do this, make sure the libusb-dev package is installed on your system, then run

./configure --with-libusb
sudo make install

You also need to make sure the faulty garmin-gps driver is disabled on your system, by adding the following line to /etc/modprobe.d/blacklist:

blacklist garmin_gps

Note that this line is already present in Ubuntu versions from Gutsy onwards. You should now be able to use the following command to download the trackpoint data:

gpsbabel -t -i garmin -f usb: -o gpx -F /tmp/track.xml

The problem at the moment is that root privileges are needed in order to access the USB, which means the above command needs to be prefixed with sudo to work. This can be overcome by creating a file named /etc/udev/rules.d/51-garmin.rules with the following contents:

SYSFS{idVendor}=="091e", SYSFS{idProduct}=="0003", MODE="666"

You'll need to unplug and plug back in your GPS device for this to take effect.
Leave Comment

/xkcd/ Unification