Tag Archive | Trains

Tracking Moving Trains (with the minimum possible effort)

Trains are, in many respects, wonderful machines. They’re simultaneously both the most romantic form of travel and the most grueling way to get to work every morning. One thing trains are not however, is up-to-date with modern technology.

Whilst you can follow the course, in real time, of a plane soaring at 36,000 feet above the ground all the way from San Francisco to London you may be surprised that Train Operating Companies (TOCs) lack the ability to pinpoint the locations of their trains between stations. In other words, they may know that your train is between Cambridge and Foxton but they wont know exactly where.

Not knowing exactly where Trains are doesn’t cause any satefy issues — Block Signalling has been used to safely manage the passage of trains by identifying which “block” of track they were in, without an exact location, since the 1850s  — however, it does mean that the decisions that control rooms make are being made on educated guesses of a trains exact position at any given time.

Control rooms are the brain room of the modern railway and make decisions when things go wrong. If you’ve ever been told a train cannot run due to a “lack of train crew” its unlikely the driver was off sick and instead much more likely that a delay on a train they were driving earlier has cascaded down to your service and they simply never arrived at your station to drive the train. Control rooms try to avoid this — and many other issues.

Our earlier examples of Cambridge and Foxton aren’t exactly a million miles apart, and on a normal service you would expect a train to travel between them in around 5 minutes — but as the railway gets more and more congested making real-time decisions based on a time resolution of minutes will result in more and more decisions resulting in delays and cancelations.

After having learnt about this situation, whilst onboard HackTrain 2.0, I decided to have a go at resolving it in my own time.

One constraint of working with technology for use on trains is that, for all intents and purposes, you cannot add hardware to trains. The Rail Industry in the UK is, thankfully, obsessed with safety and that means that anything added to a train has to go through rigorous Health & Safety checks. This means it can take months, or years, for anything to be installed trackside or in a vehicle.

Whilst staff who work for South West Trains (who explained the situation to HackTrain competitors) are all issued with BlackBerry devices, some companies have started issueing their Guards and Conductors with relatively modern Android devices, some of which even act as ticket printing machine for on-the-train ticket purchases.

Armed with this knowledge I decided to try and validate my idea that a train could be tracked using just the smartphone device a member of train crew is already carrying. As I didn’t know if the idea would work in reality I set about making a working prototype with the minimum possible effort.

My acceptance criteria was pretty simple: Be able to view in real time the position of a train from Cambridge to Kings Cross. This wasn’t exactly the most measurable criteria (what does “real time” mean, for example?) but it gave me something to work towards.

In just a few hours over two evenings I developed a solution with a server written in Node.js that hosted two pages: `map.html` which, using the Google Maps JavaScript API, showed the current position and historic route of all trains being tracked and `report.html` which delivered a tiny JavaScript application to a browser which allowed it to report its location — attained through a HTML5 geolocation watch — via WebSockets, to the server.

The Prototype JavaScript client on an iPhone

The Prototype JavaScript client on an iPhone

The client and the server were, in the nicest way possible, scrappy. In order to identify a Train the guard (in these feasability tests that was me) would have to manually enter a Headcode into a JavaScript prompt and then leave the browser window open for the entire trip — I didn’t bother developing a background task. Each trains location data was stored in one big multidimensional array on the serverside that had no persistence code. But that was all fine, these applications were never intended to be production ready, just prove an idea was workable.

I walked down a few streets with my prototype client open in the Safari Browser on my iPhone and it appeared to report its location to the server as intended. So, on one of my final commutes into work before the holiday season I tested the system on a moving train on a route that includes tunnels, large areas of poor phone signal and central London; and all the different challenges these environments bring.

The route of my commute from Cambridge to London Kings Cross as tracked by my system

The route of my commute from Cambridge to London Kings Cross as tracked by my system

I was pleasently suprised with the results, shown above , despite a few anomalies.

Due to the fact I was using the `watchLocation()` function the train didn’t report its location in even time periods, as it would if you were polling the location, but rather only when the trains position changed significantly. Despite this fact, the period between the train attemting to send its location whilst on the move was never more than around 10 seconds.

