Go to the documentation of this file.00001
00002 #ifndef FRICOMM_HH
00003 #define FRICOMM_HH
00004
00005 #include <netinet/in.h>
00006 #include <pthread.h>
00007
00008 #include <sys/time.h>
00009
00010 #include <friComm.h>
00011
00012 #include <string>
00013
00014 #include "FRIData.hh"
00015
00016 class FRICheck;
00017
00018
00058 class CartesianImpedanceControl;
00059
00060 class FRIComm
00061 {
00062 public:
00063 FRIComm();
00064 ~FRIComm();
00065
00067 void configureNetwork(int local_port, std::string remote_address, int remote_port);
00068
00069 bool open();
00070 void close();
00071
00072 FRICheck* limitChecker() {return safety_;}
00073
00074 RobotData data();
00075 RobotStatus status();
00076
00077 RobotCommand cmd();
00078 void setCmd(RobotCommand cmd);
00079
00080
00081 void setRunstop(bool stopped);
00082 bool runstop();
00083 bool postCommand(int iData[16], float rData[16]);
00084
00085 bool receive();
00086 void respond();
00087
00088 static const char* printStatus(char* buffer,
00089 RobotData data,
00090 RobotCommand cmd,
00091 RobotStatus status);
00092
00093 tFriMsrData fri_msr_;
00094 tFriCmdData fri_cmd_;
00095 private:
00096 static const float KRL_TIMEOUT=4.5;
00097 static const float KRL_GUARD_TIME = 0.8;
00098 float krl_time_;
00099 void processCommand();
00100 void stateHandler();
00101
00102 FRICheck *safety_;
00103 FRICheck *safety2_;
00104
00105 unsigned int seq_;
00106 bool closing_;
00107 bool runstop_;
00108
00109 int local_port_, remote_port_;
00110 std::string remote_address_;
00111 int socket_;
00112 struct sockaddr_in remote_addr_;
00113
00114 bool useCartesianImpedance_;
00115 CartesianImpedance cartesianImpedanceCmd_;
00116
00117 CartesianImpedanceControl* cartesianImpedance_;
00118
00119
00120 struct timeval last_tick;
00121 long long duration_sum;
00122 int duration_num;
00123 int duration_max;
00124 int duration_mean_published;
00125 int duration_max_published;
00126 void tick();
00127 void tock();
00128 };
00129
00130
00131
00133
00134 class FRIThread
00135 {
00136 public:
00137 FRIThread();
00138
00140 void configureNetwork(int local_port, const char* remote_address, int remote_port);
00141
00142 bool start();
00143
00144 bool running();
00145 void finish();
00146
00147 RobotData data();
00148
00149 RobotCommand cmd();
00150 void setCmd(RobotCommand cmd);
00151
00152 bool runstop();
00153 void setRunstop(bool stopped);
00154
00155 RobotStatus status();
00156
00157 FRICheck* limitChecker();
00158
00159 void postCommand(int iData[16], float rData[16]);
00160 private:
00161 FRIComm fri;
00162
00163 void* run();
00164 static void* run_s(void *ptr) { return ((FRIThread *) ptr)->run(); }
00165 bool exitRequested_, running_;
00166
00167 pthread_t thread_;
00168 pthread_mutex_t mutex_;
00169
00170 class KRLCmd {
00171 public:
00172 int iData[16];
00173 float rData[16];
00174 bool fresh;
00175 };
00176
00177 bool runstop_buffer_;
00178 RobotData data_buffer_;
00179 RobotCommand cmd_buffer_;
00180 RobotStatus status_buffer_;
00181 KRLCmd krlcmd_buffer_;
00182 };
00183
00184 #endif // FRICOMM_HH