00001
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
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class WalkControllerBehavior : public BehaviorBase {
00029
00030 public:
00031
00032
00033
00034 static WalkControllerBehavior * theOne;
00035 static int mechacmd_callback(char *buf, int bytes);
00036
00037 protected:
00038 SharedObject<WalkMC> shared_walker;
00039
00040 private:
00041
00042 static const char CMD_fwd = 'f';
00043 static const char CMD_roto = 'r';
00044 static const char CMD_side = 's';
00045 static const char CMD_opt0 = '0';
00046 static const char CMD_opt1 = '1';
00047 static const char CMD_opt2 = '2';
00048 static const char CMD_opt3 = '3';
00049 static const char CMD_opt4 = '4';
00050 static const char CMD_opt5 = '5';
00051 static const char CMD_opt6 = '6';
00052 static const char CMD_opt7 = '7';
00053 static const char CMD_opt8 = '8';
00054 static const char CMD_opt9 = '9';
00055
00056
00057 float dx;
00058 float dy;
00059 float da;
00060
00061
00062
00063
00064
00065
00066 WalkControllerBehavior *theLastOne;
00067
00068
00069 Socket *cmdsock;
00070
00071
00072 void runCommand(unsigned char *command);
00073
00074 WalkControllerBehavior(const WalkControllerBehavior&);
00075 WalkControllerBehavior operator=(const WalkControllerBehavior&);
00076
00077 public:
00078
00079 WalkControllerBehavior() :
00080 BehaviorBase("WalkControllerBehavior"),
00081 shared_walker(),
00082 dx(0), dy(0), da(0),
00083 theLastOne(theOne),
00084 cmdsock(NULL)
00085 {}
00086
00087 virtual ~WalkControllerBehavior() { theOne = theLastOne; }
00088
00089 virtual void DoStart();
00090
00091 virtual void DoStop();
00092
00093 virtual WalkMC * getWalkMC() { return &(*shared_walker); }
00094
00095 virtual MotionManager::MC_ID getWalkID() { return shared_walker->getID(); }
00096
00097
00098 virtual void processEvent(const EventBase &) {
00099 MMAccessor<WalkMC> walker(getWalkID());
00100 walker->setTargetVelocity(0,0,0);
00101 }
00102
00103 static std::string getClassDescription() {
00104 char tmp[20];
00105 sprintf(tmp,"%d",config->main.walkControl_port);
00106 return std::string("Listens to walk control commands coming in from port ")+tmp;
00107 }
00108 virtual std::string getDescription() const { return getClassDescription(); }
00109 };
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 #endif