Goby3
3.1.5a
2024.05.23
|
The goby-util libraries are intended to provide functions and classes for handling relevant "utility" tasks, such as logging, string manipulation, scientific calculations, etc. Wherever possible, a high quality open source peer reviewed solution is used (such as the C++ STL, Boost).
Since Goby is primarily a marine middleware, a variety of empirical formulas for converting various seawater properties are included:
Templated constants are provided for pi
, e
, and not-a-number ("NaN"). To use, provide the desired precision, e.g.
Goby provides goby::util::UTMGeodesy as a starting point for the most common geodetic conversion (i.e., latitude longitude to Northings and Eastings using UTM on the WGS84 ellipsoid).
goby::util::UTMGeodesy is a thin wrapper around Proj functions. Proj is a powerful library with many different projections suitable for a variety of different applications.
It is often convenient to work in small X,Y values rather than use the full Northings and Eastings values (which can be quite large given the size of the WGS84 zones). To accomplish this, goby::util::UTMGeodesy takes an origin of convenience (a latitude and longitude) near where the vehicle will be operated. Using this datum, UTMGeodesy can convert between (latitude,longitude) points and (X,Y) points, where X and Y are defined as the distance in Eastings and Northings, respectively from the datum point.
Given \(e_{datum}\) is the UTM eastings value for the datum, and \(e_{vehicle}\) is the UTM eastings value for the vehicle, the X position of the vehicle ( \(x_{vehicle}\)) is defined as
\(x_{vehicle} = e_{vehicle} - e_{datum}\)
The Y value is computed identically from the UTM Northings ( \(n\)):
\(y_{vehicle} = n_{vehicle} - n_{datum}\)
The AIS system is used by surface boats and ships to broadcast position and other data via radio. The AIS protocol is based around NMEA-0183 serial messages. The GPSD page on AIS has lots of helpful information.
Goby can decode and encode a subset of the AIS serial messages to and from the goby::util::ais::protobuf::Voyage and goby::util::ais::protobuf::Position protocol buffers messages.
Decode (uses libais) using goby::util::ais::Decoder:
Encode using goby::util::ais::Encoder:
Because Goby is designed first and foremost as an engineering testbed and scientific research architecture, comprehensive logging is important for debugging both at runtime and post-mission. Thus, Goby provides a logging utility (goby::glog) based on C++ STL streams that provides highly configurable runtime (i.e. terminal window) and/or post-mission (text log file) logging. The syntax inside the code should be familiar to any C++ programmer, as any std::ostream functions can be used.
A simple example:
The is
function both labels a sentence as a particular verbosity level (debug3 is the lowest (typically not shown), die is the highest (always shown)), and also returns a boolean: true
if this verbosity level is enabled, false otherwise. By virtue of short-circuiting of the &&
operator, the rest of the stream is not evaluated (and requires no CPU overhead) if the debug output at a particular level is disabled.
goby::glog extends std::ostream to provide a number of extra logging features. This is generally the preferred logger (instead of std::cout, etc.) for goby applications. Use goby::glog in the same way you would use std::cout or a std::ofstream object. These features include:
Note: When using the Goby middleware functionality, you will likely wish to use goby_logger
in addition to goby::glog to provide a more readily post-processed log file. goby::glog is primarily for human inspection of debug logs (think /var/log
) whereas goby_logger
files is more applicable for data processing using MATLAB, Python, etc.
The goby::glog debug logging tool provides:
The best way to get used to goby::glog is to compile and play with the flexostream_simple.cpp example.
A handful of examples:
Graphical user interface logger mode:
Simultaneous terminal window and file logging:
Writes the following to test.txt:
The default use of goby::glog is not thread safe. To enable thread-safe access (uses a mutex lock/unlock for each call from goby::util::FlexOstream::is to std::endl or std::flush), set (before any concurrent access):
When using goby::glog in this mode, it is essential that every call to goby::util::FlexOstream::is (this locks the mutex) be terminated by a std::flush or std::endl (which unlocks the mutex).
Note: linebasedcomms will be deprecated at some point in favor of the more full-featured I/O in goby-middleware (subclasses of goby::middleware::io::IOThread, e.g. goby::middleware::io::SerialThreadLineBased). Linebasedcomms will be included in Goby until all the existing modem drivers have been converted.
Linebasedcomms provides a common interface (goby::util::LineBasedInterface) for line-based (defined as blocks of text offset by a common delimiter such as "\\r\\n" or "\\n") text communications over a TCP or serial connection. Linebasedcomms uses the boost::asio library to perform the actual communications.
You should create the proper subclass for your needs: