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

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:41 2004 by Doxygen 1.3.9.1