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

Tekkotsu v4.0
Generated Thu Nov 22 00:54:56 2007 by Doxygen 1.5.4