Showing posts with label GPS Fix. Show all posts
Showing posts with label GPS Fix. Show all posts

Tuesday, May 1, 2012

More about how to use GPSKit for Real Studio

While I was completing the GPSKit documentation, I felt like I may share the some bits of it on this blog. I hope you'll find them useful and feel free to leave a comment if you wish to.
Just as a reminder, GPSKit 1.0beta2 is downloadable here.

The design of GPSKit.

GPSKit is based on a separation of tasks design. They are 4 layers of them:

  1. The first layer is the hardware connection. It gets the data from the GPS device and spit out valid chunks of data 'tokenized' according to the protocol specifications. It's the zdGPSDataProvider interface.
  2. The second layer is the data validator and parser. It receives the tokens from the zdGPSDataProvider, check their validity and turn each of them into an object that represents the GPS raw data in a more human understandable way. It's the zdGPSDataListener interface .
  3. The third layer is a GPS fix factory. It uses the objects instances provided by the zdGPSDataListener to create a zdGPSFix instance and make it available to the entire application. it's the zdGPSFixProvider interface.
  4. As in any I/O protocol, errors may happen, so there is a fourth layer that will handle these errors and perform the actions needed in such case. It's the zdGPSErrorHandler interface.

In order to know where to send the data, the zdGPSDataListener needs to say hello, 'to register' itself to the zdGPSDataProvider. As the zdGPSFixProvider is meant to be implemented within the same class as the zdGPSDataListener, there is no need to register it. However, it isn't mandatory for the zdGPSDataListener to implement the zdGPSFixProvider as some protocols may not provide geolocation information.

Currently, only the NMEA 00183 protocol via a serial port is available in GPSKit. For this format, the zdGPSDataProvider layer is implemented by the zdNMEASerial class. The zdGPSDataListener and the zdGPSFixProvider are both implemented by the zdNMEAParser. The zdGPSErrorHandler is implemented by the zdGPSDeviceConnection.

Getting started.

If you need to get the geolocation data provided by the GPS device connected to a serial port, you'll have to create a data provider, a data listener that is also a fix provider, register the listener to the provider, store the references to all these class instances and finally open the connection. Fortunately, zdGPSDeviceConnection is here to automate this process. It implements a method with the following syntax:

  Sub BuildSerialConnection( _
        inProtocol As zdGPSDeviceConnection.Protocol, _
        inSerialPort As SerialPort)

Where inProtocol is one of the value of the zdGPSDeviceConnection.Protocol ('UserImplemented' and 'NMEA0183' are the only currently available values), and inSerialPort is the SerialPort instance the GPS device is connected to. It will handle the serial settings depending on the protocol specifications (e.g. 4800 bauds, 8N1 for the NMEA 0183).
Note: The 'UserImplemented' protocol is currently used for internal testing purpose only. This may change in a future release.

So to build and open a connection, proceed as following:

  Dim theConnection As New zdGPSDeviceConnection

  theConnection.BuildSerialConnection( _
        zdGPSDeviceConnection.Protocol.NMEA0183, _
        System.SerialPort( 0 ) )

  If theConnection.Open Then
    MsgBox "Connection is open"
  Else
    MsgBow "theConnection failed to open"
  End If

Of course, you'll have to adapt the code depending on the serial port you are using and set your GPS device interface type to 'NMEA 0183'.

If the connection is successful, you can access the

  zdGPSDeviceConnection.NMEAParser.GetLatestGPSFix() As zdGPSFix

to get the geolocation data. Don't forget to test for 'Nil' before using the returned reference.

Something you should be aware of.

The BuildSerialConnection() method will raise a zdGPSKitException if the passed serial port reference is 'Nil' or if the chosen protocol is 'UserImplemented'. In both cases, the Message property content explains, in english, why the exception has been raised.

Why using a more complicated design when a single class handling all the data processing would have been simpler?

While the format of data may be the same (e.g. NMEA 00183), the type of hardware connection may be different depending on the GPS device you're using (e.g. serial port, USB, even TCP/IP). So to avoid duplicate code for each connection type, a multiple layering with interfaces was chosen. Actually, the first reason was to allow the testing of the code by using a file that simulates the input of serial data. A little application, developed with Real Studio, was used to record the data coming from the GPS device along with the timing information to a binary file while driving a car. Back to the IDE, A class implementing the zdGPSDataProvider interface was used to replay the flow of data with the same timing. The application and the replay class are not included in the current release because they really can use some refactoring, but may be in another release...

How GPSKit was developed.

Two Garmin GPS receivers are used to develop GPSKit: A GPS 72 and an eTrex H. A Nokia Navigator 6110 cell phone was also used via Bluetooth as well as some serial data from a Garmin Rhino 130 and a GPS III previously recorded to binary files.

The code was written and tested with Real Studio 2009r4 ( Enterprise edition ) on a MacBook 13". A HP nw9400 laptop and a Acer Aspire One ZG5 notebook are used to test on Windows XP. The Acer notebook is equipped with A 32GB SSD disk and is mostly used to record the GPS serial data when driving a car.

