VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VRF Message Printer

This subclass of DtVrfMessageInterface creates and registers with the various factories to be able to create and print interactions.

How to Run

This example demonstrates how to listen for and display VR-Forces-specific interface messages.

Usage:

(Release) vrfMsgDump

(Debug) vrfMsgDumpd

To run the application:

  1. Start VR-Forces from the start menu.
  2. Start vrfMsgDump

The contents of all VR-Forces-specific interface messages (e.g. tasks, set data requests) will be displayed in the vrfMsgDump console window. As you run VR-Forces, any task or set data request messages that get created over the course of a scenario will be displayed by vrfMsgDump.


Header file:

/*******************************************************************************
** Copyright (c) 2017 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
//class DtSimpleRadarWarningResponse:
//
//Instances of DtSimpleRadarWarningResponse are an example of a controller
//that implements a reactive behavior when a it receives sensor input that
//a radar has been detected. It receives a list of emitter systems (hostile
//radar systems). It takes the first emitter in the list and flys away to
//a location in the opposite direction.
class DtUUID;
{
public:
//constructor
DtSimulationServices* simManager, DtComponentDescriptor* desc = NULL,
DtReaderWriterRegistry* const parentRegistry = 0);
//destructor
//This returns a string that uniquely identifies this type of component.
//(must be unique with respect to the component types defined in compTypes.h
//as well as any additional user-defined components). Returns the string
//"simple-radar-warning-response".
virtual const char* type() const;
//Calculate new control values.
virtual void tick();
//Returns a newly created instance of this class. We need to provide
//this function so that we can register this class with the component
//factory.
static DtSimComponent* creator(const DtString& name, DtLocalObject* owner,
DtReaderWriterRegistry* parentRegistry);
protected:
//Called by DtSimComponent::init to create myEntityListPort used to manage
//multiple sensors that might provide targets to this controller.
virtual bool createPorts();
//Looks up safe control point by name. If the object exists and it has
//a valid state repository, returns the object. Otherwise returns NULL.
//Returns true if we are in the vicinity of the given position. To be
//in the vicinity of the position means that we are within 5 seconds of
//the given location, given our ordered speed.
virtual bool inVicinity(const DtVector& localPosition);
protected:
//default constructor
//copy constructor, not implemented
//assignment operator, not implemented
protected:
//Port though which the list of hostile emitter systems will be received.
//true while in state of reacting to the detection of an emitter.
//Name of the safe location (a control point) we can retreat to.
};

Implementation:

/*******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include "simpleRdrWrnResp.h"
#include <vlutil/vlPrint.h>
const DtString & name, DtLocalObject* owner, DtSimulationServices* simManager,
DtComponentDescriptor* desc, DtReaderWriterRegistry * const parentRegistry) :
DtFixedWingPilotController(name, owner, simManager, desc, parentRegistry),
myEmitterListPort(NULL),
myReactingToWarning(false),
mySafeControlPointName("Safe Haven")
{
}
{
{
}
}
namespace
{
const char* SimpleRadarWarningResponseType = "simple-radar-warning-response";
}
{
return SimpleRadarWarningResponseType;
}
{
if (!(myEmitterListPort = new DtEntityListInputPort("emitter-list")))
{
return false;
}
}
{
DtPROFILE("DtSimpleRadarWarningResponse::tick");
//If dT is > 0 (we're not paused), then do the work
if (dT() > 0.)
{
//Called each frame by the deriving controllers to set up need variables,
//such as myNormalBodyVelocity and myLocalAngularVelocity.
if (!safeControlPoint.isValid())
{
DtWarn << "DtSimpleRadarWarningResponse::tick() : Invalid safe control "
"point " << mySafeControlPointName.markingText() << std::endl;
return;
}
DtVector safeLocation = safeControlPoint->localPosition();
//If I'm already reacting to a previous radar warning
{
//Take control of the port group - this gives us exclusive control
//over the fixed-wing actuator until we give that control up or a
//higher priority controller overrides us
{
if (inVicinity(safeLocation))
{
//We're done
objectConsoleWarn() << "radarWarnRx Example - " <<
"We have reached the safe location! " << std::endl;
objectConsoleWarn() << "radarWarnRx Example - " <<
"Resume normal activity." << std::endl;
//Give up control of actuator's port group so other
//components may control it.
}
else
{
//Move toward the safe location
}
}
}
else
{
{
objectConsoleVerbose() << "radarWarnRx Example - " <<
"No emitter list for radar warning reaction controller" <<
std::endl;
return;
}
//Get 1st emitter system on list of emitters on the port
const DtEntityTargetList* emitterList = myEmitterListPort->value();
//If there aren't any emitters out there, there's nothing to react to
if (!(emitterList->first() && emitterList->first()->data()))
{
//Mark the data as "old"
return;
}
//We have an emitter out there
(DtEntityTargetInformation *)emitterList->first()->data();
//Look up the entity with the radar
DtSimObjectReference emitterSystemHost =
if (!emitterSystemHost)
{
//Mark the data as "old"
return;
}
//We're now reacting to an emitter
objectConsoleWarn() << "radarWarnRx Example - " <<
"Simple radar warning rx detected emitter " << info->id().string() <<
"." << std::endl;
objectConsoleWarn() << "radarWarnRx Example - " <<
"Move away from the source!" << std::endl;
//Take control of port group - this gives us exclusive control
//over the fixed-wing actuator for the duration of the frame (no other
//controllers that come after this one will be able to control it).
{
//Move toward the safe location
}
//Mark the data as "old"
}
}
}
DtReaderWriterRegistry * parentRegistry)
{
return new DtSimpleRadarWarningResponse(name, owner, simManager, desc,
parentRegistry);
}
{
if (!controlPoint.isValid())
{
objectConsoleWarn() << "radarWarnRx Example - " <<
"DtSimpleRadarWarningResponse::getControlPoint() : Can't find control point " <<
name.markingText() << std::endl;
}
return controlPoint;
}
const DtVector& localPosition)
{
{
}
myFixedWingEntityState->orderedSpeed() * 25.0)) //5 seconds away...
{
return true;
}
return false;
}

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)