Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

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

Tekkotsu v1.4
Generated Sat Jul 19 00:06:32 2003 by Doxygen 1.3.2