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