00001
00002 #ifndef INCLUDED_StewartPlatformBehavior_h_
00003 #define INCLUDED_StewartPlatformBehavior_h_
00004
00005 #include <iostream>
00006 #include "Behaviors/BehaviorBase.h"
00007 #include "Motion/MotionManager.h"
00008 #include "Shared/Config.h"
00009
00010 class Socket;
00011
00012
00013
00014
00015 class StewartPlatformBehavior : public BehaviorBase {
00016
00017 public:
00018
00019 static StewartPlatformBehavior * theOne;
00020 static int callback(char *buf, int bytes);
00021
00022 public:
00023
00024 StewartPlatformBehavior()
00025 : BehaviorBase("StewartPlatformBehavior"),
00026 cmdsock(NULL), sock(-1), ctxt(NULL), docClosed(false),
00027 pose_id(MotionManager::invalid_MC_ID)
00028 {
00029 theOne=this;
00030 }
00031
00032 virtual ~StewartPlatformBehavior() {
00033 theOne=NULL;
00034 }
00035
00036 virtual void DoStart();
00037
00038 virtual void DoStop();
00039
00040 virtual void processEvent(const EventBase &);
00041
00042 static std::string getClassDescription() {
00043 char tmp[20];
00044 sprintf(tmp,"%d",*config->main.stewart_port);
00045 return std::string("moves the legs in synchrony to emulate the capabilities of a stewart platform, base on commands from port ")+tmp;
00046 }
00047 virtual std::string getDescription() const { return getClassDescription(); }
00048
00049 virtual void setParam(const std::string& cmd, float value);
00050
00051 protected:
00052
00053 Socket *cmdsock;
00054 int sock;
00055
00056
00057 void* ctxt;
00058
00059 bool docClosed;
00060
00061
00062 MotionManager::MC_ID pose_id;
00063
00064
00065 static void* getSAXHandler();
00066
00067
00068
00069 static void sax_start_element(StewartPlatformBehavior * inst, const char * name, const char ** attrs);
00070 static void sax_end_element(StewartPlatformBehavior * inst, const char * name);
00071 static void sax_end_doc(StewartPlatformBehavior * inst);
00072 static void sax_warning(StewartPlatformBehavior *inst, const char *msg, ...);
00073 static void sax_error(StewartPlatformBehavior *inst, const char *msg, ...);
00074 static void sax_fatal_error(StewartPlatformBehavior *inst, const char *msg, ...);
00075
00076
00077 static bool isConnected();
00078 void closeComm();
00079
00080 private:
00081 StewartPlatformBehavior(const StewartPlatformBehavior&);
00082 StewartPlatformBehavior operator=(const StewartPlatformBehavior&);
00083
00084 };
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #endif