One more thing...

Doing something else than driving when your vehicle is moving is very dangerous. Always park your vehicle safely before using a GPS device, a computer, a cell phone or any other kind of stuff that needs at least one of your hands and draws your attention away from driving or riding.

Friday, April 27, 2012

GPSKit 1.0b2: The first public release for Real Studio

After being away for a while, I'm back again with some hot news: The first public beta release of GPSKit for Real Studio is now available for you to test it. A zip archive containing the demo app and a draft of the the documentation is available here.

The set of classes comes within a demo app and with a sketchy documentation that will be completed along the beta testing period. All  the classes are encrypted and their use is time limited: 10 minutes for a debug build and 5 minutes in a compiled app. An unlocking scheme will be implemented before the final candidate stage. The selling price hasn't been fixed yet.

To open a connection to your GPS device, create a new zdGPSDeviceConnection, pick a protocol from the zdGPSDeviceConnection.Protocol enumeration ( currently limited to NMEA 0183 ) and a reference to the SerialPort your GPS device is connected to. Then call the zdGPSDeviceConnection.BuildSerialConnection() method. You can see an example of how it works in the TestWindow.ConnectButton.Action event.

If you find a bug, a typo or think of a missing feature, feel free to create a report here. A subscription is required.
I'd be glad to hear any thought, critic or advice you may have about GPSKit, so don't hesitate to post a comment below.

The two top items on the GPSKit's to-do list are:
  1. Improve and complete the documentation to make it really useful.
  2. Implement the text output protocol.
They will be the main focus of the GPSKit v1.0b3 release. Stay tuned!

Monday, March 19, 2012

State of the GPS Kit

After a restless race full of legal formalities, I manage to find some time to work on the GPSKit project. And I'm pleased to announce that GPSKit and its demo project are now entering the alpha stage of the development.

As you can see on the picture on the left, the demo is a simple project but it's meant to demonstrate the basic use of GPSKit and one of the provided controls. Actually, there is only one control implemented for now: the GPS constellation canvas which is a representation of the position in the  sky of the satellites that the GPS device antennae can 'see'. There will be another control which will be a representation of the Signal to Noise ( S/N ) ratio for each of these satellites. The protocol popup menu is disabled since the NMEA0183 protocol is the only one supported for now. If you click on the 'Disconnect' button or no new data is sent for more than 10 seconds, the data text color is set to red to warn you that the currently displayed fix is obsolete. As soon as new data arrive, the text display is set to black again.

If you're bold enough to test this first alpha build, at your own risk, you will find it here as a zip archive ( Only Universal Mac OS X for the moment... ). You'll need to connect a GPS device to your Mac so the system can see it as a serial port. Then set the protocol to NMEA0183 on your GPS device configuration menu and launch GPSKit Demo. Select the serial port in the upper left popup menu and click 'Connect'. after a few secondes you should be able to see the fix data and the constellation of satellites.

If you encounter any problem, I'd be happy to hear about it. You can use our online bug tracker available at this address: http://bugs.zaatardigital.com/. You need to register before reporting an issue or request a feature. Note that it hasn't been tested on Mac OS X 10.7.x AKA Lion... yet!

The next stage will be the release of the source code for the demo project and the encrypted classes, modules and controls that are part of GPSKit and the documentation to help you implementing GPS localization in your Real Studio project. There is still a lot of work to do, so I'm going back to the IDE right now.

Update: The issue on Windows is now fixed. See this post to download new builds.

Friday, February 24, 2012

GPSKit For Real Studio

I was hoping to release the first beta tomorrow ( Saturday, 25th ) but the refactoring took longer than I thought due to an unexpected hardware issue. Tonight, all the GPSKit stuff will be ready. Unfortunately, the demo project still needs a heavy cleaning as do the documentation. So, the first beta is expected to be released later next week.

Photo by Asley Pomeroy - 2011
Let's have a sneak peek of what it can do for you:

Currently, GPSKit handles the NMEA0183 protocol via a RS-232 link. But the Text Out and the Garmin protocol are planned to be part of the final release and will be added during the beta test period.

If all you need for your Real Studio project is localization support, GPSKit provides a 'fix' in real time. In the GPS terminology, a fix is a set of data including the latitude, longitude, ground speed, altitude & vertical velocity ( in 3D fix mode ), heading, time stamp and data about the accuracy of the fix. This fix is generally refreshed once per second by the GPS device.

If your application needs more data, e.g. the satellites used for the fix, navigation information, alarm when approaching a waypoint, data about the waypoint, etc... it can access any of the NMEA0183 sentences provided by the GPS device in the form of a class and, of course in real time. Some models designed for boats even provide data about the autopilot... To spare you the time of learning all the NMEA0183 sentences, GPSKit provides classes to handle the most common sentences as object with real name properties, easier to understand than parameter indexes.

If you have any question, comment or suggestion, you're welcome.