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

The Simple Plan example demonstrates the following:

A CGF application differs from the released back-end in that there is not command line options applied to it and it is intended to be used as part of a larger back-end application that does not have a need to interface with the VR-Forces front-end.

How to Run the Example

This example demonstrates how to programatically create a plan for an entity in an embedded CGF application (outside of the context of the vrfSim application).

Usage

(Release) simplePlan

(Debug) simplePland

To run the application:

  1. Open an command line and switch to the VR-Forces "bin" directory.
  2. Start the VR-Forces GUI using the command "vrfLauncher –usePredefinedConnection DIS -F"
  3. Start simplePlan from the command line as "simplePlanDIS".
  4. Right-click on the entity to view its plan.

Note you will need to join the session or you cannot view the entity's plan.

The simplePlan application simulates a tank with a plan. You can observe the execution of the plan in the entity's 'View Plan' window.

Main Application File

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//This example demonstrates how to use the DtCgf class to create entities,
//objects and plans, and then execute the resulting scenario as you would if
//you were to embed VR-Forces in your own application.
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#endif
//VR-Forces Headers
#include "vrfcgf/cgf.h"
#include "vrfplan/plan.h"
//for conditional expression
#include "vrfplan/ifStmt.h"
//VR-Link headers
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializer.h>
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
int main(int argc, char *argv[])
{
//DIS/RPR simulation address
DtSimulationAddress simAddress(1, 3001);
//Create the CGF
DtCgf* cgf = new DtCgf(simAddress);
// The following is left so the user can see how to piece together a
// simple DIS or HLA exercise connection. Also so you know what execName to
// pass for HLA for the -x command. Use this and you don't need anything else, it will use
// a default fed file of VR-Link.fed(for HLA13) or VR-Link.xml( for HLA1516/1516e) However to make life easier we're also
// going to show you how to use an DtVrlApplicationInitializer so you can parse the command line as well
//Create the exercise connection
/*#if DtHLA
DtString execName = "VR-Link"; //HLA federation execution name
DtString federateName = "simplePlan"; //HLA federate name
double rprFomVersion = 1.0; //RPR FOM version number
DtExerciseConn* exerciseConn = new DtExerciseConn(execName, federateName,
new DtRprFomMapper(rprFomVersion));
#else //DIS
int port = 3928; //UDP port number
int exerciseId = 1; //DIS exercise ID
DtExerciseConn* exerciseConn = new DtExerciseConn(port, DtInetAddr("127.255.255.255"), exerciseId,
simAddress.siteId(), simAddress.applicationId());
#endif*/
// Use this to parse the command line then pass the initializer to the exercise connection
DtVrlApplicationInitializer initializer(argc, argv, "simplePlan");
#if DtDIS
initializer.setDisVersionToSend(7);
#endif
initializer.parseCmdLine();
#if DtDIS
initializer.setSiteId(simAddress.siteId());
initializer.setApplicationNumber(simAddress.applicationId());
#endif
DtExerciseConn* exerciseConn = new DtExerciseConn(initializer);
//Initialize the CGF
cgf->init(exerciseConn);
//Create the dispatcher so this application can interface with
//front-end
DtCgfDispatcher* cgfDispatcher = new DtCgfDispatcher(cgf,
//Create a new scenario, using the Ground-db.gdb terrain database and the EntityLevel
//simulation model set to allow for entity creation
cgf->newScenario("../userData/terrains/Ground-db.mtf",
"../data/simulationModelSets/EntityLevel.sms");
//Tick the cgf to get the terrain loaded
cgf->tick();
//Create a tank
DtEntityType tankType(1, 1, 225, 1, 1, 3, 0);
DtVector initialPosition(900.0, 900.0, 0.0); //Database coordinates, meters
DtReal initialHeading = 0.0; //Heading in radians
DtVrfObject* tank = cgf->createEntity(
tankType,
DtForceFriendly,
initialPosition,
initialHeading);
//Create an area for testing
DtList verticies;
DtVector v1(800,800,0);
DtVector v2(800,1000,0);
DtVector v3(1000,1000,0);
DtVector v4(1000,800,0);
verticies.add((void*)&v1);
verticies.add((void*)&v2);
verticies.add((void*)&v3);
verticies.add((void*)&v4);
DtVrfObject* area = cgf->createControlArea(verticies, "area");
//Create a waypoints named "Alpha" and "Beta"
DtVrfObject* alpha = cgf->createWaypoint(
DtVector(1300.0, 1000.0, 0.0),
"Alpha");
DtVector(300.0, 1000.0, 0.0),
"Beta");
//Create a simple plan for the tank
DtPlan plan;
plan.init();
//Create some set data requests and tasks to put in the plan
speedReq.setSpeed(10.0); //Ordered speed, in meters/second
waitTask.setSecondsToWait(10.0);
DtMoveToTask moveToAlphaTask;
moveToAlphaTask.setControlPoint(alpha->uuid());
DtMoveToTask moveToBetaTask;
moveToBetaTask.setControlPoint(beta->uuid());
//Create statements to hold the set data requests and tasks
DtSetDataRequestStmt setSpeedStatement;
DtTaskStmt waitStatement;
DtTaskStmt moveToAlphaStatement;
DtTaskStmt moveToBetaStatement;
setSpeedStatement.setSetDataRequest(&speedReq);
waitStatement.setTask(&waitTask);
moveToAlphaStatement.setTask(&moveToAlphaTask);
moveToBetaStatement.setTask(&moveToBetaTask);
//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.setEvaluator(DtEvaluator::factory()->
createEvaluator(conditionalExpression.type()));
conditionalExpression.setArea(area->uuid());
conditionalExpression.setEntity(tank->uuid());
DtIfStmt ifStatement;
ifStatement.setCondExpr(&conditionalExpression);
ifStatement.thenBlock()->add(moveToAlphaStatement.clone());
ifStatement.elseBlock()->add(moveToBetaStatement.clone());
//Add statements to the plan. The plan assumes responsibility
//for the memory associated with the statements, so clone the
//statements and add them to the plan.
DtPlanBlock* block = plan.mainBlock();
block->addToStart(setSpeedStatement.clone());
block->addToStart(waitStatement.clone());
block->addToEnd(ifStatement.clone());
//Assign the plan to the tank.
cgf->assignPlanByUUID(tank->uuid(), plan);
//Put the simulation engine into run mode.
cgf->run();
//Main application loop
while (1)
{
//tick the CGF Dispatcher
cgfDispatcher->tick();
//tick the CGF
cgf->tick();
//Poll & process keyboard input
char *keyPtr = DtGetInputLine();
if (keyPtr && *keyPtr == 'q')
{
break;
}
//Give up the remainder of our time slice.
DtSleep(0.01);
}
delete cgf;
delete exerciseConn;
return 0;
}

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)