Loclib Loctrace Locana Loceva Publications

Loclib - A location library

Using the package org.pi4.loclib.f350compassfd

You might have noticed that the Location API does not provide an interface for the use of a digital compass. That means that data provided by a compass can not be accessed through the Location API. Below you will find instructions on how to use our communication protocol for the FD-350 compass reference board along with your own software.

General

The front-ending provided by the compass package is basically represented by the singleton class InputOutputHandler in combination with the interface CompassListener and the class CompassBoardReply that represents the actual data and provides methods for extracting it.
InputOutputHandler can be instantiated through the methods getInstance(int) and getInstance(File, boolean).
The package offers three sub-classes of InputOutputHandler of which instances are generated depending on which getInstance method is used and what arguments are specified. The sub classes are:

Finally, a CompassListener object can be added to the InputOutputHandler by using the method addCompassListener(CompassListener).

The CompassListener object offers a method handleCompassBoardReply(CompassBoardReply) that is called everytime a data block is received from the compass. As already mentioned above, the data is stored in objects of the type CompassBoardReply.
The container class CompassBoardReply offers several methods with which the data can be extracted. The methods are as following:


Additional information is provided by the corresponding javadoc.

Example code

        import org.pi4.loclib.f350compassfd;

        public class CompassExample implements CompassListener {
          
          private InputOutputHandler ioHandler;

          public CompassExample() {
            ioHandler = InputOutputHandler.getInstance(3);
            ioHandler.addCompassListener(this);
          }

          // Inherited by the CompassListener interface
          public void handleCompassBoardReply(CompassBoardReply reply) {
            System.out.println(reply.dump());
          }

          public static void main(String[] args) {
            new CompassTest();
          }
        }
    
Praktische Informatik IV | Contact | ©2005-2008 Praktische Informatik IV, University of Mannheim