Close
0%
0%

Motorcycle lean angle video overlay

A project to add lean angle overlay to your motorcycle videos

Similar projects worth following
I like riding motorcycles and I wanted to add a data overlay to my helmet mounted GoPro videos to show the lean angle.

I've wanted to add data overlays to my motorcycle videos taken with GoPro for some time. This project is my efforts to make it happen. Mainly I wanted to have an overlay that shows the current lean angle of the motorcycle.

The hardware serves two functions:

  1. Log GPS information.
  2. Start GoPro recording and GPS logging at the same time. This makes aligning the overlay and video easier.

Hardware

  • ESP8266 - This is used to connect the the GoPro's wifi network and send the command to start and stop video recording. It is also used to do some parsing of GPS serial data and configuring the GPS at startup via the UART's.
  • Openlog - Used to record GPS data to SD card
  • GPS - Ublox NEO-6M, generates the GPS serial data.

Firmware (for esp8266)

The firmware for the ESP8266 has been developed with the opensdk. There are a number of functions, more or less following this order.

  1. Search and connect to Gopro wifi network
  2. Determine if a GPS fix has been achieved
  3. Trigger GoPro recording and GPS data logging simultaneously (well almost simultaneously). A led is also flashed at this time to help with syncing the video with data.
  4. Stop video recording and data logging (not yet implemented)

Here is a high level state machine.

Software (on PC)

A command line tool to generate the frames for the final video. The tool parses the recorded GPS data log, calculates an estimate of lean angle, applies a low pass filter to the output and generates png images that can be imported as frames for the video. Github link provided.

      logger_statemachine.png

      High level state machine describing the logger firmware.

      Portable Network Graphics (PNG) - 37.91 kB - 11/05/2016 at 23:54

      Preview Download

      filtered_lean.png

      Filtered and raw output comparison.

      Portable Network Graphics (PNG) - 70.36 kB - 09/08/2016 at 10:20

      Preview Download

      • 1 × esp8266
      • 1 × Sparkfun openlog
      • 1 × U-Blox NEO-6M GPS Module
      • 1 × Red LED
      • 1 × Green LED

      • Boards ordered and better GPS module

        Simon11/06/2016 at 21:58 0 comments

        I've put in the order for the first version of the PCB so that's a few weeks away. Also after some research I've found a GPS module at a decent price that has the time pulse pin broken out. My previous hacked together prototype needed a bodge wire soldered to the GPS module to get the time pulse, so I'm very happy about this. Here's a link: http://www.gearbest.com/transmitters-receivers-module/pp_229580.html?wid=21 I'd still like to try making my own breakout for the NEO6M GPS but I don't imagine it will be easy with all the RF voodoo required.

        I haven't decided how I want to open source the board design just yet. It still has a lot of room for improvement, I'd estimate that the components currently included to allow flashing of the esp8266 and an AT328 micro to drive the logging to SD card could all be removed with the use of an extra board for flashing and logging done by the esp8266 directly through SPI. I guess room for improvement isn't a bad thing though. With regards to opensourcing the design do people just make the gerber files available or the design files themselves?

        I've also updated the description of the project a little, hopefully people understand what I'm trying to do!

      • Added code for data logger firmware

        Simon10/21/2016 at 04:48 0 comments

        I've added the GitHub repository for the data logger firmware to the project. It's a bit rough around the edges and still needs a Readme. I wanted to get it up sooner rather than later though.

        Still working on layout for the first go at the logger PCB.

      • Quick update..

        Simon10/18/2016 at 12:02 0 comments

          Just a short update, I've been working on designing a PCB with Eagle. At this stage it will include a header for the GPS module, ESP8266-12E and the circuitry from the Openlog. The layout is almost finished and I'll upload to GitHub when it is complete.

          This process has made me consider two things.

          1. Can I design a nice module for the Ublox Neo-6m GPS that includes a breakout of the time pulse signal? I cannot find one online currently and the chip by itself is so cheap! This may be a spin off project.
          2. Can I get the ESP8266 to write the data directly to the SD card? This will require initialising the file system and writing over SPI. I'm sure it's been done but I haven't researched enough on it. This would have the added bonus of removing around half of the components from my board!! This will be something for the next iteration.

          The firmware for the ESP8266 is likewise almost ready and that will be uploaded to GitHub aswell.

          Standby......

      • Lean angle calculation method

        Simon09/05/2016 at 08:56 3 comments

        This log will give a short description of how the estimate of motorcycle lean angle is calculated from GPS NMEA sentences.

        Starting with the GPS module itself I'm using the second (TX only I believe) UART on the esp8266 to send some bytes to configure the Ublox-Neo-6M GPS module to only output the GPRMC sentence and to set the update rate to 5Hz. I had previously done some tests using my phone to record NMEA sentences which could only do a 1Hz update rate. 5Hz is working out much better.

        With the GPS outputting GPRMC at 5Hz the serial data is passed to the Openlog and recorded on the SD card for processing later.

        Ok so now the post processing. Basically the calculation is dependent on two parameters: speed and track bearing.

        The first step is to determine if the bike is turning left or right based on the "current" value and the "previous" value of the track bearing. "Turns" (haha) out this is very easy by doing a cross product like so:

        The value of turn will vary between 1 and -1 where turn > 0 is a right hand turn and turn < 0 is a left hand turn. This is used to to assign positive and negative values to right and left turns respectively.

        Next is to determine the rate of change of direction, yaw rate. This is fairly easy most of the time i.e.

        However when the points cross through zero degrees (North) a bit of extra care is required. This is probably a well known algorithm but it was instructive to figure it out myself.

        if (abs(yaw_delta) > (180))
        {
            yaw_delta = turn * ((360) - abs(yaw_delta));
        }
        
        

        So now we know how many degrees the bike has turned through between the current and the previous data point and we know if the bike is turning left or right. The period of the turn, if it was to come full circle can be calculated. Like so:

        Where the datarate is the data rate of the GPS, set to 5Hz in my case. The assumption is made that the path of the bike through the turn follows an arc of a circle. This is probably not a bad assumption given that the time elapsed between data points is 0.2 seconds and the radius of the corner is going to be quite large. The radius of the path through the turn is given by:

        Where the speed is in m/s.

        Finally the lean angle in degrees is given by:

        Well that's a quick tour through the calculation method I've used. I hope it is useful to someone.

      • First entry

        Simon09/04/2016 at 03:53 0 comments

        First entry! Ok well the current status is that I have a working prototype of the hardware which I've tested a few times and it seems to be pretty reliable. As far as the hardware goes I'm quite happy with it but would like to make a pcb which I haven't done before to I'm excited about that.

        Since I've already solved a bunch problems to get to this stage I might do a few retrospective logs to talk them through if only so they are recorded somewhere. I think this should include a description of the lean angle calculation from GPS data and a description of the filtering of the output at least.

        I'll also add a video demo of the prototype so people can see how it works.

      View all 5 project logs

      Enjoy this project?

      Share

      Discussions

      Chris wrote 09/07/2016 at 22:24 point

      If you use a savitzky-golay filter, the lean angle will be much more responsive. It is more computationally intensive, but probably worth it (especially if done on the PC after the fact)

        Are you sure? yes | no

      Simon wrote 09/08/2016 at 10:23 point

      Hi, thanks for the suggestion. I'll definitely have a look into it. I uploaded a plot of the raw and filtered (FIR LPF) lean angle which I think is giving a pretty reasonable result. With the benefit of post processing there is no phase delay with the lowpass filter which is nice :) 

        Are you sure? yes | no

      Similar Projects

      Does this project spark your interest?

      Become a member to follow this project and never miss any updates