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 TCP_WIRELESS_BUFFER_SIZE=85000; //!< 85000 bytes for use up to 416x320 pixels / 8 min expected runs * 5 bytes per run + some padding
00048   static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size
00049 
00050   virtual void DoStart();
00051 
00052   virtual void DoStop();
00053 
00054   virtual void processEvent(const EventBase& e);
00055 
00056   static std::string getClassDescription() {
00057     char tmp[20];
00058     sprintf(tmp,"%d",config->vision.rle_port);
00059     return std::string("Forwards segmented images from camera over port ")+tmp;
00060   }
00061   virtual std::string getDescription() const { return getClassDescription(); }
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   unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated
00076 
00077 private:
00078   SegCamBehavior(const SegCamBehavior&); //!< don't call
00079   SegCamBehavior& operator=(const SegCamBehavior&); //!< don't call
00080 };
00081 
00082 /*! @file
00083  * @brief Describes SegCamBehavior, which forwards segmented images from camera over wireless
00084  * @author ejt (Creator)
00085  *
00086  * $Author: ejt $
00087  * $Name: tekkotsu-2_2_2 $
00088  * $Revision: 1.7 $
00089  * $State: Exp $
00090  * $Date: 2004/11/11 01:45:36 $
00091  */
00092 
00093 #endif

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0