MovementControllerI.H

00001 #include "Component/ModelManager.H"
00002 #include "Component/OptionManager.H"
00003 #include "Component/ModelComponent.H"
00004 #include "Component/ModelParam.H"
00005 #include "Media/FrameSeries.H"
00006 #include "Transport/FrameInfo.H"
00007 #include "Raster/GenericFrame.H"
00008 #include "Image/Image.H"
00009 #include "GUI/XWinManaged.H"
00010 #include "GUI/ImageDisplayStream.H"
00011 #include "Image/Image.H"
00012 #include "Image/Pixels.H"
00013 #include "Robots/RobotBrain/RobotBrainComponent.H"
00014 #include "Ice/RobotBrainObjects.ice.H"
00015 #include "Ice/RobotSimEvents.ice.H"
00016 #include "Ice/IceImageUtils.H"
00017 #include <IceUtil/Thread.h>
00018 
00019 #ifndef MOVEMENTCONTROLLERI_H
00020 #define MOVEMENTCONTROLLERI_H
00021 
00022 /* Movement Controller States */
00023 #define STATE_INIT                0
00024 #define STATE_DO_GATE                1
00025 #define STATE_FIND_FLARE        2
00026 #define STATE_DO_FLARE                3
00027 #define STATE_FIND_BARBWIRE        4
00028 #define STATE_DO_BARBWIRE        5
00029 #define STATE_FIND_BOMBING        6
00030 #define STATE_DO_BOMBING        7
00031 #define STATE_FIND_BRIEFCASE        8
00032 #define STATE_DO_BRIEFCASE        9
00033 #define STATE_PATH_FOLLOW        10
00034 
00035 
00036 class MovementControllerI : public RobotBrainComponent
00037 {
00038 public:
00039 
00040   MovementControllerI(int id, OptionManager& mgr,
00041                       const std::string& descrName = "MovementController",
00042                       const std::string& tagName = "MovementController");
00043 
00044   ~MovementControllerI();
00045 
00046   virtual void evolve();
00047 
00048   virtual void updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00049                              const Ice::Current&);
00050 
00051   virtual void registerTopics();
00052 
00053 
00054   // Represents a pose that a SensorVote can set
00055   struct SensorPose
00056   {
00057     float val; // value of pose
00058     float weight; // weight of pose
00059     float decay; // how fast the weight should decay (0 = none)
00060   };
00061 
00062   // The various types of SensorVotes we use
00063   enum SensorType { PATH, SALIENCY, PINGER, BARBWIRE };
00064 
00065   // A vote for what the pose of the sub should be according to
00066   // one of our sensors (i.e. salient point or path found in bottom cam)
00067   struct SensorVote
00068   {
00069     enum SensorType type; // sensor type
00070     SensorPose heading; // sensor's vote for absolute heading
00071     SensorPose depth; // sensor's vote for relative depth
00072 
00073     bool init; // whether or not the SensorVote has a val set
00074   };
00075 
00076 private:
00077 
00078   // Different function for each state
00079   void state_init();
00080   void state_do_gate();
00081   void state_find_flare();
00082   void state_do_flare();
00083   void state_find_barbwire();
00084   void state_do_barbwire();
00085   void state_find_bombing();
00086   void state_do_bombing();
00087   void state_find_briefcase();
00088   void state_do_briefcase();
00089   void state_path_follow();
00090 
00091   // Setter functions for the pose of the submarine.
00092   // Each function sends a message to the BeeStemI
00093   void set_heading(int heading);
00094   void set_depth(int depth);
00095   void set_speed(int speed);
00096 
00097   // Enable/Disable PID by sending message to BeeStemI
00098   void enablePID();
00099   void disablePID();
00100 
00101   // Initialize all the SensorVotes
00102   void initSensorVotes();
00103 
00104 
00105   /**Start Command-line Options**/
00106 
00107   // how many secs we should sleep while going through gate
00108   OModelParam<float> itsGateFwdTime;
00109   // how deep we should dive (relative to current depth) for gate
00110   OModelParam<float> itsGateDepth;
00111 
00112   // how much we should correct heading based on salient point x position
00113   OModelParam<float> itsSaliencyHeadingCorrScale;
00114   // how much we should correct depth based on salient point y position
00115   OModelParam<float> itsSaliencyDepthCorrScale;
00116   // scales how fast we should go based on how far we are from desired heading and depth
00117   OModelParam<float> itsSpeedCorrScale;
00118 
00119   /**End Command-line Options**/
00120 
00121 
00122   // Stores the sub's current mission state
00123   unsigned int itsCurrentState;
00124 
00125   // checkers so we don't do states twice
00126   int checker_path_follow_1;
00127   int checker_path_follow_2;
00128   int checker_path_follow_3;
00129 
00130   // Variables to store the sub's current pose according to messages
00131   // received from the BeeStemI
00132   int its_current_heading;
00133   int its_current_ex_pressure;
00134   int its_current_int_pressure;
00135 
00136   // lock for current pose variables
00137   IceUtil::Mutex its_current_pose_mutex;
00138 
00139   // Stores the current state of the kill switch according to BeeStemI
00140   char itsKillSwitchState;
00141 
00142   // Vector that stores all of the sub's SensorVotes
00143   std::vector<SensorVote> itsSensorVotes;
00144 
00145   // The combined error of our current heading and depth from our desired heading and depth
00146   float itsPoseError;
00147 
00148   // Stores the last values we set for our heading, depth, and speed.
00149   // These are used to limit the number of messages sent to the BeeStemI
00150   // by ensuring that we only send a message if the current pose differs
00151   // from the last pose by MIN_POSE_DIFF amount
00152   float itsLastCompositeHeading, itsLastCompositeDepth, itsLastSpeed;
00153 
00154   // Used to perform intialization steps on first evolve() loop
00155   bool isInit;
00156 
00157   // Stores our currently desired dive value. Used to store intermediate dive values when
00158   // as we dive in 4 stages in the beginning.
00159   int itsDiveVal;
00160 
00161   // The current dive state we are on (1-4)
00162   char itsDiveCount;
00163 
00164   // Used to store the heading we want to use to go through the gate at the beginning of the mission.
00165   int itsHeadingVal;
00166 
00167   // Stores whether or not PID is currently enabled. Prevents us from sending multiple disable PID messages
00168   // to the BeeStem in the evolve() loop.
00169   bool itsPIDEnabled;
00170 
00171   // Whether or not we should set a new speed in the control loop
00172   bool itsSpeedEnabled;
00173 };
00174 
00175 #endif
Generated on Sun May 8 08:41:38 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3