I say attempted because, as expected, there were some issues with mobile coverage. I had expected to have issues in tunnels, but actually only the final tunnel before Kings Cross (which goes under the Grand Union Canal) caused issues. Lack of signal otherwised occured in a few blackspots in rural Cambridgeshire. This issue could be mitigated by employing a system such as that provided by Nomad Digital which provides an internet connection to a train using multiple sim cards connected to multiple network providers.

Another issue you can see in the above screenshot is that my train appears to have left the tracks a few times. I can assure you that this didn’t actually happen, but appears to have done so due to a combination of some inaccurate GPS readings and some failed data transfer caused by the aforementioned network connectivity problems. These errors could be mitigated using a host of techniques: comparing GPS position to known track locations, buffering changes in location that seem too great and only accepting them as true if subsequent location changes appear to be in the same area.

This was a pretty interesting project to work on. It gave me an oppertunity to develop a simple solution to a real life problem in a short period of time and learn about the awesome Socket.io library. I was happy to see it work so well, and to be wrong about tunnels. I look forward to making some of the improvements I’ve mentioned in this post and making the UI prettier and data storage a little bit more resilient.

Danny

HackTrain

HackTrain

This weekend I was lucky enough to be part of The HackTrain.

HackTrain is the first ever train hackathon in Europe targeted to #HackTheRails! An unforgettable experience where 40 of the best developers from all around Europe will revolutionize the world! Jump on board the HackTrain for a once in a lifetime journey, travel to the top tech spaces in the UK, hang out with the market makers in the Startup ecosystem, and create startups that will revolutionize the world!

The journey started out in London where National Rail Enquires, The Association of Train Operating Companies, East Midlands Trains and Virgin Trains East Coast all gave talks about their technology stacks, public APIs they had made available and challenges with technology they were trying to overcome. The sponsors for the event, including financial computing company Bloomberg also spoke about their APIs and what they do.

The first train we got took us from London St. Pancras to Sheffield via the Midland Mainline. During this time we had icebreaker sessions to get to know our fellow hackers, including having to come up with a pitch for a company whose name was an amalgamation of two random words. My team got Snickers Jacuzzi, so we pitched an idea for advertising jacuzzis on the inside of Snickers wrappers. Mad, I know.

Once we arrived in Sheffield we went to Electric Works — an office full of tech startups and home to Europe’s largest indoor slide — this was where each of the 40 participants who wanted to could pitch an idea. I decided to pitch the idea of an application which could dynamically work out any delays happening in real-time to your train (or any subsequent trains in your journey) and alert anyone who might be affected by this, for example a parent picking you up from the train station or anyone subscribed to attend an event on your Google Calendar. In this example it could also inform said parent what time they would have to leave their current location to pick up their child on time. Once everyone had pitched their ideas each of the participants voted for which projects they felt should be worked on. 11 out of 40 people voted for my idea, and so I was able to attempt to form a team to develop it.

However, due to weird team sizes my team had to merge with another team. This was a blessing in disguise as they were nice people to work with, however it meant that only one of our projects could be worked on. I suggested we worked democratically and put it to a vote of the 5 members of the new team and it was decided that we would work on the other idea.

The idea the team I was in developed over the course of the following 48 hours was called Icebreaker. Icebreaker aimed to solve the problem of boredom on long train journeys by matching you up with people on the train who were interested in talking and making friends. People would be allocated travel partners based on their interests and likes on Facebook. You can watch a truly horrifying video of an advert we produced showing how the system works below:

The workflow can be explained as follows:

  • Buy a ticket from TheTrainLine.com or similar
  • They redirect you to Icebreaker
  • If you want to talk, enter your mobile phone number and log in with Facebook. If not, close the tab.
  • Do nothing more, we handle all the hard work!
  • 10 minutes before you get on your train we’ll tell you who you’re matched with. If you still want to meet someone reply ‘yes’. If you’re not in a good mood that day or otherwise don’t want to meet reply ‘no’ or don’t reply!
  • If both people reply with ‘yes’ within 10 minutes, a location is selected for them to meet on board, and some unreserved seats where they could possibly sit together are suggested.

