- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/DCInterface.h

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #if !defined(TITAN_INTERFACE)
    00012 #define TITAN_INTERFACE
    00013
    00014 #include <Mers/Utils/Containers/IntegerArray.h>
    00015 #include <Mers/Utils/Containers/DynamicArrayTemplate.h>
    00016
    00017 #include <Mers/Executives/DeductiveController/Rtapi/RTAPICallback.h>
    00018 #include <Mers/Executives/DeductiveController/Rtapi/CommandCallback.h>
    00019
    00020 #include <Mers/Interfaces/ExecutionInterfaceBase.h>
    00021 #include <Mers/Interfaces/ObservationTransformationInterface.h>
    00022
    00023 namespace Mers {
    00024         namespace Interfaces {
    00025                 class Task;
    00026         }
    00027         namespace Models {
    00028                 namespace Base {
    00029                         class BaseModel;
    00030                 }
    00031         }
    00032         namespace Reconfiguration {
    00033                 namespace Discrete {
    00034                         class MR_connection;
    00035                 }
    00036         }
    00037         namespace Estimation {
    00038                 namespace Discrete {
    00039                         class ME_connection;
    00040                 }
    00041         }
    00042         namespace Executives {
    00043                 namespace DeductiveController {
    00044
    00045                         namespace Rtapi {
    00046                                 class CommandCallback;
    00047                         }
    00048
    00049                         class Task;
    00050                         class DiscreteVariable;
    00051                         class DiscreteValue;
    00052
    00083                         class DCInterface :
    00084                                 protected Mers::Executives::DeductiveController::Rtapi::RTAPICallback,
    00085                                 public Mers::Interfaces::ExecutionInterfaceBase,
    00086                                 public Mers::Interfaces::ObservationTransformationInterface
    00087                         {
    00088                         public:
    00090                                 typedef ::Mers::Utils::Containers::SharedPointer< Task >
    00091                                         t_DCTaskSharedPointer;
    00092
    00093                         public:
    00095                                 // Public Constructors, Copy Constructors, & Destructors
    00097
    00114                                 DCInterface(Mers::Estimation::Discrete::ME_connection *me_connection_p,
    00115                                         Mers::Reconfiguration::Discrete::MR_connection *mr_connection_p,
    00116                                         Mers::Models::Base::BaseModel * model, bool initialEstimate = true);
    00117
    00121                                 virtual ~DCInterface();
    00122
    00124                                 // Public Function Members
    00126
    00135                                 void setExecutionInterface(Mers::Interfaces::ExecutionInterfaceBase * execInterface);
    00136
    00147                                 void addObservationInterface(Mers::Interfaces::ObservationInterface * obsInterface);
    00148
    00149                         protected:
    00151                                 // Functions for DC DCInterface (RTAPICallback)
    00152                                 //
    00153                                 // Note: These functions are the implementation of RTAPICallback.
    00154                                 //       They will NOT need to be called by external clients.
    00155                                 //       Only the RTAPI will be concerned with them.
    00156                                 // - package scope would be nice here...
    00158
    00167                                 void post_mode_estimate(Mers::Utils::Containers::intList const &updated_mode_estimate);
    00168
    00177                                 void post_full_state(Mers::Utils::Containers::intList const &full_mode_estimate);
    00178
    00186                                 virtual void post_observation(unsigned int varUID, unsigned int valUID);
    00187
    00192                                 virtual void process_next_control_cmd(Mers::Utils::Containers::intList const &commands);
    00193
    00194
    00195                         public:
    00197                                 // Interface Functions for ExecutionInterfaceBase
    00199
    00216                                 virtual bool start( TaskIdentifier task );
    00217
    00222                                 virtual bool stop();
    00223
    00234                                 virtual bool stop( TaskIdentifier task );
    00235
    00254                                 virtual int step( bool block = true );
    00255
    00261                                 virtual bool isDone();
    00262
    00270                                 virtual bool isDone( TaskIdentifier task );
    00271
    00280                                 virtual Mers::Utils::Lang::String getActiveTasksString() const;
    00281
    00295                                 virtual TaskIdentifier createTask( const Mers::Utils::Lang::String &taskName );
    00296
    00306                                 virtual t_TaskSharedPointer getTask( TaskIdentifier task ) const;
    00307
    00323                                 virtual TaskIdentifier createTask( const Mers::Utils::Lang::String &taskName,
    00324                                         std::vector<const Mers::Utils::Lang::String *> const &parameters );
    00325
    00331                                 virtual std::set<TaskIdentifier> getRecentlyFailedTasks();
    00332
    00336                                 virtual std::set<TaskIdentifier> getRecentlyCompletedTasks();
    00337
    00338                         public:
    00340                                 // Interface Functions for ObservationTransformationInterface
    00342
    00349                                 virtual void update(ObservationInterface::ValueIdentifier value);
    00350
    00359                                 virtual void update(ObservationInterface::ContinuousVariableIdentifier varID, double value);
    00360
    00371                                 virtual DiscreteVariableIdentifier getDiscreteVariable(const char * varName);
    00372
    00387                                 virtual ValueIdentifier getValue(DiscreteVariableIdentifier varID, const char * value);
    00388
    00396                                 virtual bool isValid(DiscreteVariableIdentifier varID);
    00397
    00405                                 virtual bool isValid(ValueIdentifier value);
    00406
    00417                                 virtual ValueIdentifier getCurrentState(DiscreteVariableIdentifier varID);
    00418
    00429                                 virtual double getCurrentState(ContinuousVariableIdentifier varID);
    00430
    00436                                 Mers::Utils::Lang::String getCurrentStateStr() const;
    00437
    00438                         public:
    00440                                 // Interface Functions for Mode Estimation
    00441                                 //
    00442                                 // There appear to be two types of ME interface methods:
    00443                                 // those which use RTAPI timers and those that do not.
    00444                                 // When the RTAPI timers are used, it is unnecessary to
    00445                                 // explicitly request mode estimates from the engine
    00446                                 // (i.e. find candidates/fc).  The timers will invoke
    00447                                 // mode estimation at the appropriate time.
    00449
    00458                                 virtual void setInitialState(unsigned int state_index,
    00459                                         unsigned int value_index);
    00460
    00465                                 virtual void requestAbort();
    00466
    00474                                 virtual void requestFullState();
    00475
    00487                                 int loadInitialState(char const * initFile, Mers::Models::Base::BaseModel const * model);
    00488
    00490                                 // Interface Functions for Mode Reconfiguration
    00492
    00504                                 virtual void requestMR();
    00505
    00506                         protected:
    00507
    00517                                 DiscreteValue * getDiscreteValue(int varIndex, int valIndex);
    00518
    00526                                 int getAbsoluteIndex(int varIndex, int valIndex);
    00527
    00528                         protected:
    00529                                 // The basic int pair type.
    00530                                 typedef std::pair<int, int> t_VarValPair;
    00531
    00532                                 // A map type from Values to Variable/Value identifiers.
    00533                                 typedef std::map<ObservationInterface::ValueIdentifier, t_VarValPair>
    00534                                 t_ValueMap;
    00535
    00536                         protected:
    00538                                 // Protected Data Object Members
    00540
    00542                                 Mers::Interfaces::ExecutionInterfaceBase * mExecInterface;
    00543
    00546                                 std::map<int, TaskIdentifier> mTasks;
    00547
    00551                                 Mers::Utils::Containers::IntegerArray mBaseOffset;
    00552
    00555                                 Mers::Models::Base::BaseModel * mModel;
    00556
    00558                                 std::vector<DiscreteVariable *> mDVars;
    00559
    00561                                 std::vector<DiscreteValue *> mDVals;
    00562
    00564                                 t_ValueMap mValueIDMap;
    00565
    00568                                 bool mMrFailed;
    00569
    00571                                 std::set<t_TaskSharedPointer> mActiveGoals;
    00572
    00574                                 std::vector<DiscreteValue *> mCurrentState;
    00575
    00577                                 Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi *
    00578                                 mMeRtapi;
    00579
    00581                                 Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi *
    00582                                 mMrRtapi;
    00583
    00586                                 bool m_MRIdle;
    00587
    00590                                 bool m_MEIdle;
    00591
    00592                                 // Set of tasks determined to have failed by the last call to step.
    00593                                 std::set<TaskIdentifier> m_recentlyFailedTasks;
    00594
    00595                                 // Set of tasks determined to have completed by the last call to step.
    00596                                 std::set<TaskIdentifier> m_recentlyCompletedTasks;
    00597
    00598
    00599                         protected:
    00606                                 DCInterface(Mers::Models::Base::BaseModel * model);
    00607
    00613                                 void init(Mers::Models::Base::BaseModel * model);
    00614
    00615                         private:
    00617                                 static log4cplus::Logger m_Logger;
    00618
    00619                                 bool isDone(t_DCTaskSharedPointer task);
    00620                         };
    00621                 }
    00622         }
    00623 }
    00624
    00625 #endif // !defined(TITAN_INTERFACE)