WalkController.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_WalkController_h_
00003 #define INCLUDED_WalkController_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 #include "IPC/SharedObject.h"
00014
00015 #include <iostream>
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class WalkController : public BehaviorBase {
00031
00032 public:
00033
00034
00035
00036 static WalkController * theOne;
00037 static int mechacmd_callback(char *buf, int bytes);
00038
00039 protected:
00040 enum { TIMER_COMM_CHECK, TIMER_COMM_TIMEOUT };
00041 SharedObject<WalkMC> shared_walker;
00042
00043 private:
00044
00045 static const char CMD_fwd = 'f';
00046 static const char CMD_roto = 'r';
00047 static const char CMD_side = 's';
00048 static const char CMD_opt0 = '0';
00049 static const char CMD_opt1 = '1';
00050 static const char CMD_opt2 = '2';
00051 static const char CMD_opt3 = '3';
00052 static const char CMD_opt4 = '4';
00053 static const char CMD_opt5 = '5';
00054 static const char CMD_opt6 = '6';
00055 static const char CMD_opt7 = '7';
00056 static const char CMD_opt8 = '8';
00057 static const char CMD_opt9 = '9';
00058
00059
00060 float dx;
00061 float dy;
00062 float da;
00063
00064 bool keepGUI;
00065
00066
00067
00068
00069
00070
00071 WalkController *theLastOne;
00072
00073
00074 Socket *cmdsock;
00075
00076 int sock;
00077
00078
00079 void runCommand(unsigned char *command);
00080
00081
00082 void shutdown();
00083
00084 WalkController(const WalkController&);
00085 WalkController operator=(const WalkController&);
00086
00087 public:
00088
00089 WalkController() :
00090 BehaviorBase("WalkController"),
00091 shared_walker(),
00092 dx(0), dy(0), da(0), keepGUI(false),
00093 theLastOne(theOne),
00094 cmdsock(NULL), sock(-1)
00095 {}
00096
00097 virtual ~WalkController() { theOne = theLastOne; }
00098
00099 virtual void doStart();
00100
00101 virtual void doStop();
00102
00103 void setKeepGUI(bool b=true) { keepGUI = b; }
00104
00105 virtual WalkMC * getWalkMC() { return &(*shared_walker); }
00106
00107 virtual MotionManager::MC_ID getWalkID() { return shared_walker->getID(); }
00108
00109
00110 virtual void doEvent() {
00111 if(event->getGeneratorID()==EventBase::runtimeEGID && event->getTypeID()==EventBase::deactivateETID) {
00112 shutdown();
00113 BehaviorBase::doStop();
00114 return;
00115 }
00116 if(event->getSourceID()==TIMER_COMM_TIMEOUT) {
00117 MMAccessor<WalkMC> walker(getWalkID());
00118 walker->setTargetVelocity(0,0,0);
00119 }
00120 if(cmdsock!=NULL && !wireless->isConnected(sock))
00121 stop();
00122 }
00123
00124 static std::string getClassDescription() {
00125 char tmp[20];
00126 sprintf(tmp,"%d",*config->main.walkControl_port);
00127 return std::string("Listens to walk control commands coming in from port ")+tmp;
00128 }
00129 virtual std::string getDescription() const { return getClassDescription(); }
00130 };
00131
00132
00133
00134
00135
00136
00137
00138
00139 #endif