VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Simple Plan (simplePlan)

The Simple Plan example demonstrates the following:

The Simple Plan example is loaded as a plugin and demonstrates plan creation and assignment of this plan to a pre-exisiting entity. It also demonstrates creating and registering a trigger area that adds a trigger statement to the object's plan when the object coincides with the area. Finally, it shows how to create and register a console command to send the plan to the specified object.

How to Run the Example

This example demonstrates how to programatically create a plan for an entity in a plugin.

Usage

(Release) simplePlan

(Debug) simplePland

In the Launcher:

  1. Set the simplePlan plugin to load.
  2. Launch the application.
  3. Load the simplePlan.scnx scenario.

To view the new behavior:

  1. Enter the "sendPlan" command in the SIM console.
  2. In the GUI, right-click the entity to view the plan.
  3. Play the scenario. As the entitiy enters the trigger area (Area 2), the triggered action takes place before the entity resumes the original plan.

Plugin Code

/*******************************************************************************
** Copyright (c) 2017 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
// VR-Forces includes
#include "vrfcgf/cgf.h"
//for conditional expression
#include "vrfplan/ifStmt.h"
// VR-Link includes
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
static DtSimulationAddress theSimulationAddress(1,3001);
static DtSimManager* theSimManager = 0;
static DtCgf* theCgf = 0;
/*
sendPlan command should:
-Get a M1A2 tank entity
-Get the area(s)
-Get all waypoints(Alpha, Beta, Gamma)
-Create a simple plan for the tank:
-Set tank's speed
-Add a wait task
-Add a move-to Alpha waypoint (conditional)
-Add a move-to Beta waypoint (conditional)
-Register and add a trigger statement to the plan
-Assign the plan to the tank
*/
class DtSendPlanCommand : public DtConsoleCommand
{
~DtSendPlanCommand() { };
//Execute the command.
//\return True on success of the command.
virtual bool execute(const DtString& parameters)
{
//Object Manager
DtVrfObjectManager* objMgr = theCgf->vrfObjectManager();
//Get the tank object
DtString myTankName = "M1A2 1";
//Get Area1 for testing
DtString myFirstArea = "Area 1";
DtSharedVrfObjectReference areaStart = objMgr->lookupVrfObjectByMarkingText(myFirstArea);
//Get Area2 for trigger task
DtString myTriggerArea = "Area 2";
DtSharedVrfObjectReference triggerArea = objMgr->lookupVrfObjectByMarkingText(myTriggerArea);
//Get the Alpha Waypoint
DtString myAlpha = "Alpha";
//Get the Beta Waypoint
DtString myBeta = "Beta";
//Get the Gamma Waypoint
DtString myGamma = "Gamma";
//Create a simple plan for the tank
DtPlanBuilder planBuilder;
//Create blocks for conditional statements
DtPlanBlockBuilder::SharedPlanBlockBuilder thenBlockBuilder, elseBlockBuilder, triggerBlockBuilder;
//Create some plan sets and tasks
//Set tank speed
speedReq.setSpeed(10.0); //Ordered speed, in meters/second
//Wait task
waitTask.setSecondsToWait(10.0);
//Move to Alpha Task
DtMoveToTask moveToAlphaTask;
moveToAlphaTask.setControlPoint(alpha->uuid());
//Move to Beta Task
DtMoveToTask moveToBetaTask;
moveToBetaTask.setControlPoint(beta->uuid());
//Move to Gamma Task
DtMoveToTask moveToGammaTask;
moveToGammaTask.setControlPoint(gamma->uuid());
//Create an "entity in area" conditional expression. The entity has
//already been created within the test area so this expression will
//always return true. To test the "else" condition, try changing the
//initial position of the entity or the area.
DtCeEntInArea conditionalExpression;
conditionalExpression.setArea(areaStart->uuid());
conditionalExpression.setEntity(myEntity->uuid());
//Create an "entity in trigger area" conditional expression.
DtCeEntInArea conditionalExpressionTrigger;
conditionalExpressionTrigger.setArea(triggerArea->uuid());
conditionalExpressionTrigger.setEntity(myEntity->uuid());
DtString triggerAreaDescription = "This trigger causes the entity who passes through the area to reroute to a different waypoint."; //Trigger area description
//Add tasks to the plan
//The plan assumes responsibility for the memory associated with the statements,
//so clone the statements and add them to the plan.
planBuilder.addStatement(speedReq);
planBuilder.addStatement(waitTask);
planBuilder.addIfCondition(conditionalExpression, thenBlockBuilder, elseBlockBuilder);
thenBlockBuilder->addStatement(moveToAlphaTask);
elseBlockBuilder->addStatement(moveToBetaTask);
//Create trigger when entity is within triggerArea
DtUUID triggerAreaUuid = (DtUUID)(triggerArea->uuid());
triggerBlockBuilder = planBuilder.addTriggerStatement(conditionalExpressionTrigger, triggerAreaUuid, triggerAreaDescription, true, "SuspendTask", true);
triggerBlockBuilder->addStatement(moveToGammaTask);
//Assign the plan to the tank
theCgf->assignPlanByUUID(myEntity->uuid(), planBuilder);
return true;
}
//\return Some help text for the command.
virtual DtString help(const DtString& parameters)
{
return "Send a message with the given text.";
};
//\return True if this command should show up in the help list.
//If false, than this command will not be presented to the user.
virtual bool showInHelp() const { return true; };
};
static DtSendPlanCommand* theSendPlanCommand = new DtSendPlanCommand();
extern "C" {
{
info.pluginName = "Simple Plan Sim";
info.pluginDescription = "This is an example of how to send a simple plan to an entity and register a trigger statement.";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "10 Fawcett Street, Suite 204, Cambridge, MA 02138 USA";
info.pluginContactPhone = "(617) 876 8085";
}
DT_VRF_DLL_PLUGIN bool DtInitializeVrfPlugin(DtCgf* cgf)
{
//Register the creator function for the controller here if needed
return true;
}
DT_VRF_DLL_PLUGIN bool DtPostInitializeVrfPlugin(DtCgf* cgf)
{
//Register the command to trigger sendPlan to <entity>
theSimulationAddress = cgf->exerciseConn()->applicationId();
theSimManager = cgf->simManager();
theCgf = cgf;
return true;
}
}

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)