VR-Forces 4.2 Class Documentation
Derived Move To Controller

This subclass of the DtGroundMoveToControllerComponent will give up on the movement task after a certain amount of simulation time


Header file:

/*******************************************************************************
** Copyright (c) 1999 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: derivedMoveToController.h,v $ $Revision: 1.5 $ $State: Exp $
*******************************************************************************/
//
//File: DerivedMoveToController.h
//
//Class: DerivedMoveToController
//
#ifndef DerivedMoveToController_H_
#define DerivedMoveToController_H_
//
//Class Description: DerivedMoveToController
//
//The purpose of this class is to demonstrate how to check for and handle
//a situation in which an entity is unable to carry out a given task behavior.
//In this particular example, it extends the DtGroundMoveToControllerComponent
//with the ability to determine when it should 'give up' trying to reach its
//waypoint. The criteria for determining it should give up trying to complete
//its task is that it should stop trying after 10 seconds. At that point, it
//sends a task complete report, indicating it has finished (although it may be
//no where near its destination).
//
//There are 2 required member functions that this class overrides to implement
//the 'give up' behavior:
//
//decideToGiveUpTask() : This is the function that looks at the current
//situation and decides if it should give up. It will be automatically called
//immediately following the entity's tick().
//
//giveUpTask() : This gets called when the decideToGiveUpTask() returns true.
//In this example, it calls taskComplete(), which results in a task complete
//report being sent and the controller put into a non-tasked state.
{
public:
//constructor
DtVrfObject* owner,
DtSimManager* simManager,
DtComponentDescriptor* desc = NULL,
DtReaderWriterRegistry* parentRegistry = NULL);
//destructor
//Override to initialize myTimeToGiveUp member to current time plus 10 seconds.
//We'll check this in decideToGiveUp(). Note that this function is only
//overridden for this particular time-based criteria for giving up. You would
//not in general have to override this to add a 'decide to give up' capability
//to a controller.
virtual void processMoveToTask(DtSimMessage * msg);
//Creates and returns a new DerivedMoveToController
static DtSimComponent* creator(const DtString& name,
DtVrfObject* owner,
DtSimManager* simManager,
DtComponentDescriptor* desc = NULL,
DtReaderWriterRegistry* parentRegistry = NULL);
protected:
//Override to see if we should give up after 10 seconds (checks current
//simulation time against myTimeToGiveUp).
virtual bool decideToGiveUpTask() const;
//Calls taskComplete(). This will result in a DtTaskComplete report being
//sent to whomever issued the task.
virtual void giveUpTask();
private:
//Default constructor; should not be called. Here because the compiler
//will generate an unprotected one otherwise.
//copy constructor; shallow; does not copy the ports.
orig);
//assignment operator; see comments on copy constructor!
protected:
//This is the time we decide we want to give up when the entity
//is executing a task.
};
#endif

Implementation:

/*******************************************************************************
** Copyright (c) 1999 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: derivedMoveToController.cxx,v $ $Revision: 1.6 $ $State: Exp $
*******************************************************************************/
//
//File: DerivedMoveToController.cxx
//
//Class: DerivedMoveToController
//
#include <vrfcore/simMgr.h>
const DtString& name,
DtVrfObject* owner,
DtSimManager* simManager,
DtReaderWriterRegistry* parentRegistry) :
DtGroundMoveToControllerComponent(name, owner, simManager, desc,
parentRegistry)
{
}
{
}
const DtString& name,
DtVrfObject* owner,
DtSimManager* simManager,
DtReaderWriterRegistry* parentRegistry)
{
return new DerivedMoveToController(name, owner, simManager, desc, parentRegistry);
}
{
//Initialize time to give up to 10 seconds from now.
myTimeToGiveUp = mySimManager->exerciseClock()->simTime() + 10.0;
objectConsoleInfo() << myEntity->objectName().string() <<
" - Setting time to give up for move-to task to " << myTimeToGiveUp <<
std::endl;
}
{
DtTime currentSimTime = mySimManager->exerciseClock()->simTime();
if( currentSimTime > myTimeToGiveUp)
{
objectConsoleInfo() << myEntity->objectName().string() <<
" - Giving up move to task at time " << currentSimTime << std::endl;
return true;
}
else
{
return false;
}
}
{
" - Gave up on move to task. Calling taskComplete()." << std::endl;
}

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)