TCX-Tools: Convert Nike+ Files, Work With GPS and Heart Rate Data from TCX Files.

Photo by darkmatter/flickr.

I recently started using Endomondo to keep track of my workouts. Endomondo can get data from the Endomondo smartphone apps, but it also has good support for importing data from Garmin devices (including my Garmin Forerunner 610) and it supports importing tcx files generated by other sites/apps as well. However, there was a few things that annoyed me a little bit.

  • I could not import my old foot-pod workouts from Nike+.
  • Endomondo will only display the heart rate graph if the workout has associated GPS information. This means that I cannot see the heart rate graph for my indoor workouts, and that’s just dumb.
  • Sometimes I will walk or run with my wife and we will follow the same route. If she wears the Forerunner the associated heart rate information will not apply to me, although the gps trace itself is perfectly valid.
I decided to scratch my itch and develop some simple open source tools that can help me with the above issues. The result is TCX-Tools. which is a suite of very rudimentary tools that perform helpful operations on TCX files, the popular Garmin file format for fitness information.
  • nike+totcx Converts XML Files with iPod foot-pod data from Nike+
    to TCX files.
  • tcx-add-gps-coordinate Adds a GPS coordinate to an existing TCX
    file without location information.
  • tcx-strip-heart-rate Removes heart rate information from an
    existing TCX file.

Be aware: This is a very basic collection of XSL Transformations and some trivial tools to run them. There are probably multiple bugs and there is no fancy GUI or anything like that. It is also completely untested on anything but Ubuntu 11.10, but I am hopeful that it works on most OS’s, even if the scripts themselves won’t run :). Please let me know if/when you find any issues with any of the tools and I’ll try and fix them.

Endomondo heart rate

Endomondo heart rate graph with no speed information.

Installation

TCX-Tools is hosted on github. These directions assume  you are working with a GNU/Linux (or possibly Mac) system. The tools are based on XSL Transformations which should work in any os if you have the right tools. First clone the tcx-tools repository

$ git clone https://thomasmoelhave@github.com/thomasmoelhave/tcx-tools.git
$ cd tcx-tools 

You will need to install Saxon, on Ubuntu this can be done like this:

$ sudo aptitude install libsaxon-java 

To use nike+totcx to convert Nike+ XML files to TCX files you also
need to download the EXSLT template:

$ wget http://www.exslt.org/date/functions/add/date.add.template.xsl 

nike+totcx

The nike+totcx tool is an xsl document that can be used to convert
information from a standard Nike+ foot-pod system paired with an iPod
to the TCX files supported by Endomondo and Garmin Connect (and many
others).

Getting the data

Mount your iPod and find the directory containing the .xml files for
the individual workouts. On my iPod the workouts are stored in the
directory

 /media/<ipod name>/iPod_Control/Device/Trainer/Workouts/ 

It is also possible to get the xml files of past runs from the Nike+
website, but it involves some trickery.

Running

$ ./nike+totcx <input xml file> <output tcx file> 

tcx-add-gps-coordinate

As explained above this tool adds a single GPS coordinate (lat,long)
to the tcx file. Doing this will coerce Endomondo to display the heart
rate graph that it otherwise wouldn’t display.

Running

$ ./tcx-add-gps-coordinate <input tcx file> <output tcx file> <lat> <long> 

tcx-strip-heart-rate

If you have been out exercising with a companion that used a gps and
heart rate monitoring device, you may want to import the GPS trace but
not the heart rate information into your own account (on Endomondo,
Garmin Connect or other tool). This tool strips the heart rate (and
calorie) information from the supplied tcx file, but keeps everything
else.

Running

$ ./tcx-strip-heart-rate <input tcx file> <output tcx file> 

11 thoughts on “TCX-Tools: Convert Nike+ Files, Work With GPS and Heart Rate Data from TCX Files.

  1. Awesome tool! I have a bunch of old run files that I’d like to convert to tcx, and I’m trying to do it using your code on a Windows XP computer. When I run this command:

    ./Transform.exe -t -s:run_2012-02-16_1295177237.xml -xsl:nike+totcx.xsl -o:run_2012-02-16_1295177237.tcx

    I get this error message:

    Error at xsl:function on line 72 column 37 of nike+totcx.xsl:
    XTSE0280: Namespace prefix ‘foo’ has not been declared
    Error on line 75 of nike+totcx.xsl:
    XPDY0002: Axis step child::element(”:hej) cannot be used here: the context item is undefined
    Failed to compile stylesheet. 2 errors detected.

  2. Hi Thomas,

    I was able to run the code on my Ubuntu computer at home, and it worked perfectly. Thank you for taking the time to write this tool – it’s very helpful to be able to load my iPod runs to endomondo.

    Just to be thorough, I tried re-running the code on my Windows computer after removing lines 72-76 as you suggested. I get another error message related to the $csvdata variable. So, I changed line 56 to match the predicates in line 51:

    I got another error message, so I changed line 86 to:

    and line 104 to:

    I guess the strings are converted to numbers automatically on a linux computer, but not a Windows computer. Weird.

    After these changes, your tool generated a txc file on my windows computer that imported perfectly into endomondo. Thanks again!

  3. Holy Cow! I’ll just explain it :)

    The predicates in line 56 should match the predicates in line 51: [@dataType='distance' and @intervalType='time' and @intervalUnit='s']

    Line 82 needs a number() function around “substring-before($csvdata, ‘,’)”

    and Line 104 needs a number() function around $csvdata

    Hope that makes sense.

  4. Yep – those changes make it work perfectly on Windows, and I was able to import the files into endomondo.com

  5. jeg har det nye Nike Sportswatch GPS og kunne også godt tænke mig at kunne uploade til Endomondo. Jeg vil gætte på dit program også vil kunne det. Men er der nogen chance for du vil lave en mere blondinevenlig version? Jeg ved der findes rigtig mange som vil være meget interesseret i at deres nye Nikeur kune bruges på Endomondo.

  6. Hej Jakob,

    Værktøjet til at konvertere mellem Nike+ og tcx er ikke lavet til GPS filer, så det er ville ikke virke i dit tilfælde — selv hvis værktøjet var mere brugervenligt :/.
    Det er ikke umuligt at lave det så det kan håndtere GPS-data men det er desværre næppe noget jeg får gjort selv.

  7. This great tool has finally given my a solution to how to import my Nike+ pod runs into Endomondo. I am using the RunningTracker application to get all my runs, then I export them and make a batch conversion. Great!

    Many thanks to Thomas and Daniel for your time to create these tool.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>