Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VRmixin.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _VRmixin_h_
00003 #define _VRmixin_h_
00004 
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include "Behaviors/BehaviorBase.h"
00009 #include "Shared/debuget.h" // needed for ASSERT macros
00010 #include "Vision/RawCameraGenerator.h"
00011 #include "Vision/SegmentedColorGenerator.h"
00012 #include "Vision/cmv_types.h" // needed for 'run' type?
00013 #include "Wireless/Wireless.h"
00014 #include "Shared/Config.h"
00015 #include "Shared/RobotInfo.h"
00016 #include "Shared/get_time.h" // needed for time stamp, for serialization 
00017 
00018 #include "ShapeAgent.h"
00019 #include "BlobData.h"
00020 #include "PFShapeSLAM.h"
00021 #include "SketchRoot.h"
00022 
00023 namespace DualCoding {
00024 
00025 class Lookout;
00026 class Pilot;
00027 class SketchDataRoot;
00028 class SketchSpace;
00029 class MapBuilder;
00030 
00031 typedef unsigned char cmap_t;
00032 
00033 //! Mix-in for the BehaviorBase or StateNode class to give access to VisualRoutinesBehavior variables.
00034 class VRmixin {
00035 protected:
00036   static unsigned int instanceCount; //!< count of NewVRmixin instances -- when this hits zero, free sketch spaces
00037   static unsigned int crewCount; //!< count of "crew" (pilot, lookout, map builders) users -- stop these when no one is using them
00038   
00039 public:
00040   //! returns reference to the global space instances, call there from global constructors instead of accessing #camSkS, which might not be initialized yet
00041   static SketchSpace& getCamSkS();
00042   static SketchSpace& getLocalSkS();
00043   static SketchSpace& getWorldSkS();
00044   static ShapeSpace& getGroundShS();
00045 
00046   static SketchSpace& camSkS;      //!< The camera sketch space
00047   static ShapeSpace& camShS;       //!< The camera shape space
00048   
00049   static ShapeSpace& groundShS;    //!< The ground shape space of MapBuilder (MapBuilder::groundShS)
00050   
00051   static SketchSpace& localSkS;    //!< The localmap sketch space (LocalMapBuilder::localSkS)
00052   static ShapeSpace& localShS;     //!< The localmap shape space (LocalMapBuilder::localShS)
00053   
00054   static SketchSpace& worldSkS;    //!< The worldmap sketch space (WorldMapBuilder::localSkS)
00055   static ShapeSpace& worldShS;     //!< The worldmap sketch space (WorldMapBuilder::localShS)
00056   static Shape<AgentData> theAgent; //!< The robot (usually lives in worldShS)
00057   
00058   //! returns reference to the global WorldMapBuilder instance, call this from global constructors instead of accessing #worldSkS/#localSkS/#groundShS/etc., which might not be initialized yet
00059   static MapBuilder& getMapBuilder();
00060   static MapBuilder& mapBuilder;   //!< the global world mapbuilder instance
00061 
00062   static Lookout& getLookout();
00063   static Lookout &lookout;         //!< the global Lookout instance
00064   
00065   static Pilot& getPilot();
00066   static Pilot& pilot;              //!< the global Pilot instance
00067 
00068   static PFShapeLocalization *particleFilter;   //!< the global particle filter instance
00069 
00070 private:
00071   static Socket *camDialogSock;    //!< socket to talk with cam-space sketch viewer
00072   static Socket *camRleSock;       //!< socket for transmitting RLE images to cam-space sketch viewer
00073   static Socket *localDialogSock;  //!< socket to talk with local-space sketch viewer
00074   static Socket *localRleSock;     //!< socket for transmitting RLE images to local-space sketch viewer
00075   static Socket *worldDialogSock;  //!< socket to talk with world-space sketch viewer
00076   static Socket *worldRleSock;     //!< socket for transmitting RLE images to world-space sketch viewer
00077   
00078 public:
00079   //! Constructor
00080   VRmixin();
00081 
00082   //! Destructor
00083   virtual ~VRmixin(void);
00084   
00085   static void startCrew(); //!< starts map builders, pilot, and lookout
00086   static void stopCrew(); //!< stops map builders, pilot, and lookout
00087 
00088   // serialize the specified Sketch; should use RLE encoding later 
00089   static bool rleEncodeSketch(const SketchDataRoot& image);
00090   
00091   //! Import the current color-segmented camera image as a Sketch<uchar>
00092   static Sketch<uchar> sketchFromSeg();
00093   
00094   //! Import channel n image as a Sketch<uchar>
00095   static Sketch<uchar> sketchFromChannel(const RawCameraGenerator::channel_id_t chan);
00096   
00097   //! Import the current y-channel camera image as a Sketch<uchar>
00098   static Sketch<uchar> sketchFromRawY();
00099   
00100   //! Import blobs from the current region list as a vector of Shape<BlobData>
00101   static std::vector<Shape<BlobData> >
00102   getBlobsFromRegionGenerator(const color_index color, int minarea=25,
00103             const BlobData::BlobOrientation_t orient=BlobData::groundplane,
00104             const coordinate_t height=0,
00105             const int maxblobs=50);
00106   
00107   //! processes a single line of input for a Sketch request
00108   static void processSketchRequest(const std::string &line, 
00109            SketchSpace &sketches, 
00110            ShapeSpace &shapes);
00111   
00112   //! project shapes from cam space to ground space
00113 #ifdef TGT_HAS_CAMERA
00114   static void projectToGround(const NEWMAT::Matrix& camToBase = kine->jointToBase(CameraFrameOffset),
00115             const NEWMAT::ColumnVector& ground_plane = kine->calculateGroundPlane());
00116 #else
00117   // no camera, require they provide the camToBase parameter...
00118   static void projectToGround(const NEWMAT::Matrix& camToBase,
00119             const NEWMAT::ColumnVector& ground_plane = kine->calculateGroundPlane());
00120 #endif
00121 
00122 private:
00123   //! used so static member functions can access non-static members
00124   static VRmixin* theOne;
00125   
00126   // dummy functions to satisfy the compiler
00127   VRmixin (const VRmixin&);  //!< never call this
00128   VRmixin& operator=(const VRmixin&); //!< never call this
00129   
00130   //! Called whenever data is received on camDialogSocket
00131   static int camDialogSockCallback(char *buf, int bytes);
00132   
00133   //! Called whenever data is received on localDialogSocket
00134   static int localDialogSockCallback(char *buf, int bytes);
00135   
00136   //! Called whenever data is received on worldDialogSocket
00137   static int worldDialogSockCallback(char *buf, int bytes);
00138   
00139   static void dialogCallback(char* buf, int bytes, std::string& incomplete,
00140            SketchSpace &SkS, ShapeSpace &ShS);
00141 };
00142   
00143 } // namespace
00144 
00145 #endif

DualCoding 4.0
Generated Thu Nov 22 00:52:37 2007 by Doxygen 1.5.4