VR-Link API Documentation for HLA 4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Evolved Talk-Listen Example

Table of Contents

The Evolved Listen Example

Talk Evolved is a simple Talk VR-Link application which has been extended to take advantage of HLA Evolved Specific functionality. There is virtually no difference between this and the regular Talk example, as the HLA Evolved features are provided automatically by VR-Link.

The Talk Evolved example takes advantage of these features to provide more information.

The Evolved Listen Example

Listen is a simple listen-only VR-Link application which has been extended to take advantage of HLA Evolved Specific functionality.

Implementation

With each iteration of the loop, the program prints an entity's updated, dead-reckoned position in topographic coordinates. If a fire PDU or interaction is detected on the network, the program prints a message showing the entity ID of the attacker.

To exit, press the 'q' key. This example works with the Talk Evolved example.

Connecting to An Exercise

The program creates an exercise connection (DtExerciseConn). This connection serves as the program's interface to an exercise. After it's regular connection features, it then loads an HLA Evolved FOM Module that defines the update rate reduction parameters of the aircraft.

Update Rate Reduction

HLA Evolved allows us to subscribe to an object but only receive a limited subset of updates based on time. In order to do this, one must pass the name of the string defineding update rate reduction in the FOM (in this case "everyFiveSeconds") to the DtReflectedEntityList. VR-Link takes care of the rest.

Tracking Federates

In addition to tracking updates and interactions, HLA Evolved provides a way to access the name of the producing federate. One can access this federate by calling the producingFederate() function available in all objects and interactions in an HLA Evolved exercise. You must enable the conveyProducingFederate FOM switch for this to work.

Talk Listen Evolved Example Code

Talk Evolved Example Code

