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 "SoundPlay/SoundManager.h"
00014 #include "Shared/Config.h"
00015
00016
00017 class WalkControllerBehavior : public BehaviorBase {
00018
00019 public:
00020
00021
00022
00023 static WalkControllerBehavior * theOne;
00024 static int mechacmd_callback(char *buf, int bytes);
00025
00026 protected:
00027 MotionManager::MC_ID walker_id;
00028
00029 private:
00030
00031 static const char CMD_fwd = 'f';
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;
00047 float dy;
00048 float da;
00049
00050
00051
00052
00053
00054
00055 WalkControllerBehavior *theLastOne;
00056
00057
00058 Socket *cmdsock;
00059
00060
00061 void runCommand(unsigned char *command);
00062
00063 WalkControllerBehavior(const WalkControllerBehavior&);
00064 WalkControllerBehavior operator=(const WalkControllerBehavior&);
00065
00066 public:
00067
00068 WalkControllerBehavior() :
00069 BehaviorBase(),
00070 walker_id(MotionManager::invalid_MC_ID),
00071 dx(0), dy(0), da(0),
00072 theLastOne(theOne),
00073 cmdsock(wireless->socket(SocketNS::SOCK_STREAM, 2048, 2048))
00074 { theOne = this; }
00075
00076 virtual ~WalkControllerBehavior() { theOne = theLastOne; }
00077
00078 virtual void DoStart();
00079
00080 virtual void DoStop();
00081
00082
00083 virtual void processEvent(const EventBase &) {
00084 MMAccessor<WalkMC> walker(walker_id);
00085 walker->setTargetVelocity(0,0,0);
00086 }
00087
00088 virtual std::string getName() const { return "Walk Remote Control"; }
00089 static std::string getClassDescription() {
00090 char tmp[20];
00091 sprintf(tmp,"%d",config->main.walkControl_port);
00092 return std::string("Listens to walk control commands coming in from port ")+tmp;
00093 }
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #endif