Homepage Demos Overview Downloads Tutorials Reference
Credits

SegCamBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SegCamBehavior_h_
00003 #define INCLUDED_SegCamBehavior_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Shared/Config.h"
00007 
00008 class Socket;
00009 class FilterBankGenerator;
00010 class FilterBankEvent;
00011 
00012 //! Forwards segmented images from camera over wireless
00013 /*! The format used for serialization is basically defined by the
00014  *  subclass of FilterBankGenerator being used.  I suggest looking at
00015  *  that classes's documentation to determine the format used.
00016  *
00017  *  However, SegCamBehavior will add a few fields at the beginning of
00018  *  each packet to assist in processing the image stream.
00019  *
00020  *  I emphasize: <i>beginning</i> of each Vision packet, <i>before</i> the FilterBankGenerator header. 
00021  *  - <@c string:"TekkotsuImage">
00022  *  - <<tt>Config::vision_config::encoding_t</tt>: Config::vision_config::ENCODE_SINGLE_CHANNEL> <i>(always just sends a single channel)</i>
00023  *  - <<tt>Config::vision_config::compression_t</tt>: Config::vision_config::COMPRESS_RLE> <i>(This is misleading - may actually be uncompressed, but this signals it's a segmented color image)</i>
00024  *  - <@c unsigned @c int: width> <i>(this is the width of the largest channel - note different channels can be sent at different resolutions!  Provides cheap "compression" of chromaticity channels)</i>
00025  *  - <@c unsigned @c int: height> <i>(similarly, height of largest channel)</i>
00026  *  - <@c unsigned @c int: timestamp> <i>(time image was taken, milliseconds since boot)</i>
00027  *  - <@c unsigned @c int: framenumber> <i>(incremented for each frame, so we can tell if/when we drop one)</i>
00028  *
00029  *  This is exactly the same protocol that is followed by the
00030  *  RawCamBehavior as well - the same code can parse either stream.
00031  *
00032  *  However, odd bit - since the RLEGenerator doesn't save the color
00033  *  information itself, SegCamBehavior will do it instead.  So, if
00034  *  SegCamBehavior is using RLE compression, it will tack a footer at
00035  *  the end of the packet: (from SegmentedColorGenerator::encodeColors())
00036  *  - <@c unsigned @c int: num_cols> <i>(number of different colors available)</i>
00037  *  - for each of num_col:
00038  *    - <@c char: red> <i>red color to use for display of this index</i>
00039  *    - <@c char: green> <i>green color to use for display of this index</i>
00040  *    - <@c char: blue> <i>blue color to use for display of this index</i>
00041  */ 
00042 class SegCamBehavior : public BehaviorBase {
00043 public:
00044   //! constructor
00045   SegCamBehavior();
00046 
00047   static const unsigned int WIRELESS_BUFFER_SIZE=85000; //!< 85000 bytes for use up to 416x320 pixels / 8 min expected runs * 5 bytes per run + some padding
00048 
00049   virtual void DoStart();
00050 
00051   virtual void DoStop();
00052 
00053   virtual void processEvent(const EventBase& e);
00054 
00055   virtual std::string getName() const { return "SegCamServer"; }
00056 
00057   static std::string getClassDescription() {
00058     char tmp[20];
00059     sprintf(tmp,"%d",config->vision.rle_port);
00060     return std::string("Forwards segmented images from camera over port ")+tmp;
00061   }
00062   
00063 protected:
00064   //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error)
00065   /*! see the class documentation for SegCamBehavior for the protocol documentation */
00066   bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 
00067   bool writeRLE(const FilterBankEvent& fbke); //!< writes a color image
00068   bool writeSeg(const FilterBankEvent& fbke); //!< writes a color image
00069   void closePacket(); //!< closes and sends a packet, does nothing if no packet open
00070 
00071   Socket * visRLE; //!< socket to send image stream over
00072   char * packet; //!< buffer being filled out to be sent
00073   char * cur; //!< current location in #packet
00074   unsigned int avail; //!< number of bytes remaining in #packet
00075 
00076 private:
00077   SegCamBehavior(const SegCamBehavior&); //!< don't call
00078   SegCamBehavior& operator=(const SegCamBehavior&); //!< don't call
00079 };
00080 
00081 /*! @file
00082  * @brief Describes SegCamBehavior, which forwards segmented images from camera over wireless
00083  * @author ejt (Creator)
00084  *
00085  * $Author: ejt $
00086  * $Name: tekkotsu-2_1 $
00087  * $Revision: 1.5 $
00088  * $State: Exp $
00089  * $Date: 2004/02/05 23:33:41 $
00090  */
00091 
00092 #endif

Tekkotsu v2.1
Generated Tue Mar 16 23:19:15 2004 by Doxygen 1.3.5