vsTASKER 7 Tutorial
×
Menu
Index

Publish

  
 
Now, double-click on the publishing FedItem to call its Property Window
 
Here, we can see that Entity Object has been selected and that the three Attributes (State, Position and Identifier) must be mapped somehow with some local variables.
When a Federation (1516 XML) file is loaded, vsTASKER generates an OMT like definitions that can be viewed on the OMT part.
 
Now, let's see what hlaPosition contains, but opening the symbol:
 
vsTASKER will automatically generate OMT Structs and Enums in the header file, so, it is useless to recreate them (as it will generate compilation errors).
So, we know that the header will contain the following structure definition:
 
 typedef struct {
    HLAdouble X;
    HLAdouble Y;
    HLAdouble Z;
    HLAinteger Type;
} hlaPosition;
 
 
 typedef struct {
   hlaPosition   position;
   hlaIdentifier ident;
   hlaState      state;
   bool _position, _ident, _state;
} local;
 
 
We know that every time an Object Attribute is modified on the Publisher side, the RTI will automatically update all corresponding Subscriber's Object Attribute.
So, we need to publish the Attribute whenever it has been modified by the Object.
 
In the FedItem property window, let's select SOM panel and let's double-click the State Attribute.
In the Code section, let's add:
 
 if (local_state) {
   "State" <- (hlaState) local.state;
   local._state = false;
 }
 
vsTASKER will pre-process this part and translate it into HLA API C++ code.
"State" must be understood as "the RTI data counterpart".
 
Let's do it for the three Attributes (on each respective window) :
 
 if (local._position) {
   "Position" <- (hlaPosition) local._position;
   local._position = false;
}
 
if (local._ident) {
   "Identifier" <- (hlaIdentifier) local._ident;
   local._ident = false;
}
 
 
Now, we must update the Attributes for each FedItem users.
For that, open the FedItem property window at the Runtime::Code panel:
 
This part of the code is called at the frequency set for the FedItem.
Each registered entity (user) attached to the FedItem (see used_by list) will be used.
 
ent_idx will parse all indexes from 0 to n-1 entities using this FedItem.
We will put our update code as follow:
 
local.state.Heading = entity->getDyn()->getHeading();
local.state.Speed   = entity->getDyn()->getSpeed();
local.state.Health  = entity->getStatus()->getHealth();
local._state        = true;
 
local.position.X    = entity->pos.x;
local.position.Y    = entity->pos.y;
local.position.Z    = entity->pos.z;
local._position     = true;
   
local.ident.ID    = entity->getId();
local.ident.Type  = entity->getStatus()->getType();
local.ident.Color = entity->getColor();
local.ident.IFF   = entity->getStatus()->getIFF();
local._ident      = true;
 
It is mandatory to use the function getEntity() (if the FedItem works with entities) or getHandle() (if the FedItem uses objects only) to set the RTI handle before publishing.
 
Now, you can compile and even run the simulation.
The Simulation Engine will connect to the Mak RTI and register the Federation.
 
Let's do the Subscriber...