VR-Link API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F18 Example

The f18 program simulates a simple HLA or DIS vehicle.

By default, that vehicle is n F/A18 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 and react to detonations.


The F18 is composed of two major classes:

The F18 example is contained in several major files:

The main application:

/****************************************************************************
* Copyright (c) 2017 VT MAK
* All rights reserved.
****************************************************************************/
#include "multiF18Init.h"
#include <stdlib.h>
#include <iostream>
#ifndef _WIN32
#include <sys/socket.h>
#endif
// *****************************************************************
// *************************** GLOBALS *****************************
// *****************************************************************
DtTime timeOutInterval = 12.0; // seconds
DtTime timeThreshold = 5.0; // seconds
double translationThreshold = 1.0; // meters
double rotationThreshold = DtDeg2Rad( 3.0 ); // radians
// Static functions
static int keybrdTick( );
#if VXWORKS
#define main realMain
#endif
// *****************************************************************
// *************************** MAIN *******************************
// *****************************************************************
int main( int argc, char* argv[] )
{
// Used for error handling
DtINIT_MINIDUMPER( "Parallel-F18" );
try
{
// get the PID so we can run multiple F18's
int pid = DtGetPid();
DtString pidStr( pid );
// get the Application name
DtString appName = "VR-Link F18 " + pidStr;
DtF18Initializer initializer( argc, argv, appName );
#if DtDIS
// Set the default DIS version
initializer.setDisVersionToSend( 7 );
#else
// Set the default FED File, executable, and version
initializer.setFedFileName( DtDefaultRpr2Fom );
initializer.setExecName( "MAK-RPR-2.0" );
initializer.setRprFomVersion( 2.0 );
initializer.setRprFomRevision( 1 );
#endif
initializer.setApplicationNumber( pid );
DtString defaultF18Name( initializer.f18Name() );
defaultF18Name += " " + pidStr;
initializer.setF18Name( defaultF18Name );
#ifdef DtHLA
initializer.setFederateType( defaultF18Name );
#endif
initializer.parseCmdLine();
// Create an instance of our simulator
DtMultiVehicleFed simulator;
// Set up default static values
// This is the only DIS specific code in this file.
#if DtDIS
DtEntityPublisher::setDfltTimeThreshold( timeThreshold );
// MUST use async I/O in parallel mode for thread saftey
// Sync I/O in DIS not yet thread safe
initializer.setUseAsynchIO(true);
#endif
// Connect to the exercise or RTI
simulator.initializeExConn(DtTime(timeThreshold), &initializer);
// initialize the fleet
simulator.initializeFleet(0, initializer.count(), &initializer);
// Simulation loop
int forever = 1;
while( forever ) // to keep cfront quiet
{
// process incoming data
simulator.drainInput(initializer.deltaTime());
if ( keybrdTick( ) == 0 ) break;
// Perform simulation for the current time frame
simulator.simulate();
// Publish simulation changes
simulator.publish();
// wait for real time to catch up to simulated time
simulator.sleep(initializer.deltaTime());
}
simulator.dismantleFleet(); // Dismantle the fleet of vehicles
simulator.dismantleExConn(); // Dismantle exercise connection
}
DtCATCH_AND_WARN(std::cout);
return 0;
}
int keybrdTick( )
{
char* keyPtr = DtPollBlockingInputLine();
if ( !keyPtr ) return 1; // no input
switch( *keyPtr )
{
case 'q':
case 'Q':
return 0;
default:
std::cout << "Unrecognized command key " << *keyPtr << std::endl;
break;
}
return 1;
}

Document ID: Generated on Mon Apr 8 04:49:21 EDT 2019 from SVN revision 197403
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)