00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "stdafx.h"
00024 #include "FF3DGuidanceAgent.h"
00025 #include "define.h"
00026
00027
00028 #include "FF3DSphericalForceModel.h"
00029 #include "FF3DAttractivePointForceModel.h"
00030 #include "FF3DDiscForceModel.h"
00031 #include "FF3DLinearForceModel.h"
00032 #include "FF3DPlanarForceModel.h"
00033 #include "FF3DPicobHGForceModel.h"
00034 #include "FF3DPicobGForceModel.h"
00035
00036
00037
00038
00039
00040
00041
00042
00043 FF3DGuidanceAgent::FF3DGuidanceAgent()
00044 : Child( new FF3DGuidanceAgentCollider ), MicoleAgent("FF3DGuidanceAgent","Output"), _fm(NULL), _transform(new Transform())
00045 {
00046 ((FF3DGuidanceAgentCollider *)this->collider.get())->_parent = this;
00047
00048
00049 Display * dis = ReachinMicoleApplication::getInstance()->getDisplay();
00050
00051 _transform->children->add(this);
00052 dis->children->add( _transform );
00053
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 sendMessage("Set stiffness = 1.5;");
00082 sendMessage("Set d = 0.02;");
00083
00084
00085 bindMessage( "^OUT FF3D GUIDE : point=\\((.*), (.*), (.*)\\);$",
00086 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePointForceModel ));
00087 bindMessage( "^OUT FF3D GUIDE : sphere=\\((.*), (.*), (.*), (.*)\\);$",
00088 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleSphericalForceModel ));
00089 bindMessage( "^OUT FF3D GUIDE : line=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$",
00090 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleLinearForceModel ));
00091 bindMessage( "^OUT FF3D GUIDE : plan=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$",
00092 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePlanarForceModel ));
00093 bindMessage( "^OUT FF3D GUIDE : disc=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\),(.*)\\);$",
00094 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleDiscForceModel ));
00095 bindMessage( "^OUT FF3D GUIDE : none;$",
00096 BUS_CALLBACK_OF(FF3DGuidanceAgent, handleNoForceModel ));
00097 bindMessage( "^OUT FF3D GUIDE : picobhg=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$",
00098 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePicobHgForceModel ));
00099 bindMessage( "^OUT FF3D GUIDE : picobg=\\((.*), (.*), (.*)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$",
00100 BUS_CALLBACK_OF(FF3DGuidanceAgent, handlePicobGForceModel ));
00101 }
00102
00103 FF3DGuidanceAgent::~FF3DGuidanceAgent()
00104 {
00105 delete _fm;
00106
00107 }
00108
00109 void FF3DGuidanceAgent::handlePointForceModel ( MicoleBus *app, int argc, const char **argv )
00110 {
00111 if (argc < 3)
00112 return;
00113 Vec3f position;
00114 try
00115 {
00116 position.x = atof(argv[0]);
00117 position.y = atof(argv[1]);
00118 position.z = atof(argv[2]);
00119 }
00120 catch (...)
00121 {
00122 return;
00123 }
00124
00125 _transform->translation->set(Vec3f(0,0,0));
00126 _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00127
00128 setForceModel(new FF3DAttractivePointForceModel(position));
00129 }
00130
00131 void FF3DGuidanceAgent::handleLinearForceModel ( MicoleBus *app, int argc, const char **argv )
00132 {
00133 if (argc < 6)
00134 return;
00135 Vec3f pt1;
00136 Vec3f pt2;
00137 try
00138 {
00139 pt1.x = atof(argv[0]);
00140 pt1.y = atof(argv[1]);
00141 pt1.z = atof(argv[2]);
00142
00143
00144 pt2.x = atof(argv[3]);
00145 pt2.y = atof(argv[4]);
00146 pt2.z = atof(argv[5]);
00147 }
00148 catch (...)
00149 {
00150 return;
00151 }
00152
00153 setForceModel(new FF3DLinearForceModel(pt1,pt2));
00154
00155
00156 Vec3f vec_line = pt1 - pt2;
00157 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00158 _transform->translation->set( (pt1+pt2)/2 );
00159 }
00160
00161 void FF3DGuidanceAgent::handlePlanarForceModel ( MicoleBus *app, int argc, const char **argv )
00162 {
00163 if (argc < 6)
00164 return;
00165
00166 Vec3f pt1;
00167 Vec3f pt2;
00168 Vec3f pt3;
00169 try
00170 {
00171 pt1.x = atof(argv[0]);
00172 pt1.y = atof(argv[1]);
00173 pt1.z = atof(argv[2]);
00174 _transform->translation->set(pt1);
00175
00176 pt2.x = atof(argv[3]);
00177 pt2.y = atof(argv[4]);
00178 pt2.z = atof(argv[5]);
00179 }
00180 catch (...)
00181 {
00182 return;
00183 }
00184
00185
00186
00187
00188
00189 Vec3f vec_line = pt1 - pt2;
00190 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00191 _transform->translation->set( pt1 );
00192
00193 setForceModel(new FF3DPlanarForceModel(pt1,pt2));
00194 }
00195
00196 void FF3DGuidanceAgent::handleSphericalForceModel ( MicoleBus *app, int argc, const char **argv )
00197 {
00198 if (argc < 4)
00199 return;
00200
00201 Vec3f position;
00202 mgFloat range;
00203 try
00204 {
00205 position.x = atof(argv[0]);
00206 position.y = atof(argv[1]);
00207 position.z = atof(argv[2]);
00208 range = atof(argv[3]);
00209 }
00210 catch (...)
00211 {
00212 return;
00213 }
00214
00215 _transform->translation->set(position);
00216 _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00217
00218
00219 setForceModel( new FF3DSphericalForceModel(Vec3f(0,0,0),range) );
00220 }
00221
00222 void FF3DGuidanceAgent::handleDiscForceModel ( MicoleBus *app, int argc, const char **argv )
00223 {
00224 if (argc < 7)
00225 return;
00226
00227 Vec3f pt1;
00228 Vec3f pt2;
00229 Vec3f pt3;
00230 try
00231 {
00232 pt1.x = atof(argv[0]);
00233 pt1.y = atof(argv[1]);
00234 pt1.z = atof(argv[2]);
00235 _transform->translation->set(pt1);
00236
00237 pt2.x = atof(argv[3]);
00238 pt2.y = atof(argv[4]);
00239 pt2.z = atof(argv[5]);
00240 }
00241 catch (...)
00242 {
00243 return;
00244 }
00245
00246 mgFloat range = atof(argv[6]);
00247
00248 Vec3f vec_line = pt1 - pt2;
00249 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00250 _transform->translation->set( pt1 );
00251
00252 setForceModel(new FF3DDiscForceModel(pt1,pt2,range));
00253 }
00254
00255 void FF3DGuidanceAgent::handleNoForceModel ( MicoleBus *app, int argc, const char **argv )
00256 {
00257 setForceModel(NULL);
00258 }
00259
00260 void FF3DGuidanceAgent::handlePicobHgForceModel ( MicoleBus *app, int argc, const char **argv )
00261 {
00262 if (argc < 9)
00263 return;
00264
00265 Vec3f pt1;
00266 Vec3f pt2;
00267 try
00268 {
00269 pt1.x = atof(argv[0]);
00270 pt1.y = atof(argv[1]);
00271 pt1.z = atof(argv[2]);
00272
00273
00274 pt2.x = atof(argv[3]);
00275 pt2.y = atof(argv[4]);
00276 pt2.z = atof(argv[5]);
00277 }
00278 catch (...)
00279 {
00280 }
00281
00282
00283 Vec3f vec_line = pt1 - pt2;
00284 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00285 _transform->translation->set( (pt1+pt2)/2 );
00286
00287 vector<Vec3f> bumpList;
00288 Picob::readPicobList(argv[6], bumpList);
00289 setForceModel(new FF3DPicobHGForceModel(pt1, pt2, bumpList, atof(argv[7]), atof(argv[8])));
00290 }
00291
00292 void FF3DGuidanceAgent::handlePicobGForceModel ( MicoleBus *app, int argc, const char **argv )
00293 {
00294 if (argc < 6)
00295 return;
00296
00297 Vec3f pt;
00298 try {
00299 pt.x = atof(argv[0]);
00300 pt.y = atof(argv[1]);
00301 pt.z = atof(argv[2]);
00302 }
00303 catch (...)
00304 {
00305 }
00306
00307
00308 vector<Vec3f> bumpList;
00309 Picob::readPicobList(argv[3], bumpList);
00310 setForceModel(new FF3DPicobGForceModel(pt, bumpList, atof(argv[4]), atof(argv[5])));
00311
00312 _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00313 _transform->translation->set(Vec3f(0,0,0));
00314 }