Vessel Simulator Program
Ruby program that simulates a vessel moving on the face of the earth. Assuming you have all the prerequisites
installed you can run the program by simply going 'ruby Testing.rb'. Tell your navigation software/whatever that
wants to read NMEA 0183 sentences to connect to port 2222 of your machine. Then in the GUI slide up the speed
slider (vertical) to start moving and steer using the steering slider (horizontal).
Currently there is no facility to move vertically. The altitude is set at initialization and remains where set.
The compass rose will give you an approximate compass direction and other navigation parameters are displayed
in the status line at the top. The compass rose is displayed based on a calculated name. It load one of 16 PNG
files into a pixmap buffer array. Depending on the compass heading, the appropriate pixmap is displayed on the
GUI. I am sure there must be a way better way to do this, but it's crude and it works.
You need to have the following prerequisites installed and working. Please don't submit support requests or
questions unless you are absolutely sure you have the following installed and working:
1. Ruby of a fairly recent vintage like 1.8.7+. I do my testing on 1.8.7, 1.9.x and 2.0 so any should be fine
2. Visual Ruby. On MacOSX I have found this to be a non-trivial thing to get working. Google is your friend
3. Event Machine. This should be no problem to get working by just 'gem install eventmachine' or similar
Ruby program files
Testing.rb is the main program. It spins up threads to run the NMEA TCP/IP server, GPS, Compass, UI etc. If you want to
tweak things like the TCP/IP port it listens on or the initial starting position, then this is where you can do that.
UI.rb is the main User Interface. It uses Visual Ruby to drive Gtk+ GtkBuilder which displays the GLADE XML file found under
glade/UI.glade. You can edit this file using the Glade editor which is available for free download. While this may seem like
a slightly long-winded way to go about getting a GUI under Ruby, I have found it lets me build a completely OS-agnostic UI.
NMEAServer.rb is a TCP/IP NMEA 0183 repeater server. It listens on a pre-configured port (2222 by default) for
NMEA 0183 sentences and re-broadcasts them to any other peers that are connected. In this way, the various
program components can generate NMEA sentences and broadcast them to other listeners. Your application can
also connect to this server and listen to or send sentences.
NMEAUtility.rb is a small utility that can do some quirky NMEA 0183 stuff like calculate checksums and
convert decimal lat/lon to DMS.
Simulation.rb is the main simulation thread. It keeps track of the simulated vessel's current position (latitude/longitude),
speed, heading etc. For GIS geeks there is a nice little bit of code to calculate new lat/lon given starting position
with displacement and heading. It uses a spherical earth approximation and is "pretty accurate" which is good enough for a
Compass and GPS.rb simulate a Compass (or at least some sort of heading measuring device) and a GPS. Nuff said.
CompassDeviation.rb generates a set of simulated compass deviations. I have purposely made the deviations quite large on
certain headings but you an easily edit the table in the code to tweak the deviation card to your own needs.
CompassDeclination.rb calculates the local declination using the IGRF declination table values for 2013. This will
give you a good enough value for simulation purposes in most cases. It simply takes the Variation at the closest point
to the lat/lon where the simulation happens to be.
There is really only one file: UI.glade. It is the GUI definition consumed by Visual Ruby. Actually it's an XML file that
is read by Gtk+ GtkBuilder to display a GUI. Visual Ruby gives me a nice way to get at variables representing the various
field values in the display.