Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WalkControllerBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_WalkControllerBehavior_h_
00003 #define INCLUDED_WalkControllerBehavior_h_
00004 
00005 #include <iostream>
00006 #include "Wireless/Wireless.h"
00007 #include "Behaviors/BehaviorBase.h"
00008 #include "Motion/MotionManager.h"
00009 #include "Motion/WalkMC.h"
00010 #include "Motion/MMAccessor.h"
00011 #include "Events/EventRouter.h"
00012 #include "Events/EventBase.h"
00013 #include "Shared/Config.h"
00014 
00015 //! Listens to control commands coming in from the command port for remotely controlling the walk
00016 /*! The communication protocol is a very simple binary format, shared
00017  *  with HeadPointControllerBehavior.  Each command is sent as a
00018  *  5-byte group.  The first byte is a command selector, and the
00019  *  following 4 bytes are a floating point argument:
00020  *
00021  *  - <@c char: command indicator>
00022  *  - <@c float: value>
00023  *  
00024  *  The valid values for command indicator are given by #CMD_fwd,
00025  *  #CMD_roto, or #CMD_side ('f', 'r', or 's' respectively).  Others
00026  *  are listed below, but are not currently used.
00027  */  
00028 class WalkControllerBehavior : public BehaviorBase {
00029 
00030  public:  
00031   //! Points to the one WalkControllerBehavior object that the input
00032   //! command stream is talking to. A kludge. Dunno how you're gonna
00033   //! make sure you're not using this uninitialized.
00034   static WalkControllerBehavior * theOne;
00035   static int mechacmd_callback(char *buf, int bytes); //!< called by wireless when there's new data
00036 
00037  protected:
00038   SharedObject<WalkMC> shared_walker; //!< the WalkMC to use
00039  
00040  private:
00041   //!@name Command Bytes
00042   static const char CMD_fwd  = 'f'; //!< handy symbol for matching incoming communication
00043   static const char CMD_roto = 'r';
00044   static const char CMD_side = 's';
00045   static const char CMD_opt0 = '0';
00046   static const char CMD_opt1 = '1';
00047   static const char CMD_opt2 = '2';
00048   static const char CMD_opt3 = '3';
00049   static const char CMD_opt4 = '4';
00050   static const char CMD_opt5 = '5';
00051   static const char CMD_opt6 = '6';
00052   static const char CMD_opt7 = '7';
00053   static const char CMD_opt8 = '8';
00054   static const char CMD_opt9 = '9';
00055   //@}
00056 
00057   float dx; //!< Motion parameter
00058   float dy; //!< Motion parameter
00059   float da; //!< Motion parameter
00060 
00061   //! The last WCB object that was theOne, so we can restore it
00062   //! to prominence when we die. This is a nice gesture, but it doesn't
00063   //! really make sense since we're all using the same port. But just
00064   //! in case something changes and we don't do that, this mechanism
00065   //! is in place.
00066   WalkControllerBehavior *theLastOne;
00067 
00068   //! The input command stream socket
00069   Socket *cmdsock;
00070 
00071   //! Executes a command. Called by mechacmd_callback.
00072   void runCommand(unsigned char *command);
00073 
00074   WalkControllerBehavior(const WalkControllerBehavior&); //!< don't call
00075   WalkControllerBehavior operator=(const WalkControllerBehavior&); //!< don't call
00076 
00077  public:
00078   //! constructor
00079   WalkControllerBehavior() :
00080     BehaviorBase("WalkControllerBehavior"),
00081     shared_walker(),
00082     dx(0), dy(0), da(0),
00083     theLastOne(theOne),
00084     cmdsock(NULL)
00085   {}
00086   //! destructor
00087   virtual ~WalkControllerBehavior() { theOne = theLastOne; }
00088 
00089   virtual void DoStart();
00090 
00091   virtual void DoStop();
00092 
00093   virtual WalkMC * getWalkMC() { return &(*shared_walker); }  //!< returns the WalkMC which [will be|is being] used
00094 
00095   virtual MotionManager::MC_ID getWalkID() { return shared_walker->getID(); } //!< returns the current Walk's MotionCommand ID
00096 
00097   //! The only event we could possibly receive is the stop-if-no-heartbeat timer.
00098   virtual void processEvent(const EventBase &) {
00099     MMAccessor<WalkMC> walker(getWalkID());
00100     walker->setTargetVelocity(0,0,0);
00101   }
00102 
00103   static std::string getClassDescription() {
00104     char tmp[20];
00105     sprintf(tmp,"%d",config->main.walkControl_port);
00106     return std::string("Listens to walk control commands coming in from port ")+tmp;
00107   }
00108   virtual std::string getDescription() const { return getClassDescription(); }
00109 };
00110 
00111 /*! @file
00112  * @brief Describes WalkControllerBehavior, listens to control commands coming in from the command port for remotely controlling the walk
00113  * @author tss (Creator)
00114  * @author ejt (modifications)
00115  * @author PA Gov. School for the Sciences 2003 Team Project - Haoqian Chen, Yantian Martin, Jon Stahlman (modifications)
00116  * 
00117  * $Author: ejt $
00118  * $Name: tekkotsu-3_0 $
00119  * $Revision: 1.5 $
00120  * $State: Exp $
00121  * $Date: 2005/09/13 22:10:36 $
00122  */
00123 
00124 #endif 

Tekkotsu v3.0
Generated Wed Oct 4 00:03:47 2006 by Doxygen 1.4.7