VR-Forces 4.0.4 Class Documentation
examples/subtask/turnAndMoveController.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2005 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: turnAndMoveController.h,v $ $Revision: 1.3 $ $State: Exp $
00007 *******************************************************************************/
00008 
00009 #ifndef turnAndMoveController_H_
00010 #define turnAndMoveController_H_
00011 
00012 #include "vrfobjcore/singleTaskControllerComponent.h"
00013 
00014 class DtTurnAndMoveControllerPSR;
00015 
00016 const char DtTurnAndMoveControllerType[] = "turn-and-move-controller";
00017 
00018 //This example controller responds to a user task with the name "turn-and-move"
00019 //and argument 1 specifying the name of a destination object (i.e. a waypoint).
00020 //The task is carried out by first issuing a Turn To Heading subtask, and
00021 //when that completes, issuing a Move To task.
00022 //The controller registers for DtTaskCompletedReport messages from itself
00023 //in order to find out when a subtask has completed.
00024 class DtTurnAndMoveController : public DtSingleTaskControllerComponent
00025 {
00026 private:
00027    //Not Implemented.
00028    DtTurnAndMoveController();
00029    //Not Implemented.
00030    DtTurnAndMoveController(const DtTurnAndMoveController& orig);
00031    //Not Implemented.
00032    DtTurnAndMoveController& operator=(const DtTurnAndMoveController& orig);
00033 
00034 public:
00035 
00036    //\copydoc DtSimComponent(const DtString&,DtVrfObject*,DtSimManager*,
00037    //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
00038    DtTurnAndMoveController(const DtString& name, 
00039       DtVrfObject* owner,
00040       DtSimManager* simManager, 
00041       DtComponentDescriptor* desc = NULL,
00042       DtReaderWriterRegistry* parentRegistry = NULL);
00043 
00044    virtual ~DtTurnAndMoveController();
00045 
00046    //Initial setup of component after creation.
00047    virtual bool init();
00048 
00049    //Creates the process state repository for this component.
00050    virtual bool createPSR();
00051 
00052    //\copydoc DtSimComponent::type()
00053    //\return DtTurnAndMoveControllerType.
00054    virtual DtString type() const;
00055 
00056    //Overridden to register interest in user-task and task-completed
00057    //radio messages.
00058    virtual void registerTaskMsgCallbacks();
00059 
00060    //Callback for DtUserTask.  Calls the virtual processUserTask().
00061    static void userTaskCallback(DtSimMessage * msg, void * usr);
00062 
00063    //Starts this task.
00064    //Looks for DtUserTasks with name of "turn-and-move" with
00065    //the first argument being the name of the destination object.
00066    virtual void processUserTask(DtSimMessage * msg);
00067 
00068    //Callback for DtTaskCompletedReport.  
00069    //Calls the virtual processTaskCompleteReport().
00070    static void taskCompleteReportCallback(DtSimMessage* msg, void* usr);
00071 
00072    //Listens for task completed reports from the subtasks that
00073    //are started by this task, and issues the next subtask,
00074    //or completes the task as necessary when the reports arrive.
00075    virtual void processTaskCompleteReport(DtSimMessage* msg);
00076 
00077    //Main processing for component.
00078    virtual void tick();
00079 
00080 protected:
00081 
00082    //Calculates the heading to the destination and starts a 
00083    //turn to heading subtask.
00084    virtual bool startTurningPhase();
00085 
00086    //Starts a move to subtask.
00087    virtual bool startMovingPhase();
00088 
00089    //Overridden for any resource cleanup when task is cleared.
00090    //For this example, only calls down to the base class.
00091    virtual void clearTask();
00092 
00093 public:
00094 
00095    //\copydoc DtSimComponent(const DtString&,DtVrfObject*,DtSimManager*,
00096    //DtComponentDescriptor*,DtReaderWriterRegistry* parentRegistry)
00097    //\return New instance of this class.
00098    static DtSimComponent * creator(const DtString& name, 
00099       DtVrfObject* owner,
00100       DtSimManager* simManager, 
00101       DtComponentDescriptor* desc = 0,
00102       DtReaderWriterRegistry* parentRegistry = 0);
00103 
00104 protected:
00105    enum DtControllerStates
00106    {
00107       StateTurning,
00108       StateMoving
00109    };
00110 
00111    //All state values for this controller are stored in a process state
00112    //repository, so that if the scenario is saved during the execution
00113    //of the task, it will resume correctly when the scenario is reloaded.
00114    //See the addPSR example for more information specifically about 
00115    //using process state repositories.
00116    DtTurnAndMoveControllerPSR* myProcessState;
00117 };
00118 
00119 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)