This is a time constrained version of the VR-Link Talk-Listen example.
HLA Time Regulating Talk Example
Time Regulation
This program is a time regulating version of TalkRPR. It gets an initial time when time regulation is enabled and then advances for about 10 time units. Movement of the entity is not even. It sends one interaction. Time regulation is turned off when the federate is ready to leave; this will allow time constrained federates to advance at that point. It is possible, and usually desirable, to move time forward as the simulation progresses. However, we choose not to here.
HLA Time Constrained Listen Example
Time Constraint
This program is a slightly modified version of Listen example with HLA time management enabled.
In time managed mode, do not use the RPR time stamp in User tag. If this option is True (the default), the FedTime supplied in a reflect attribute callback is overwritten in the DtStateMsg by the timestamp in the RPR User Tag field. This means that the updated attributes are applied to the state repo with the current simTime, or with the RPR User tag time, depending on relative time mode or absolute. This will in turn cause bad dead reckoning values when querying the state repo for location, for example.
In time managed mode, set the exercise connection timestamp type to Absolute. This will tell the decoders to use the time stamp value contained in the reflect attribute update message. If this is not enabled, the timestamp will be ignored and the sim time at time of receipt will be used instead.
After we have initialized the exercise connection, we need to register for two callbacks to:
- let us know when time moves forward as we will be lock step and
- let us know that we have become time constrained We also need to notify the RTI that we wish to be time constrained and enable this in the RTI Ambassador.
Time Managed Example Code
HLA Time Regulating Talk Example Code
#ifdef DtHLA
#if DtHLA_1516
#if DtHLA_1516_EVOLVED
#include <RTI/time/HLAfloat64Time.h>
#include <RTI/time/HLAfloat64Interval.h>
#else
#include <RTI/logicalTimeImpl.h>
#include <RTI/logicalTimeIntervalImpl.h>
#endif
#else
#include <fedtime.hh>
#endif
#if DtHLA_1516
#else
void timeAdvanceRequestCb(const RTI::FedTime &, void *);
void timeRegulationEnabledCb(const RTI::FedTime &, void *);
#endif
bool theTimeRegOn(false);
bool theTimeMoved(false);
#if DtHLA_1516
#if DtHLA_1516_EVOLVED
HLAfloat64Time theGlobalFedTime;
const HLAfloat64Interval theLookAhead(2.0);
const HLAfloat64Interval theFedTimeAdvance(0.5);
#else
LogicalTimeImpl theGlobalFedTime;
const LogicalTimeIntervalImpl theLookAhead(2.0);
const LogicalTimeIntervalImpl theFedTimeAdvance(0.5);
#endif
#else
RTIfedTime theGlobalFedTime;
const RTIfedTime theLookAhead(2.0);
const RTIfedTime theFedTimeAdvance(0.5);
#endif
int main( int argc, char* argv[] )
{
appInit.setExecName( "MAK-One-2025" );
appInit.setRprFomVersion( 2.0 );
appInit.setRprFomRevision( 1 );
#ifdef DtHLA_1516_EVOLVED
std::vector<DtString> fomModules;
std::vector<DtString> fomModuleFromCommandLine;
appInit.fomModules(fomModuleFromCommandLine);
fomModules.push_back("NETN-Physical.xml");
fomModules.insert(fomModules.end(), fomModuleFromCommandLine.begin(), fomModuleFromCommandLine.end());
appInit.setFomModules(fomModules);
#endif
appInit.parseCmdLine();
DtInfo <<
"Time Management examples require attributes in FOM to be set to TimeStamp order." << std::endl;
#if DtHLA_1516
#else
#endif
while(!theTimeRegOn)
{
}
double refLongitude =
DtDeg2Rad(-121.326577);
DtTopoView topoView(esr, refLatitude, refLongitude);
topoView.setLocation(position);
topoView.setVelocity(velocity);
#if DtHLA_1516
DtTime timeAdvanceInterval = theFedTimeAdvance.getInterval();
#else
DtTime timeAdvanceInterval = theFedTimeAdvance.getTime();
#endif
#if DtHLA_1516
DtTime lookahed = theLookAhead.getInterval();
DtTime simTime = theGlobalFedTime.getTime() + lookahed;
#else
DtTime lookahed = theLookAhead.getTime();
DtTime simTime = theGlobalFedTime.getTime() + lookahed;
#endif
DtInfo <<
"\nSending Interaction at Time: " << simTime <<
"\n\n";
int updateCount = 0;
DtTime endTime = simTime + 10.0;
while (simTime <= endTime)
{
break;
if (theTimeMoved)
{
theTimeMoved = false;
DtTime dt = simTime - lastTime;
position[0] += velocity[0] * dt;
position[1] = simTime;
position[2] = updateCount++;
topoView.setLocation(position);
topoView.setVelocity(velocity);
DtInfo <<
"Fed Time: " << theGlobalFedTime.getTime()
<< " Sim Time: " << simTime
<< " Pos: " << topoView.location().string() << '\n'
<< "--------" << std::endl;
lastTime = simTime;
simTime += timeAdvanceInterval;
#if DtHLA_1516
#if DtHLA_1516_EVOLVED
HLAfloat64Time reqTime(theGlobalFedTime);
#else
LogicalTimeImpl reqTime(theGlobalFedTime);
#endif
reqTime = theGlobalFedTime;
reqTime += theFedTimeAdvance;
DtInfo <<
"requesting time: " << (theGlobalFedTime.getTime() + theFedTimeAdvance.getInterval()) << std::endl;
#else
DtInfo <<
"requesting time: " << (theGlobalFedTime.getTime() + theFedTimeAdvance.getTime()) << std::endl;
#endif
}
}
delete f18Type;
delete entityPub;
return 0;
}
void timeAdvanceRequestCb(
#if DtHLA_1516
#else
const RTI::FedTime &aTime,
#endif
void *userData)
{
theGlobalFedTime = aTime;
theTimeMoved = true;
DtInfo <<
"Time Advance Grant to: " << theGlobalFedTime.getTime() << std::endl;
}
void timeRegulationEnabledCb(
#if DtHLA_1516
#else
const RTI::FedTime &aTime,
#endif
void *userData)
{
theGlobalFedTime = aTime;
theTimeRegOn = true;
theTimeMoved = true;
DtInfo <<
"\nTime Regulation Enabled at time: " << theGlobalFedTime.getTime() <<
"\n\n";
}
#else // !DtHLA
#include <iostream>
int main()
{
std::cout << "Time Management Is only available in HLA" << std::endl;;
return 0;
}
#endif // !DtHLA
HLA Time Constrained Listen Example Code
#ifdef DtHLA
#if DtHLA_1516
#if DtHLA_1516_EVOLVED
#include <RTI/time/HLAfloat64Time.h>
#else
#include <RTI/logicalTimeImpl.h>
#endif
#else
#include <fedtime.hh>
#endif
#include <iostream>
#if DtHLA_1516
#else
void timeAdvanceRequestCb( const RTI::FedTime &, void * );
void timeConstrainedEnabledCb( const RTI::FedTime &, void * );
#endif
#ifdef DtHLA_1516
#ifdef DtHLA_1516_EVOLVED
HLAfloat64Time theFedTime;
const HLAfloat64Time theFedTimeAdvance( 0.25 );
#else
LogicalTimeImpl theFedTime;
const LogicalTimeImpl theFedTimeAdvance( 0.25 );
#endif
#else
const RTIfedTime theFedTimeAdvance( 0.25 );
RTIfedTime theFedTime;
#endif
bool theTimeConstraintOn = false;
bool theTimeMoved = false;
int main( int argc, char* argv[] )
{
appInit.setExecName( "MAK-One-2025" );
appInit.setRprFomVersion( 2.0 );
appInit.setRprFomRevision( 1 );
appInit.parseCmdLine();
DtInfo <<
"Time Management examples require attributes in FOM to be set to TimeStamp order." << std::endl;
DtInfo <<
"Waiting for Time Constraint Grant." << std::endl;
while ( !theTimeConstraintOn )
{
}
#if DtHLA_1516
#if DtHLA_1516_EVOLVED
HLAfloat64Time lastTime( -10 );
#else
LogicalTimeImpl lastTime( -10 );
#endif
#else
RTIfedTime lastTime( -10 );
#endif
int forever = 1;
while ( forever )
{
break;
if ( theTimeMoved )
{
theTimeMoved = false;
#if DtHLA_1516
#if DtHLA_1516_EVOLVED
HLAfloat64Time reqTime;
#else
LogicalTimeImpl reqTime;
#endif
reqTime = theFedTime.getTime() + theFedTimeAdvance.getTime();
#else
theFedTimeAdvance );
#endif
<< ( theFedTime.getTime() + theFedTimeAdvance.getTime() )
<< std::endl;
if ( first )
{
double refLongitude =
DtDeg2Rad( -121.326577 );
DtTopoView topoView( esr, refLatitude, refLongitude );
<< theFedTime.getTime()
<< " Position: " << topoView.location().string() << std::endl;
}
}
}
return 0;
}
void timeAdvanceRequestCb(
#if DtHLA_1516
#else
const RTI::FedTime &aTime,
#endif
void *userData )
{
theFedTime = aTime;
theTimeMoved = true;
DtInfo <<
"Time Advance Grant to: "
<< theFedTime.getTime() << std::endl;
}
void timeConstrainedEnabledCb(
#if DtHLA_1516
#else
const RTI::FedTime &aTime,
#endif
void *userData )
{
theFedTime = aTime;
theTimeConstraintOn = true;
theTimeMoved = true;
DtInfo <<
"Time Constrained Enabled at time: "
<< theFedTime.getTime() << std::endl;
}
{
DtInfo <<
"------------------------------------\n "
DtInfo <<
"------------------------------------\n" << std::endl;
}
#else // !DtHLA
#include <stdio.h>
int main()
{
DtInfo <<
"Time Management is only available in HLA" << std::endl;
return 0;
}
#endif // !DtHLA