/****************************************************************************
* Copyright (c) 1992-2025 MAK Technologies, Inc
* All rights reserved.
****************************************************************************/
#include <vl/topoView.h>
#include <iostream>
int main(int argc, char** argv)
{
try
{
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer appInit( argc, argv, "VR-Link Talk" );
// HLA Evolved has both a federate name, which must be unique, and a
// federate type, which does not have to be.
appInit.setFederateType( "Talk Evolved Example" );
// Set the default FED File, executable, and version
appInit.setFedFileName( DtDefaultRpr2Fom );
appInit.setExecName( "MAK-RPR-2.0" );
appInit.setRprFomVersion( 2.0 );
appInit.setRprFomRevision( 1 );
// Process the command line. This will actually set values in the
// DtVrlApplicationInitializer class and should be called before
// creating the DtExerciseConn instance.
appInit.parseCmdLine();
// The DtExerciseConn instance is perhaps the most important class
// in any VR-Link exercise. Think of it as the hub which holds
// everything else together. Technically this instance is what's
// responsible for connecting this federate to another federate via
// a network, or an RTI. After exConn is created, and if no error
// has occurred this simulator will be a live federate.
DtExerciseConn exConn(appInit);
// Create an entity publisher for the entity we are simulating.
DtEntityPublisher entityPub(f18Type, &exConn,
// Hold on to the entity's state repository, where we can set data.
// Create a topographic view on the state repository, so we
// can set position information in topographic coordinates.
double refLatitude = DtDeg2Rad( 35.699760);
double refLongitude = DtDeg2Rad(-121.326577);
DtTopoView topoView(esr, refLatitude, refLongitude);
// We can use the ESR to set state.
esr->setMarkingText("VR-Link");
topoView.setOrientation(DtTaitBryan(0.0, 0.0, 0.0));
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
DtVector position(0, 0, -100);
DtVector32 velocity(20, 0, 0);
// Send a Fire Interaction.
fire.setAttackerId(entityPub.globalId());
exConn.sendStamped(fire);
// Main loop
DtTime dt = 0.05;
DtTime simTime = 0;
while (simTime <= 10.0)
{
// Tell VR-Link the current value of simulation time.
clock->setSimTime(simTime);
// Process any incoming messages.
exConn.drainInput();
// Set the current position information.
topoView.setLocation(position);
topoView.setVelocity(velocity);
// Call tick, which insures that any data that needs to be
// updated is sent.
entityPub.tick();
// Set up for next iteration.
position[0] += velocity[0] * dt;
simTime += dt;
// Wait till real time equals simulation time of next step.
DtSleep(simTime - clock->elapsedRealTime());
}
}
DtCATCH_AND_WARN(std::cout);
return 0;
}

Listen Evolved Example Code

/****************************************************************************
* Copyright (c) 1992-2025 MAK Technologies, Inc
* All rights reserved.
****************************************************************************/
#include <vl/topoView.h>
#include <iostream>
int keybrdTick(void);
void reflectCb( const DtStateMsg& msg, DtHlaObject* obj, void* usr );
void removeObjectCb( DtHlaObject* obj, void* usr );
void discoverObjectCb( DtHlaObject* obj, void* usr );
unsigned int numUpdates = 0;
DtTime initialTime;
bool hasDiscovered = false;
DtString lastProducingFederate;
double updatesPerSecond = 0.0;
// Define a callback to process fire interactions.
void fireCb(DtFireInteraction* fire, void* /*usr*/)
{
std::cout << "Fire Interaction from "
<< fire->attackerId().string() ;
// HLA Evolved provides a way of returning the name of the federate
// that created the object or interaction. Here we print this
// producing federate if it has been provided.
// You must enable the conveyProducingFederate switch for this to work.
DtString producingFederate = fire->producingFederateName();
if ( producingFederate.size() )
{
std::cout << " Federate Name " << producingFederate;
}
std::cout << std::endl;
}
int main(int argc, char** argv)
{
try
{
// Create an exercise conn initializer. This will parse the command
// line, as well as parse an mtl file with the same name as this application.
DtVrlApplicationInitializer appInit(argc, argv, "VR-Link Listen");
// HLA Evolved has both a federate name, which must be unique, and a
// federate type, which does not have to be.
appInit.setFederateType( "Listen Evolved Example" );
// Set the default FED File, executable, and version
appInit.setFedFileName( DtDefaultRpr2Fom );
// Process the command line. This will actually set values in the
// DtVrlApplicationInitializer class and should be called before
// creating the DtExerciseConn instance.
appInit.parseCmdLine();
appInit.addFomModule("updateRate.xml");
// The DtExerciseConn instance is perhaps the most important class
// in any VR-Link exercise. Think of it as the hub which holds
// everything else together. Technically this instance is what's
// responsible for connecting this federate to another federate via
// a network, or an RTI. After exConn is created, and if no error
// has occurred this simulator will be a live federate.
DtExerciseConn exConn(appInit);
// Register a callback to handle fire interactions.
DtFireInteraction::addCallback(&exConn, fireCb, NULL);
// Create an object to manage entities that we hear about
// on the network. This object will use the HLA Evolved feature
// of update rate reduction to only update every five seconds.
try
{
rel = new DtReflectedEntityList(&exConn, DtString("everyFiveSeconds"));
}
catch(...)
{
DtFatal << "Update Rate Reduction failed.\n"
"This may be due to using a lightweight connection,\nor a non-standard compliant RTI.\n";
return -1;
}
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
exConn.addDiscoverObjectCallback( RTI::ObjectClassHandle(), discoverObjectCb, 0 );
int forever = 1;
while (forever)
{
// Check if user hit 'q' to quit.
if (keybrdTick() == -1)
break;
// Tell VR-Link the current value of simulation time.
clock->setSimTime(clock->elapsedRealTime());
// Process any incoming messages.
exConn.drainInput();
// Find the first entity in the reflected entity list.
DtReflectedEntity *first = rel->first();
if (first)
{
// Grab its state repository, where we can inspect its data.
// Create a topographic view on the state repository, so we
// can look at position information in topographic coordinates.
double refLatitude = DtDeg2Rad( 35.699760);
double refLongitude = DtDeg2Rad(-121.326577);
DtTopoView topoView(esr, refLatitude, refLongitude);
DtTime effectiveCurrTime = clock->elapsedRealTime() - initialTime;
updatesPerSecond = ((double)(numUpdates)) / ((double)(effectiveCurrTime));
std::cout << " num updates / second = " << updatesPerSecond ;
// HLA Evolved provides a way of returning the name of the federate
// that created the object or interaction. Here we print this
// producing federate if it has been provided.
// You must enable the conveyProducingFederate switch for this to work.
lastProducingFederate = first->lastProducingFederate();
if ( lastProducingFederate.size() )
{
std::cout << ". Last Update from " << lastProducingFederate ;
}
std::cout << std::endl;
}
// Sleep till next iteration.
DtSleep(1);
}
}
DtCATCH_AND_WARN(std::cout);
return 0;
}
int keybrdTick()
{
char *keyPtr = DtPollBlockingInputLine();
if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q'))
return -1;
else
return 0;
}
#if DtHLA
void reflectCb( const DtStateMsg& msg, DtHlaObject* obj, void* usr )
{
DtExerciseConn* exConn = obj->exerciseConn();
DtClock* clock = obj->exerciseConn()->clock();
DtTime curr = clock->elapsedRealTime();
++numUpdates;
if ( 0 == numUpdates )
{
initialTime = curr;
}
}
void removeObjectCb( DtHlaObject* obj, void* usr )
{
obj->removeRemoveObjectCb( removeObjectCb, 0 );
obj->removePostReflectCb( reflectCb, 0 );
hasDiscovered = false;
}
void discoverObjectCb( DtHlaObject* obj, void* usr )
{
if ( !hasDiscovered )
{
obj->addPostReflectCb( reflectCb, 0 );
obj->addRemoveObjectCb( removeObjectCb, 0 );
}
hasDiscovered = true;
}
#endif

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)