Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

HeadController.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_HeadController_h_
00003 #define INCLUDED_HeadController_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 /*! The communication protocol is a very simple binary format, shared
00015  *  with WalkControllerBehavior.  Each command is sent as a 5-byte
00016  *  group.  The first byte is a command selector, and the following 4
00017  *  bytes are a floating point argument:
00018  *
00019  *  - <@c char: command indicator>
00020  *  - <@c float: value>
00021  *  
00022  *  The valid values for command indicator are given by #CMD_tilt,
00023  *  #CMD_pan, or #CMD_roll ('t', 'p', or 'r' respectively).
00024  */  
00025 class HeadController : public BehaviorBase {
00026 
00027  public:  
00028   //! Points to the one HeadController object that the input
00029   //! command stream is talking to. A kludge. Dunno how you're gonna
00030   //! make sure you're not using this uninitialized.
00031   static HeadController * theOne;
00032   static int mechacmd_callback(char *buf, int bytes); //!< called by wireless when there's new data
00033 
00034  protected:
00035   MotionManager::MC_ID head_id;   //!< the HeadPointerMC to use
00036  
00037  private:
00038   //!@name Command Bytes
00039   static const char CMD_tilt  = 't'; //!< handy symbol for matching incoming communication
00040   static const char CMD_pan   = 'p';
00041   static const char CMD_roll  = 'r';
00042   //@}
00043 
00044   float t; //!< head parameter
00045   float p; //!< head parameter
00046   float r; //!< head parameter
00047 
00048   //! The last HPCB object that was theOne, so we can restore it
00049   //! to prominence when we die. This is a nice gesture, but it doesn't
00050   //! really make sense since we're all using the same port. But just
00051   //! in case something changes and we don't do that, this mechanism
00052   //! is in place.
00053   HeadController *theLastOne;
00054 
00055   //! The input command stream socket
00056   Socket *cmdsock;
00057 
00058   //! Executes a command. Called by mechacmd_callback.
00059   void runCommand(unsigned char *command);
00060 
00061   HeadController(const HeadController&); //!< don't call
00062   HeadController operator=(const HeadController&); //!< don't call
00063 
00064  public:
00065   //! constructor
00066   HeadController() :
00067     BehaviorBase("HeadController"),
00068     head_id(MotionManager::invalid_MC_ID),
00069     t(0), p(0), r(0),
00070     theLastOne(theOne),
00071     cmdsock(NULL)
00072   {}
00073   //! destructor
00074   virtual ~HeadController() { theOne = theLastOne; }
00075 
00076   virtual void doStart();
00077 
00078   virtual void doStop();
00079 
00080   static std::string getClassDescription() {
00081     char tmp[20];
00082     sprintf(tmp,"%d",*config->main.headControl_port);
00083     return std::string("Listens to head control commands coming in from port ")+tmp;
00084   }
00085   virtual std::string getDescription() const { return getClassDescription(); }
00086 };
00087 
00088 /*! @file
00089  * @brief Describes HeadController, listens to control commands coming in from the command port for remotely controlling the head
00090  * @author tss (Creator)
00091  */
00092 
00093 #endif 

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:41 2016 by Doxygen 1.6.3