PursuingMessages.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __PURSUING_MESSAGES__
00027 #define __PURSUING_MESSAGES__
00028
00029 #define PURSUING_MSG_ID "pursuing"
00030 #define PURSUING_CENTRAL_ID 100
00031
00032 #include <Types.h>
00033 #include <string>
00034 #include <vector>
00035
00036 #include <Message.h>
00037
00038 #define MAX_SCAN_SIZE 1024
00039 #define MAX_POSE_ARRAY_SIZE 10
00040
00041 using namespace std;
00042 using namespace MipBaselib;
00043
00046 enum PursuingHeaders {
00047
00048 PUR_HEADER_GO_TO_POSE,
00049 PUR_HEADER_REQ_SCAN,
00050 PUR_HEADER_INITIALIZE,
00051
00052
00053 PUR_HEADER_POSE_AND_SCAN,
00054 PUR_HEADER_POSE,
00055 PUR_HEADER_POSE_ARRAY,
00056 PUR_HEADER_PARAMS,
00057
00058 PUR_HEADERS_NUM,
00059 };
00060
00061 static const char* pursuingHeaderNames[PUR_HEADERS_NUM] = {
00062
00063 "go to pose",
00064 "request scan",
00065 "initialize",
00066
00067
00068 "send pose and scan",
00069 "send pose",
00070 "send pose array",
00071 "send parameters",
00072 };
00073
00074
00075 class PursuingMsg : public MipBaselib::Message{
00076 protected:
00077 PursuingMsg(){
00078 string id(PURSUING_MSG_ID);
00079 setId(id);
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 public:
00091 int robotId;
00092 PursuingHeaders header;
00093
00094 PursuingMsg(const string& inMessage){
00095 inMessage.copy((char* ) this, sizeof(PursuingMsg));
00096 }
00097 };
00098
00099
00100
00101
00102 class PursuingMsgGoToPose : public PursuingMsg{
00103 public:
00104
00105 double x;
00106 double y;
00107 double theta;
00108 bool bReportScan;
00109
00113 PursuingMsgGoToPose(int robotId_, double x_,
00114 double y_,
00115 double theta_,
00116 bool bReportScan_){
00117 robotId = robotId_;
00118 header = PUR_HEADER_GO_TO_POSE;
00119 x = x_;
00120 y = y_;
00121 theta = theta_;
00122 bReportScan = bReportScan_;
00123 }
00124
00126 PursuingMsgGoToPose(const string& inMessage){
00127 constructor<PursuingMsgGoToPose>(inMessage);
00128 }
00129
00132 void encode(string& outMessage){
00133 encoder<PursuingMsgGoToPose>(outMessage);
00134
00135 }
00136 };
00137
00138 class PursuingMsgReqScan : public PursuingMsg{
00139 public:
00140
00141 PursuingMsgReqScan(int robotId_){
00142 robotId = robotId_;
00143 header = PUR_HEADER_REQ_SCAN;
00144 }
00145
00147 PursuingMsgReqScan(const string& inMessage){
00148 constructor<PursuingMsgReqScan>(inMessage);
00149 }
00150
00153 void encode(string& outMessage){
00154 encoder<PursuingMsgReqScan>(outMessage);
00155 }
00156 };
00157
00158 class PursuingMsgInitialize : public PursuingMsg{
00159 public:
00160
00161 PursuingMsgInitialize(int robotId_){
00162 robotId = robotId_;
00163 header = PUR_HEADER_INITIALIZE;
00164 }
00165
00167 PursuingMsgInitialize(const string& inMessage){
00168 constructor<PursuingMsgInitialize>(inMessage);
00169 }
00170
00173 void encode(string& outMessage){
00174 encoder<PursuingMsgInitialize>(outMessage);
00175 }
00176 };
00177
00178
00179
00180 class PursuingMsgPoseAndScan : public PursuingMsg{
00181 public:
00182
00183 double x;
00184 double y;
00185 double theta;
00186 double scanLengthArray[MAX_SCAN_SIZE];
00187 double scanBearingArray[MAX_SCAN_SIZE];
00188 int scanSize;
00189
00190 PursuingMsgPoseAndScan(int robotId_, double x_,
00191 double y_,
00192 double theta_,
00193 Scan &scan){
00194 robotId = robotId_;
00195 header = PUR_HEADER_POSE_AND_SCAN;
00196 x = x_;
00197 y = y_;
00198 theta = theta_;
00199 while( !scan.askExclusiveAccess(Time(1,0)) ) { usleep(1000); };
00200 while( !scan.getSize(scanSize) ){ usleep(1000); };
00201 scanSize = min( MAX_SCAN_SIZE, scanSize );
00202
00203 cout<< " sending scan size " << scanSize << endl;
00204
00205 Ray ray;
00206 for( int i = 0; i < scanSize; i++ )
00207 {
00208 while( !scan.getRay( ray, i ) ) { usleep(1000); };
00209
00210 scanLengthArray[i] = ray.reading();
00211 scanBearingArray[i] = ray.bearing().dCast2Pi();
00212
00213
00214 }
00215 scan.leaveExclusiveAccess();
00216 }
00217
00219 PursuingMsgPoseAndScan(const string& inMessage){
00220 constructor<PursuingMsgPoseAndScan>(inMessage);
00221 }
00222
00225 void encode(string& outMessage){
00226 encoder<PursuingMsgPoseAndScan>(outMessage);
00227 }
00228 };
00229
00230
00231 class PursuingMsgPose : public PursuingMsg{
00232 public:
00233
00234 double x;
00235 double y;
00236 double theta;
00237
00238 PursuingMsgPose(int robotId_, double x_,
00239 double y_,
00240 double theta_){
00241 robotId = robotId_;
00242 header = PUR_HEADER_POSE;
00243 x = x_;
00244 y = y_;
00245 theta = theta_;
00246 }
00247
00249 PursuingMsgPose(const string& inMessage){
00250 constructor<PursuingMsgPose>(inMessage);
00251 }
00252
00255 void encode(string& outMessage){
00256 encoder<PursuingMsgPose>(outMessage);
00257 }
00258 };
00259
00260 class PursuingMsgPoseArray : public PursuingMsg{
00261 public:
00262
00263 double x[MAX_POSE_ARRAY_SIZE];
00264 double y[MAX_POSE_ARRAY_SIZE];
00265 double theta[MAX_POSE_ARRAY_SIZE];
00266
00267 PursuingMsgPoseArray(int robotId_, PoseFeatures poseFeatures){
00268 robotId = robotId_;
00269 header = PUR_HEADER_POSE_ARRAY;
00270
00271 for( int i = 0; i < MAX_POSE_ARRAY_SIZE; i++ )
00272 {
00273 x[i] = -99;
00274 y[i] = -99;
00275 theta[i] = -99;
00276 }
00277
00278 for( int i = 0; i < poseFeatures.size(); i++ )
00279 {
00280 Pose pose = poseFeatures[i].getObj();
00281 int id = poseFeatures[i].getAsso();
00282
00283 if( id < MAX_POSE_ARRAY_SIZE && id >= 0 )
00284 {
00285 x[id] = pose.pos().x();
00286 y[id] = pose.pos().y();
00287 theta[id] = pose.ori().dCast2Pi();
00288 }
00289 }
00290 }
00291
00293 PursuingMsgPoseArray(const string& inMessage){
00294 constructor<PursuingMsgPoseArray>(inMessage);
00295 }
00296
00299 void encode(string& outMessage){
00300 encoder<PursuingMsgPoseArray>(outMessage);
00301 }
00302 };
00303
00304 class PursuingMsgParams : public PursuingMsg{
00305 public:
00306
00307 double sensorLinMaxRange;
00308 double sensorFieldOfView;
00309 int sensorCount;
00310 double sensorResolution;
00311
00312 double robotRadius;
00313
00314 double x;
00315 double y;
00316 double theta;
00317
00318 PursuingMsgParams(int robotId_, double sensorLinMaxRange_,
00319 double sensorFieldOfView_,
00320 int sensorCount_,
00321 double sensorResolution_,
00322 double robotRadius_,
00323 double x_,
00324 double y_,
00325 double theta_)
00326 {
00327 robotId = robotId_;
00328 header = PUR_HEADER_PARAMS;
00329 sensorLinMaxRange = sensorLinMaxRange_;
00330 sensorFieldOfView = sensorFieldOfView_;
00331 sensorCount = sensorCount_;
00332 sensorResolution = sensorResolution_;
00333
00334 robotRadius = robotRadius_;
00335
00336 x = x_;
00337 y = y_;
00338 theta = theta_;
00339 }
00340
00342 PursuingMsgParams(const string& inMessage){
00343 constructor<PursuingMsgParams>(inMessage);
00344 }
00345
00348 void encode(string& outMessage){
00349 encoder<PursuingMsgParams>(outMessage);
00350 }
00351 };
00352
00353
00354 #endif
00355
00356