coreDS™ – Implementation sample

As a test case for coreDS™ we’ve decided to create a plugin for the Flight simulator X-Plane (www.x-plane.com).

Excluding the time spent learning the X-Plane API – and learning how to fly a plane – we’ve spent a total of one hour to create a full-blown HLA and DIS integration for X-Plane using coreDS™. Let me show you how.

1. We first defined which data (in and/or out) will be exchanged with the other simulator. To keep it simple, let’s focus on “latitude”, “longitude” and “elevation”. For the full list of exposed  properties by the X-Plane distributed simulation plugin refers to the user manual.

2. We define a global object to handle communication with our distributed simulation engine:

CDSConnection mDSManager;

Let’s focus on the GUI integration and data mapping for a moment.

3. Then we register the name of the properties we want to exchange:

std::map<std::string, std::set< std::string > > lOutputObjectVariables;
lOutputObjectVariables["LocalAircraft"].insert("latitude");
lOutputObjectVariables["LocalAircraft"].insert("longitude");
lOutputObjectVariables["LocalAircraft"].insert("elevation");

This means that your simulator supports sending an object of type “LocalAircraft” with the properties “latitude”, “longitude” and “elevation”. These properties are only strings and they are used by the coreDS™ GUIs to allow a direct mapping between the simulation properties and HLA or DIS properties.

4.  The next step is to configure our connection with the RTI. This can be done manually but since the coreDS™ comes with GUI let’s use them.

showUI(lSelectedConfiguration, ...);

 

ConfigurationSelector

 

From there you can create a new connection or edit an existing one.

 

FederateConfig

All you have to do is to fill out the forms and configure the mapping.

Mapping

This is where the magic happens. coreDS™ has been designed to be FOM agile. This means  you can change the FOM file at run time. The name of the properties you want to exchange are displayed. You can assign a property to a HLA attribute. You can also hard code a value (e.g. you may want a value to be constant).

The path to the configuration file will then be saved in “lSelectedConfiguration”. The configuration path will be passed to the coreDS™ initialize function.

Now, let’s see how we connect the dots.

5. We are now ready to initialize a connection with the RTI

std::map<std::string, std::string> mDSIMParameters;
mDSIMParameters["LogError"] = EnableLogging ? "1" : "0";
mDSIMParameters["LogErrorWindow"] = EnableLoggingToWindow ? "1" : "0";
mDSIMParameters["LogErrorPath"] = logFilePath;
mDSIMParameters["ReloadScriptEachUse"] = ReloadScriptEachUse ? "1" : "0";
mDSIMParameters["EnableScripting"] = EnableScripting ? "1" : "0";
mDSIMParameters["EnableDebugging"] = EnableDebugging ? "1" : "0";

try
{
     mDSimManager.init(std::string(lSelectedConfiguration)).c_str(), mDSIMParameters);
}
catch(std::exception &e)
{
     std::cout << e.what() << std::endl;
}

 

At this point X-Plane is connected to the federation. The last step is to update the data.

6.  Updating the values

std::map<std::string, std::string> iDataStruct;

iDataStruct[“longitude”] = "values for Xplane";
iDataStruct[“latitude”] = "values for Xplane";
iDataStruct[“elevation”] = "values for Xplane";
mDSimManager.updateObject(“MyXplane”, “LocalAircraft”, iDataStruct);

mDSimManager.step(); // Step, time advance request and receive callbacks

The first parameter to updateObject must be unique and represents a single entity of your object. You must keep the same unique name for the duration of the object lifetime. The second parameter is the object type defined in your OutputObjectVariables, finally, a map of the data to be sent. On the first call, the object will me created in the federation (or the CreateObject pdu will be sent).

7.  The “On data Updated” line in the mapping table allows to bind a LUA (LUA is a fast scripting language, more info at www.lua.org) script to a value. Each time the value is updated the script is called. In our case, X-Plane sends long/lat/alt values but HLA prefers geocentric coordinates. We can use LUA to do the conversion without adding complexity to the C++ side.

Remember, coreDS™ has been designed for fast HLA/DIS integration and FOM agility. You can always tweak the mapping, use the LUA scripts to do whatever you want without – ever – having to recompile your application. Defines what you want to exchange and you are done.

Curious about using the LUA scripting engine? Take a look here.

Enjoy!