Making a Global Positioning Sensor

Introduction

The purpose of this tutorial is to demonstrate how to use the OpenJAUS SDK in the development of a JAUS Global Position Sensor (GPOS). Additionally a client of that sensor will be developed to demonstrate the behavior and capabilities of the GPOS service.

JAUS Global Position Sensor

The GPOS is a very common service in JAUS systems. Its purpose is to provide the current global position of the platform to other services throughout the platform and various controller like an Operator Control Unit (OCU). The GPOS does this in the global coordinate system using Latitude and Longitude. The message set of the GPOS service is defined in the JAUS Mobility Service Set (AS-6009) and is outlined below:

  • Set Global Pose
  • Set Geomagnetic Property
  • Query Global Pose
  • Query Geomagnetic Property
  • Report Global Pose
  • Report Geomagnetic Property

As can be seen above, the GPOS is a relatively simple service. In terms of its statemachine, the GPOS service is also simple. It inherits from the Access Control service which is part of the JAUS Core Service Set (AS-5710a).

GposDemo


The GposDemo is a simple implementation of the GPOS Service. The GposComponent is implemented by extending the skeleton component in openjaus::mobility::GlobalPoseSensor

First we define our GposComponent which extends the GlobalPoseSensor defined in the OpenJAUS SDK library. 

class GposComponent : public openjaus::mobility::GlobalPoseSensor
{
public:
    mobility::ReportGlobalPose reportGlobalPose;
    mobility::ReportGeomagneticProperty reportGeomagneticProperty;
 
    GposComponent() :
        GlobalPoseSensor(),
        reportGlobalPose(),
        reportGeomagneticProperty()
    {
        name = "GposDemo";
        this->reportGeomagneticProperty.setMagneticVariation_rad(1.0);
 
        this->reportGlobalPose.setLatitude_deg(34.5);
        this->reportGlobalPose.setLongitude_deg(-80.04);
        this->reportGlobalPose.setAltitude_m(100);
        this->reportGlobalPose.setRoll_rad(0.5);
        this->reportGlobalPose.setPitch_rad(-0.1);
        this->reportGlobalPose.setYaw_rad(0.1);
 
        publish(&reportGlobalPose);
    }

Most the above is very straighforward, the data of the ReportGeomagneticProperty and ReportGlobalPose messages is initialized. In a real-world GPOS component a thread or some other run-time mechanism would be created to populate these values with the latest from the GPS sensor or other positioning system. Of particular interest is the highlighted line, #36. On this line the bool publish(Message *message) funtion is used. This function registers the given message with the underlying Events service. This allows the Event service to respond properly to Create Event requests for the ReportGlobalPose message.

The next part of the GposComponent is implementation of the virtual functions functions from the GlobalPoseSensor base class. Message callbacks are implemented as get<Message> where the query message is passed in as a parameter. This allows the component to respond appropriately. It is important to note that any state conditions and guard conditions are already handled in the background by the OpenJAUS library. Therefore the message callback is only executed when the response is needed by the service (this could be a query or an event trigger). the next two functions, updateGlobalPose and updateGeomagneticProperty are used to set the appropriate values by using the SetGlobalPose and SetGeomagneticProperty messages. Lastly, the guard conditions are implmented, isControllingCmpt. This function is overloaded, once for each source message in which this guard is used.

GposClientDemo



The GposClientDemo is designed to give an example of how to build a component which would be a client to the GPOS component. This simple example shows user how to do common activities within the OpenJAUS framework such as: finding a service by URI value, sending GPOS query messages, creating and stopping a periodic event and taking and releasing control of the GPOS component. These examples are shown below:

Finding a GPOS Service

The Discovery service automatically exchanges system information with other JAUS components and maintains a SystemTree of components and services. Finding a particular service on the System Tree is easily done using the lookupService(char *) method of the SystemTree class. This returns a vector of JausAddress objects with the JausAddress of each matching service in the SystemTree.
gposList = component.getSystemTree()->lookupService("urn:jaus:jss:mobility:GlobalPoseSensor");
std::cout << "GPOS Services (" << gposList.size() << "):\n";
for(size_t i = 0; i < gposList.size(); i++)
{
    std::cout << "\t" << gposList.at(i).toString() << std::endl;
}

Sending a Query Message

Sending a query message is also very simple. Create the message to be sent, populate it with the requiste data and send it using the sendMessage function.
mobility::QueryGlobalPose *query = new mobility::QueryGlobalPose();
query->setQueryPresenceVector(65535);
query->setDestination(gposList.at(0));
component.sendMessage(query);

Subscribing and Unsubscribing to a Periodic Event

Creating a periodic event is something done very often in the JAUS architecture. This allows a component to create a standing query to another service's information at a particular update rate. Creation and management of the periodic event is handled by the Event service which is implemented in the OpenJAUS library. Creation is done using the subscribePeriodic(address, message, rateHz) function as shown below. This returns a unique Event Id which is used for futher interaction with the Event service such as unsubscribing to an event using the unsubscribe(id) method.
mobility::QueryGlobalPose *query = new mobility::QueryGlobalPose();
query->setQueryPresenceVector(65535);
subscriptionId = component.subscribePeriodic(gposList.at(0), query, 1.0);
if(component.unsubscribe(subscriptionId))
{
    subscriptionId = 0;
}

Requesting and Releasing Control of a Service

Requesting control of another component is done using the requestControl method. Similarly releasing control is done using the releaseControl method.
component.requestControl(gposList.at(0), processControlResponse);
component.releaseControl(gposList.at(0));
 
 
 

0 Comments

Add Comment

Copyright © 2012 OpenJAUS. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.