The f18 program simulates a simple HLA or DIS vehicle.
By default, that vehicle is an F/A-18 flying in a circle, just off the coast of California, USA, but you can control the entity type, location and route.
The f18 generates predictable HLA entity update messages (or DIS entity state PDUs), so it is a useful tool for debugging applications that receive and interpret these messages. It can also fire munitions, react to detonations, enable/disable IFF Systems, and send lethal interactions.
Major Components of the F18 Example
The F18 is composed of five major classes:
The Vehicle Sim Class and subcomponents
The class DtVehicleSim is responsible for simulating the Aircraft. This class directly handles modeling the general characteristics (e.g., entity type and appearance) and spatial representation (position, velocity, accleration, and orientation). It uses separate component classes to model warfare (fire/detonate), emitter, and IFF functionality - DtWarfareComponent, DtEmitterComponent, and DtIffComponent.
The F18 Initialization Class
The DtF18Initializer class is a subclass of VR-Link's DtVrlApplicationInitializer. This class processes the command line and reads the F18's mtl file.
VR-Link Advanced Configuration
The F18 Config Example Code config.cxx serves an an example of how to re-configure VR-Link to interpret FOM attributes and parameters differently. Specifically, after calling the configVrl function on a DtExerciseConn, a VR-Link-based application will assume that the "Position" atttribute of the "BaseEntity" object class (and its subclasses) should be encoded in outgoing messages and interpreted in incoming messages as three doubles in the order: Z, Y, X, rather than the standard X, Y, Z. The same will be true for the "FiringLocation" parameter of the "WeaponFire" interaction.
To demonstrate modifying the FOM to replace existing attributes or parameters, you can edit the .fed file to replace "Position" and "FiringLocation" with different attribute and parameter names, such as "ReversePosition" and "ReverseFiringLocation". If you do this, you will need to replace the names in this file as well (in the calls to addAttributeEncoder, addAttributeDecoder, addParameterEncoder and addParameterDecoder), so that the encoding and decoding functions will be associated with the correct parameter and attribute names.
This file is commented out and not part of the default f18. To add this functionality, compile with DtReverse defined.
How to Run the Example
- Launch 2 F18 examples from your VR-Link install's bin64 directory using the same protocol.
- To toggle enabling and disabling of Emitters, press the 'e' key in the F18 console application.
- To change emitter beam scan data for this aircraft, press the 'd' key.
- To toggle enabling and disabling of IFF, press the 'i' key.
- To toggle enabling and disabling of Lethal IFF Interrogation, press 'l' key.
- To send an interrogation of Mode 5, press the '5' key.
- To send a Lethal IFF Interaction, press the 's' key.
- To fire munitions at a nearby target, press the 'f' key.
- For usage information, press the 'h' key.
- To exit, press the 'q' key.
- Note
- To send any interrogation, the IFF System for the aircrafts must be enabled. Lethal Interrogation will only force a Mode 5 Reply, regardless of Mode 5 IsOn attribute status. Interrogations will only provide transponder information for Modes included in the interrogation whose isOn attribute is set to true.
Example Code
Main Application
#include <stdlib.h>
#include <iostream>
#ifndef _WIN32
#include <sys/socket.h>
#endif
DtTime timeOutInterval = 12.0;
double translationThreshold = 1.0;
static int keybrdTick( );
#if VXWORKS
#define main realMain
#endif
int main( int argc, char* argv[] )
{
try
{
DtString appName =
"VR-Link F18 " + pidStr;
#if DtDIS
initializer.setDisVersionToSend( 7 );
#else
#endif
initializer.parseCmdLine();
initializer.setApplicationNumber( pid );
DtString defaultF18Name( initializer.f18Name() );
defaultF18Name += " " + pidStr;
initializer.setF18Name( defaultF18Name );
#ifdef DtHLA
initializer.setFederateType( "Parallel F18" );
initializer.setFederateName(defaultF18Name);
#endif
#if DtDIS
DtEntityPublisher::setDfltTimeThreshold( timeThreshold );
initializer.setUseAsynchIO(true);
#endif
#ifdef DtHLA
std::cout <<
"[" << clock->
elapsedRealTime() <<
", 0] Initializing" << std::endl;
#endif
DtTime frameTime = initializer.deltaTime();
#ifdef DtHLA
std::cout <<
"[" << clock->
elapsedRealTime() <<
", 0] Initialized" << std::endl;
#endif
int forever = 1;
double outputInterval = initializer.outputInterval();
#ifdef DtHLA
std::cout <<
"[" << clock->
elapsedRealTime() <<
", 0] Executing" << std::endl;
#endif
unsigned long frameCount = 1;
double totalDrainDuration = 0.0;
double totalSimDuration = 0.0;
double totalPubDuration = 0.0;
double totalIdle = 0.0;
double totalFrameDuration = 0.0;
int numberFrameOverflows = 0;
double totalOverflow = 0.0;
std::cout << std::fixed;
while( forever )
{
dt = startTime - lastTime;
totalDrainDuration += drainDuration;
totalSimDuration += simDuration;
totalPubDuration += pubDuration;
totalFrameDuration += frameDuration;
if (frameDuration < frameTime)
{
idle = frameTime - frameDuration;
totalIdle += idle;
dt = frameTime;
}
else
{
dt = frameDuration;
idle = -1.0;
numberFrameOverflows++;
totalOverflow += frameDuration - frameTime;
}
if (outputInterval <= 0.0 || outputTime < startTime)
{
std::cout <<
"[" << std::setprecision(2) << simulator.
simTime() <<
", " << frameCount <<
"] #entities: " << simulator.
numberRemoteEntities()
<< " total=" << std::setprecision(6) << frameDuration << "(" << totalFrameDuration / frameCount << ")"
<< " idle=" << idle << "(" << totalIdle/frameCount << ")"
<< " drain=" << drainDuration << "(" << totalDrainDuration / frameCount << ")"
<< " sim=" << simDuration << "(" << totalSimDuration / frameCount << ")"
<< " pub=" << pubDuration << "(" << totalPubDuration / frameCount << ")"
<< " #FO=" << numberFrameOverflows << "(" << (numberFrameOverflows > 0 ? totalOverflow/numberFrameOverflows : 0) << ")"
<< std::endl;
numberFrameOverflows = 0;
totalOverflow = 0.0;
}
if (idle > 0.0)
{
}
lastTime = startTime;
frameCount++;
}
}
return 0;
}
Vehicle Sim Class and subcomponents
Vehicle Sim Header
#pragma once
{
public:
const char* name, const char* markings,
double initHeading, double initTRadius,
double initPitch, bool autoRoll, double initRoll, int num );
public:
protected:
protected:
protected:
protected:
};
Vehicle Sim Source
#include "vehicleSim.h"
#ifndef effZero
#define effZero 1.0E-30
#endif
const char* name, const char* markings,
myTimeSpacing(timeSpacing),
myPublishedObjects(pubContainer),
mySysPub( 0 )
{
#if DtHLA
#elif DtDIS
#else
#error "Please Choose Protocol!"
#endif
myPublishedObjects.add(myEntityPub);
myESR = myEntityPub->entityStateRep();
myESR->setEntityType( type );
myESR->setGuise( type );
myESR->setMarkingText( markings );
myESR->setAlgorithm( alg );
myESR->setEntityId( id );
myTopoView =
new DtTopoView( myESR, refLat, refLon );
myRel = rel;
myFire = 0;
myDetonateTime = 0.0;
myTimeDestroyed = -1.0;
myIsDestroyed = false;
myEmissionsEnabled = false;
myHaveArtParts = haveArtParts;
}
{
}
double initHeading, double initTRad,
double initPitch, bool autoRoll, double initRoll, int num)
{
myTurnRate = ( ( initTRad != 0.0 ) ? ( initSpeed / initTRad ) : 0.0 );
double roll = ( autoRoll ) ?
float cosPsi = cos( psi );
float sinPsi = sin( psi );
float cosPhi = cos( phi );
float sinPhi = sin( phi );
for (int i = 0; i < 3; i++)
{
}
{
}
}
{
for( int i=0; i<3; ++i )
{
}
{
}
}
{
{
}
else
{
}
{
}
else
{
}
}
{
}
{
{
}
}
{
double distance;
{
{
{
DtInfo(
"Direct hit! Going down!\n");
return 1;
}
}
{
{
DtInfo(
"Indirect hit only %s m away! Going down!\n",
return 1;
}
else
{
return 0;
}
}
default:
{
return 0;
}
}
}
{
myTurnRate= 0.0;
}
{
{
DtInfo(
"Emissions enabled.\n");
#if DtHLA
#endif
}
}
{
{
DtInfo(
"Emissions disabled.\n");
}
}
{
{
}
else
{
}
}
{
{
}
}
{
double minDistSqr = 0.0;
entity;
entity = entity->
next() )
{
if ( entity->id() == me ) continue;
entity->entityStateRep()->location(), geocPos );
if ( distSqr < minDistSqr || !nearest )
{
nearest = entity;
minDistSqr = distSqr;
}
}
return nearest;
}
{
if ( nearest )
{
}
}
{
{
return;
}
#if DtHLA
#endif
DtInfo(
"Sending fire interaction\n");
}
{
{
return;
}
det.setMunitionType(sidewinder);
det.setEntityLocation(
DtVector32( 0.0, 0.0, 0.0 ) );
if ( ent )
{
det.setVelocity(velocity);
}
else
{
}
DtInfo(
"Sending detonation interaction\n");
}
{
{
}
}
{
}
{
}
{
}
{
}
Warfare Component Header
#pragma once
{
public:
private:
};
Warfare Component Source
#include "vehicleSim.h"
static double sLethalDetonationRange = 20.0;
static DtTime sMunitionFlightTime = 3.0;
: myOwner(owner)
, myExConn(conn)
, myRel(rel)
, myEntityPub(entPub)
, myESR(esr)
, myFire(nullptr)
, myDetonateTime(0.0)
{
}
{
{
}
}
{
{
return;
}
#if DtHLA
#endif
DtInfo(
"Sending fire interaction\n");
}
{
}
{
{
return;
}
det.setMunitionType(sidewinder);
if (ent)
{
velocity.
setX(difference.
x() / sMunitionFlightTime);
velocity.
setY(difference.
y() / sMunitionFlightTime);
velocity.
setZ(difference.
z() / sMunitionFlightTime);
det.setVelocity(velocity);
}
else
{
det.setVelocity(
DtVector32(0.0, 0.0, 1000.0f / sMunitionFlightTime));
det.setWorldLocation(
DtVector(pos[0], pos[1], pos[2] + 1000.0));
}
DtInfo(
"Sending detonation interaction\n");
}
{
{
}
}
{
std::cout << "Received Detonation!" << std::endl;
{
}
}
{
double distance;
{
{
DtInfo(
"Direct hit! Going down!\n");
return 1;
}
{
if (distance < sLethalDetonationRange)
{
DtInfo(
"Indirect hit only %s m away! Going down!\n",
return 1;
}
else
{
return 0;
}
}
default:
return 0;
}
}
Emitter Component Header
#pragma once
public:
protected:
protected:
};
Emitter Component Source
#include "vehicleSim.h"
: myOwner(owner)
, myExConn(conn)
, myRel(rel)
, myESR(esr)
, myEmitterPub(nullptr)
, myBeam(nullptr)
, myEnabled(false)
{
myRefEmitList->setDiscoveryCondition(emitterSystemDiscoveryCondition, this);
myRefEmitList->addEmitterSystemAdditionCallback(emitterSystemAdditionCallback, this);
myRefEmitList->addEmitterSystemRemovalCallback(emitterSystemRemovalCallback, this);
}
{
{
}
}
{
{
return;
}
DtInfo(
"Emissions enabled.\n");
#if DtHLA
#else
#endif
}
{
{
return;
}
DtInfo(
"Emissions disabled.\n");
}
{
{
}
else
{
}
}
{
{
}
}
{
{
DtInfo(
"Enable Emitters before changing scan data!\n");
return;
}
if (!beamSR)
{
DtInfo(
"Cannot find RadarBeam. Enable Emitters before changing scan data!\n");
return;
}
{
DtInfo(
"Unknown scan pattern type, setting Circle...\n");
break;
DtInfo(
"Circle scan pattern type, setting Sector...\n");
break;
DtInfo(
"Sector scan pattern type, setting Raster...\n");
break;
DtInfo(
"Raster scan pattern type, setting Spiral...\n");
break;
DtInfo(
"Spiral scan pattern type, removing scan data...\n");
break;
}
}
{
}
{
}
{
}
{
}
{
DtInfo(
"Updated Emitter %s\n",
}
{
}
{
}
{
}
{
}
{
}
IFF Component Header
#pragma once
#if DtDIS
#endif
#if DtHLA
#endif
{
public:
protected:
protected:
};
IFF Component Source
#include "vehicleSim.h"
#if DtHLA
#endif
#if DtDIS
#endif
: myOwner(owner)
, myExConn(conn)
, myRel(rel)
, myESR(esr)
, myIffTransponderPub(nullptr)
, myIffInterrogatorPub(nullptr)
, myEnabled(false)
, myLethalEnabled(false)
{
myRefIffList->addIffAdditionCallback(iffAddedCb, this);
myRefIffList->addIffRemovalCallback(iffRemovedCb, this);
#ifdef DtHLA
#elif DtDIS
DtInterrogationInteraction::addIffCallback(
#endif
}
static DtU16 iffCodeFromOctal(
int octalDigits)
{
int shift = 0;
while (octalDigits > 0)
{
result |=
static_cast<DtU16>((octalDigits % 10) << shift);
octalDigits /= 10;
shift += 3;
}
return result;
}
{
}
{
{
return;
}
DtInfo(
"IFF Systems enabled.\n");
#if DtHLA
relPosition,
enableModes,
relPosition,
enableModes,
#else
#endif
#ifdef DtHLA
#elif DtDIS
#endif
#if DtDIS
iffTransponderSr->setLayer3DataAvailable(true);
DtIffAntennaLocationRecord transponderAntennaRecord;
transponderAntennaRecord.setAntennaReferenceNumber(1);
iffTransponderSr->setNumIffRecords(1, 3);
iffTransponderSr->setIffRecord(0, transponderAntennaRecord, 3);
#endif
const DtU8 aircraftId[8] = {
'A',
'A',
'L',
'2',
'6',
'9',
'3', 0};
iffInterrogatorSr->
setEventId(interrogatorEventId);
#if DtDIS
iffInterrogatorSr->setLayer3DataAvailable(true);
DtIffAntennaLocationRecord interrogatorAntennaRecord;
interrogatorAntennaRecord.setAntennaReferenceNumber(1);
iffInterrogatorSr->setNumIffRecords(1, 3);
iffInterrogatorSr->setIffRecord(0, interrogatorAntennaRecord, 3);
#endif
}
{
{
return;
}
DtInfo(
"IFF System disabled.\n");
}
{
{
}
else
{
}
}
{
{
myIffInterrogatorPub->
tick();
myIffTransponderPub->
tick();
}
}
{
{
return;
}
DtInfo(
"Lethal IFF Interrogation enabled.\n");
if (myIffTransponderPub == nullptr)
{
#if DtHLA
std::vector<DtModeType> enableModes = {
DtMode5};
#else
#endif
}
if (myIffInterrogatorPub == nullptr)
{
#if DtHLA
std::vector<DtModeType> enableModes = {
DtMode5};
#else
#endif
}
}
{
if (!myIffTransponderPub || !myIffInterrogatorPub)
{
DtWarn(
"IFF System is not enabled; enter 'i' to enable IFF system .\n");
return;
}
{
DtWarn(
"Reflected IFF System is not enabled; enable IFF system in other console.\n");
return;
}
{
return;
}
#ifdef DtHLA
#elif DtDIS
interrogationInteraction.setSystemID(sysId);
interrogationInteraction.setEmittingEntityID(myIffInterrogatorPub->
globalId());
DtIffAtcNavaidsOperational operat;
operat.setSystemStatus(87);
operat.setInformationLayers(40);
interrogationInteraction.setOperational(operat);
#endif
interModes.
setModesIncluded(
false,
false,
false,
false,
true,
false,
false,
false,
false,
false);
myIffInterrogatorPub->
tick();
myIffTransponderPub->
tick();
DtInfo(
"Sending non-lethal mode 5 interrogation interaction: \n");
DtInfo(
" \n ********************************************************* \n ");
}
{
{
DtInfo(
"Lethal IFF Interrogation disabled.\n");
}
}
{
{
}
else
{
}
}
{
{
DtWarn(
"Toggle Lethal Interrogation before attempting to send a lethal interaction.\n");
return;
}
if (!myIffTransponderPub || !myIffInterrogatorPub)
{
}
{
DtWarn(
"No Reflected IFF System found; enable IFF system in other console.\n");
return;
}
else
{
}
#ifdef DtHLA
#elif DtDIS
interrogationInteraction.setSystemID(sysId);
interrogationInteraction.setEmittingEntityID(emittingEntityId);
DtIffAtcNavaidsOperational operat;
operat.setSystemStatus(87);
operat.setInformationLayers(40);
interrogationInteraction.setOperational(operat);
#endif
interModes.
setModesIncluded(
true,
true,
true,
false,
true,
true,
false,
false,
false,
false);
myIffInterrogatorPub->
tick();
myIffTransponderPub->
tick();
DtInfo(
"Sending lethal interrogation interaction: \n");
}
{
#ifdef DtDIS
{
return;
}
#endif
{
DtInfo(
"\n*********************************************************\n");
DtInfo(
"Received lethal interrogation interaction!\n");
if (myIffTransponderPub == nullptr)
{
}
#ifdef DtHLA
#elif DtDIS
replyInteraction.setEmittingEntityID(myIffTransponderPub->
globalId());
DtIffAtcNavaidsSystemID sysId;
sysId.setSystemType(iffTransponderSr->
systemType());
sysId.setSystemName(iffTransponderSr->
systemName());
replyInteraction.setSystemID(sysId);
#endif
if (myIffTransponderPub)
{
myIffTransponderPub->
tick();
}
if (myIffInterrogatorPub)
{
myIffInterrogatorPub->
tick();
}
DtInfo <<
"\n********************************************************* \n ";
DtInfo <<
"Sending lethal reply interaction: " << std::endl;
DtInfo <<
"\n********************************************************* \n ";
}
else
{
DtInfo(
"\n*********************************************************\n");
DtInfo(
"Received non-lethal interrogation interaction!\n");
if (!myIffTransponderPub)
{
DtWarn(
"No IFF Systems active; enable IFF Systems.\n");
}
else
{
#ifdef DtHLA
#elif DtDIS
replyInteraction.setEmittingEntityID(myIffTransponderPub->
globalId());
DtIffAtcNavaidsSystemID sysId;
sysId.setSystemType(iffTransponderSr->
systemType());
sysId.setSystemName(iffTransponderSr->
systemName());
replyInteraction.setSystemID(sysId);
replyInteraction.setOperational(inter->operational());
#endif
myIffTransponderPub->
tick();
myIffInterrogatorPub->
tick();
DtInfo <<
"Sending non-lethal reply interaction: " << std::endl;
}
}
}
{
#ifdef DtDIS
{
return;
}
#endif
DtInfo(
"\n*********************************************************\n");
: "Received reply to non-lethal interrogation interaction!"))
.c_str());
if (refIffObj == nullptr)
{
DtWarn(
"No Reflected IFF Object found.\n");
}
else
{
{
}
{
}
{
}
{
}
{
}
{
{
}
else
{
DtInfo(
"Mode 5 is OFF, but was not interrogated using lethal mode. No reply.\n");
}
}
{
}
}
}
{
}
{
}
{
}
{
}
{
}
F18 Initializer Class
F18 Initializer Header
#pragma once
{
public:
private:
public:
protected:
protected:
};
F18 Initializer Source
#include <stdio.h>
, myInitialPosition(settings(),
"initialPosition",
DtVector(0.0, 0.0, -1230.0),
, myLispFileName(settings(), "&lispFile", "f18.xml", "LISP File Name" )
, myDeadReckonAlgorithm(settings(),
"deadReckonAlgorithm",
DtDrDrmRvw,
"Dead Reckon Algorithm",
, myInitialTurnRadius(settings(), "initialTRadius", -250.0, "Initial Turn Radius",
, myInitialSpeed(settings(), "initialSpeed", 40.0, "Initial Speed" )
, myEntityTypeString(settings(), "entity&TypeStr", "1:2:225:1:9:0:0", "Entity Type String" )
, myMarkings(settings(), "f18&Markings", "MAK-VRLink-F18", "F18 Markings" )
, myName(settings(), "f18Name", "MAK-F18", "F18 Object Name" )
, myDestroyedToFinalDelay(settings(), "&destroyedToFinalDelay", 20.0,
"Destroyed To Final Delay" )
, myInitialHeading(settings(), "initial&Heading", 180.0, "Initial Heading" )
, myTopoOrigin(settings(), "topo&Origin", "35.699760,-121.326577",
"Topographic Coordinate System Origin" )
, myWorldPosition( settings(),
"worldPos",
DtVector(0.0,0.0,0.0),
, myLethalDetonationRange( settings(), "lethalDetonationRange", 20.0, "Lethal Detonation Range",
, myMunitionFlightTime( settings(), "munitionFlightTime", 3.0, "Munition Flight Time",
, myInitialPitch( settings(), "initialPitch", 0.0, "Initial Pitch",
, myInitialRoll( settings(), "initialRoll", 0.0, "Initial Roll",
, myAutoRoll( settings(), "autoRoll", true, "Auto Roll",
, myEntityNumber( settings(), "entNum", 1, "Entity Number",
, myHaveArtParts( settings(), "haveArtParts", false, "Have Articulated Parts",
, myRefLatitude( settings(), "refLatitude", 35.699760, "Reference Latitude",
, myRefLongitude( settings(), "refLongitude", -121.326577, "Reference Longitude",
, myDeltaTime( settings(), "deltaTime", 0.05, "Delta Time",
, myMtlAutoRoll( 1 )
, myMtlHaveArtParts( 0 )
, myMtlInitialPosition( 0.0, 0.0, -1230.0 )
{
settings().setChangeOnce(true);
}
{
}
{
}
{
}
{
for (
int index = 1; index <
myArgc; ++index )
{
if ( ! strcmp(
myArgv[index],
"-l") || ! strcmp(
myArgv[index],
"--lispFile") )
{
if ( index + 1 < myArgc )
{
break;
}
}
}
{
posVec[2] = -posVec[2];
}
{
if ( numReads > 0 )
{
if ( numReads > 1 )
{
}
}
}
{
}
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
F18 Config Example Code
#if DtHLA
#if DtReverse
RTI::AttributeHandle handle )
{
}
int pairSetIndex )
{
avlist.
getValue( pairSetIndex, (
char*)&netVal, length );
}
RTI::ParameterHandle handle )
{
}
int pairSetIndex )
{
pvlist.
getValue( pairSetIndex, (
char*)&netVal, length );
}
{
addAttributeEncoder( "BaseEntity", "Position",
addAttributeDecoder( "BaseEntity", "Position",
addParameterEncoder( "WeaponFire", "FiringLocation",
addParameterDecoder( "WeaponFire", "FiringLocation",
}
#endif // DtReverse
#endif // DtHLA