![]() |
VR-Link API Documentation for HLA Evolved
|
Talk is a minimal VR-Link application.
The program simulates the flight of an F18 aircraft. The program begins by sending a fire PDU or HLA fire interaction. Then, the F18 flies north for 10 seconds, updating its position by sending DIS entity state PDUs or HLA attribute updates.
This example is an extremely simplified version of the F18 example. It publishes a stripped down aircraft. The published data can be viewed by the Listen example.
This example builds and runs in DIS, HLA1.3, HLA1516, and HLA1516e because we use the VR-Link Protocol Independent API.
Like the listen-only example, this program creates a DtExerciseConn to provide an interface to the RTI or DIS network.
We define the entity type the F18 will use.
To be visible to other applications in the exercise, each locally-simulated entity requires a DtEntityPublisher. The entity publisher manages the generation of messages for this particular entity. It provides an entity state repository where you can set state values, and a tick() function, which causes state information to be sent to the network if necessary.
It sets up a pointer to the entity state repository, then creates a topographic view on that repository. This lets us set the entity's positional data using topographic coordinates, rather than the default geocentric coordinates. (The coordinates are hard-coded for this example.) We show an example of storing a non-positional state value in the repository.
The example sends an interaction. You can send the interaction using the exercise connection's sendStamped() function.
You can use sendStamped() to send state updates, but it is preferable to let the entity publisher send state updates for you, using data in the entity state repository.
The main loop executes twenty times per second for ten seconds. As in the listen-only example, this program sets VR-Link simulation time at the start of each iteration.
While this program's main purpose is to demonstrate the sending of data to the network, it is not a true send-only application. Incoming data is also processed with the drainInput() call. This call is required for HLA, because this is where we tick the RTI.
The program updates the F18's positional data in its entity state repositoryentity state repository and ticks the entity publisher to send the updated data onto the network. It sets topographic coordinates through a view, which VR-Link converts to geocentric coordinates.
Then, the only remaining tasks are to increment the F18's position, increment the simulation time, and sleep until it is time to begin the next iteration.
//******************************************************************** // Copyright (c) 2007 MaK Technologies, Inc. // All rights reserved. //******************************************************************** #include <vl/exerciseConn.h> #include <vl/exConnInit.h> #include <vl/topoView.h> #include <vl/entityPub.h> #include <vl/entitySR.h> #include <vl/fireInter.h> #include <vlpi/EntityTypes.h> #include <vlutil/vlProcessControl.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"); #if DtHLA_1516_EVOLVED appInit.setFederateType("TALK Example"); #endif // 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); DtEntityType f18Type(DtPlatform, DtPlatformDomainAir, DtUnitedStates, DtFighter, DtF18, 0, 0); // Create an entity publisher for the entity we are simulating. DtEntityPublisher entityPub(f18Type, &exConn, DtDrDrmRvw, DtForceFriendly, DtEntityPublisher::guiseSameAsType()); // Hold on to the entity's state repository, where we can set data. DtEntityStateRepository *esr = entityPub.entityStateRep(); // 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); DtVector velocity(20, 0, 0); // Send a Fire Interaction. DtFireInteraction fire; fire.setAttackerId(entityPub.globalId()); exConn.sendStamped(fire); // Main loop DtTime dt = 0.05; DtTime simTime = 0; while (simTime <= 10000.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 + 100; simTime += dt; // Wait till real time equals simulation time of next step. DtSleep(simTime - clock->elapsedRealTime()); } } DtCATCH_AND_WARN(std::cout); return 0; }