Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

UPennWalkControllerBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_UPennWalkControllerBehavior_h_
00003 #define INCLUDED_UPennWalkControllerBehavior_h_
00004 
00005 #include <iostream>
00006 #include "Wireless/Wireless.h"
00007 #include "Behaviors/BehaviorBase.h"
00008 #include "Motion/MotionManager.h"
00009 #include "Motion/UPennWalkMC.h"
00010 #include "Motion/MMAccessor.h"
00011 #include "Events/EventRouter.h"
00012 #include "Events/EventBase.h"
00013 #include "Shared/Config.h"
00014 #include "IPC/SharedObject.h"
00015 
00016 //! Listens to control commands coming in from the command port for remotely controlling the walk
00017 class UPennWalkControllerBehavior : public BehaviorBase {
00018 
00019  public:  
00020   //! Points to the one UPennWalkControllerBehavior 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 UPennWalkControllerBehavior * theOne;
00024   static int mechacmd_callback(char *buf, int bytes); //!< called by wireless when there's new data
00025 
00026  protected:
00027   SharedObject<UPennWalkMC> shared_walker; //!< 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   UPennWalkControllerBehavior *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   UPennWalkControllerBehavior(const UPennWalkControllerBehavior&); //!< don't call
00064   UPennWalkControllerBehavior operator=(const UPennWalkControllerBehavior&); //!< don't call
00065 
00066  public:
00067   //! constructor
00068   UPennWalkControllerBehavior() :
00069     BehaviorBase("UPennWalkControllerBehavior"),
00070     shared_walker(),
00071     dx(0), dy(0), da(0),
00072     theLastOne(theOne),
00073     cmdsock(NULL)
00074   {}
00075   //! destructor
00076   virtual ~UPennWalkControllerBehavior() { theOne = theLastOne; }
00077 
00078   virtual void doStart();
00079 
00080   virtual void doStop();
00081 
00082   virtual UPennWalkMC * getWalkMC() { return &(*shared_walker); }  //!< returns the WalkMC which [will be|is being] used
00083 
00084   virtual MotionManager::MC_ID getWalkID() { return shared_walker->getID(); } //!< returns the current Walk's MotionCommand ID
00085 
00086   //! The only event we could possibly receive is the stop-if-no-heartbeat timer.
00087   virtual void doEvent() {
00088     MMAccessor<UPennWalkMC> walker(getWalkID());
00089     walker->setTargetVelocity(0,0,0);
00090   }
00091 
00092   static std::string getClassDescription() {
00093     char tmp[20];
00094     sprintf(tmp,"%d",*config->main.walkControl_port);
00095     return std::string("Listens to walk control commands coming in from port ")+tmp;
00096   }
00097   virtual std::string getDescription() const { return getClassDescription(); }
00098 };
00099 
00100 /*! @file
00101  * @brief Describes UPennWalkControllerBehavior, listens to control commands coming in from the command port for remotely controlling the walk
00102  * @author tss (Creator)
00103  * @author ejt (modifications)
00104  * @author PA Gov. School for the Sciences 2003 Team Project - Haoqian Chen, Yantian Martin, Jon Stahlman (modifications)
00105  */
00106 
00107 #endif 

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