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