Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

HeadPointControllerBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_HeadPointControllerBehavior_h_
00003 #define INCLUDED_HeadPointControllerBehavior_h_
00004 
00005 #include <iostream>
00006 #include "Wireless/Wireless.h"
00007 #include "Behaviors/BehaviorBase.h"
00008 #include "Motion/MotionManager.h"
00009 #include "Events/EventRouter.h"
00010 #include "Events/EventBase.h"
00011 #include "Shared/Config.h"
00012 
00013 //! Listens to control commands coming in from the command port for remotely controlling the head
00014 class HeadPointControllerBehavior : public BehaviorBase {
00015 
00016  public:  
00017   //! Points to the one HeadPointControllerBehavior object that the input
00018   //! command stream is talking to. A kludge. Dunno how you're gonna
00019   //! make sure you're not using this uninitialized.
00020   static HeadPointControllerBehavior * theOne;
00021   static int mechacmd_callback(char *buf, int bytes); //!< called by wireless when there's new data
00022 
00023  protected:
00024   MotionManager::MC_ID head_id;   //!< the HeadPointerMC to use
00025  
00026  private:
00027   //!@name Command Bytes
00028   static const char CMD_tilt  = 't'; //!< handy symbol for matching incoming communication
00029   static const char CMD_pan   = 'p';
00030   static const char CMD_roll  = 'r';
00031   //@}
00032 
00033   float t; //!< head parameter
00034   float p; //!< head parameter
00035   float r; //!< head parameter
00036 
00037   //! The last HPCB object that was theOne, so we can restore it
00038   //! to prominence when we die. This is a nice gesture, but it doesn't
00039   //! really make sense since we're all using the same port. But just
00040   //! in case something changes and we don't do that, this mechanism
00041   //! is in place.
00042   HeadPointControllerBehavior *theLastOne;
00043 
00044   //! The input command stream socket
00045   Socket *cmdsock;
00046 
00047   //! Executes a command. Called by mechacmd_callback.
00048   void runCommand(unsigned char *command);
00049 
00050   HeadPointControllerBehavior(const HeadPointControllerBehavior&); //!< don't call
00051   HeadPointControllerBehavior operator=(const HeadPointControllerBehavior&); //!< don't call
00052 
00053  public:
00054   //! constructor
00055   HeadPointControllerBehavior() :
00056     BehaviorBase("HeadPointControllerBehavior"),
00057     head_id(MotionManager::invalid_MC_ID),
00058     t(0), p(0), r(0),
00059     theLastOne(theOne),
00060     cmdsock(NULL)
00061   {}
00062   //! destructor
00063   virtual ~HeadPointControllerBehavior() { theOne = theLastOne; }
00064 
00065   virtual void DoStart();
00066 
00067   virtual void DoStop();
00068 
00069   static std::string getClassDescription() {
00070     char tmp[20];
00071     sprintf(tmp,"%d",config->main.headControl_port);
00072     return std::string("Listens to head control commands coming in from port ")+tmp;
00073   }
00074   virtual std::string getDescription() const { return getClassDescription(); }
00075 };
00076 
00077 /*! @file
00078  * @brief Describes HeadPointControllerBehavior, listens to control commands coming in from the command port for remotely controlling the head
00079  * @author tss (Creator)
00080  * 
00081  * $Author: ejt $
00082  * $Name: tekkotsu-2_4_1 $
00083  * $Revision: 1.5 $
00084  * $State: Exp $
00085  * $Date: 2005/06/10 19:18:59 $
00086  */
00087 
00088 #endif 

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:47 2005 by Doxygen 1.4.4