Whilst we were developing the system we were lucky enough to visit the National Railway Museum in York and Tech Cube in Edinburgh. A highlight of the journey for me was going over the Royal Border Bridge (aka the Berwick-upon-Tweed Viaduct).

The Final Judging of the competition happened in the National Railway Museum at York (nice and close to home ;)). Unfortunately our team wasn’t to win anything this time, however I can say I learnt a lot from the experience and made some wonderful connections with people in my industry and that of the train industry. I particularly learnt quite a lot about the Facebook and Twilio API’s, how to develop a business plan in a short period of time, how not to act on video and how important consumer validation is to an idea.

I’d like to take this time to thank the organisers, sponsors and judges of the HackTrain as well as my fellow participants who made it a weekend to remember.

Danny

Red Hot Chili Peppers

Tonight I went to see the Red Hot Chili Peppers at the LG Arena in the NEC in Birmingham. Simply put, it was a disaster.

Thursday when I went to purchase my train tickets the woman who served me provided me with tickets for the wrong day, due to the fact she recited the days back to me correctly I didn’t check the physical tickets for the date. So when I got to Hull Paragon Interchange station I found that my train time didn’t actually exist, putting me back by about an hour waiting for another, then when I got to Doncaster my connection from there to Birmingham was 33 minutes delayed.

The fact I even got on the trains was a miracle, as I was threatened with a massive fine and possibly being arrested.

This resulted in me getting to Birmingham at 8:30 rather than 5:30, missing the support acts, only just making it in time for the chili peppers and not even being able to meet up with my mate Sam, which totally ruined the night.

Due to many hours of frantic phone calls and web surfing to try to actually get to Birmingham at all my phone ran out of battery so no pictures of the chilis themselves unfortunately.

They played really well and It was great to see such enthusiasm and energy from a band where the members are ageing and its always great to see flea slap his bass!

Unfortunately the days train events ruined the night for me, but oh well.

Danny

IT, Professionalism, Operating Systems & Annoyances

(After only 7 minutes waiting at the Cottingham railway crossing “A Wild Train Appears…!” )

Today has been a good day on the whole, It started with our first ever Information Technology and Professionalism lecture in The Wilberforce building — the one that doesn’t look like a boat. The basic overview of the IT part of the course involves;

  • Word Processing Skills
  • Spreadsheet Skills
  • Database Skills
  • Enterprise Computing
  • Information (Management, Systems and the Internet)
  • Understanding the costs to business / business use of IT
Furthermore the professionalism side of the course covers;
  • The Concept of professionalism
  • Professional Ethics and good practice
  • The Law and Computing
  • Technical Writing Skills

It looks to be an interesting course, and I am looking especially forward to the group work in semester two, which involes creating a database running on a Microsoft SQL Server back-end and presenting a Powerpoint presentation to the year.

After this I grabbed a Bacon and Sausage sandwich from the Student Union and checked my emails… which brings me to my first annoyance of the day. Student Finance England have managed to cock up my student loan, by attempting to give me a Maintenance loan I neither want nor need and not paying my university — which I both want and need. This all stems from literally months of mis-communication on their behalf. I’ve never heard a good word said about the company.

After spending what seems like an hour trying to get through and solve the issue it was time for our second Computer Systems lecture, this time it was on the operating systems side of the topic and gave us a very interesting insight into what Operating Systems do and it was asked of us to make our own definition of an operating system by mixing the best parts of 5 definitions shown to us. I came up with;

An operating system is a software interface between hardware and the user; it is responsible for the management and coordination of activities and the sharing of the resources of a computer (such as memory, CPU time, disk space and input/output devices). It acts as a host for computing applications.

After the lecture finished I went to catch the bus back to my flat at The Lawns which brings me to my second (joke of an) annoyance. Cottingham Village Railway Crossing. I swear to god it always closes when I’m either on the way to or on the way back from Uni! Lol.

Anyway, thats all for now,

Danny