FF3DDeviceOutputAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "stdafx.h"
00024 #include "FF3DDeviceOutputAgent.h"
00025 #include "define.h"
00026 
00027 
00028 #include "FF3DSphericalForceModel.h"
00029 #include "FF3DPointForceModel.h"
00030 #include "FF3DDiscForceModel.h"
00031 #include "FF3DLinearForceModel.h"
00032 #include "FF3DPlanarForceModel.h"
00033 #include "FF3DPicobHGForceModel.h"
00034 #include "FF3DPicobGForceModel.h"
00035 
00036 /*#include <Shape.h>
00037 #include <Sphere.h>
00038 #include <Cone.h>
00039 #include <Appearance.h>*/
00040 #include <FrictionalSurface.h>
00041 
00042 
00043 FF3DDeviceOutputAgent::FF3DDeviceOutputAgent()
00044 : Child( new FF3DDeviceOutputAgentCollider ), MicoleAgent("FF3DDeviceOutputAgent","Output"), _fm(NULL), _transform(new Transform())
00045 {
00046         static_cast<FF3DDeviceOutputAgentCollider *>(this->collider.get())->_parent = this;
00047 
00048         //add FF3DDeviceOutputAgent in scene
00049         Display * dis = static_cast<Display *>(ReachinMicoleApplication::getInstance()->getDisplay());
00050         
00051         
00052         _transform->children->add(this);
00053         dis->children->add( _transform );  
00054 
00056         /*
00057 #ifdef _DEBUG
00058         Shape * sh = new Shape;
00059         Cone * sph = new Cone;
00060 
00061         //FrictionalSurface * surf = new FrictionalSurface;
00062         sph->height->set(0.05);
00063         sph->bottom_radius->set(0.01);
00064 
00065         //surf->stiffness->set( 500 );
00066 
00067         Material * mat = new Material;
00068         mat->diffuse_color->set( RGB(0,1,0));
00069 
00070         Appearance * app = new Appearance;
00071         app->material->set(mat);
00072         //app->surface->set( surf );
00073 
00074         sh->appearance->set(app);
00075         sh->geometry->set(sph);
00076 
00077         _transform->children->add(sh);
00078 #endif
00079         */
00080         //en test
00081 
00082         bindMessage( "^OUT FF3D : point=\\((.*), (.*), (.*)\\);$", 
00083                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePointForceModel ));
00084         bindMessage( "^OUT FF3D : sphere=\\((.*), (.*), (.*), (.*)\\);$", 
00085                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleSphericalForceModel ));
00086         bindMessage( "^OUT FF3D : line=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$", 
00087                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleLinearForceModel ));
00088         bindMessage( "^OUT FF3D : plan=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$", 
00089                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePlanarForceModel ));
00090         bindMessage( "^OUT FF3D : disc=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\),(.*)\\);$", 
00091                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleDiscForceModel ));
00092         bindMessage( "^OUT FF3D : none;$", 
00093                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleNoForceModel ));
00094         bindMessage( "^OUT FF3D : picobhg=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$", 
00095                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePicobHgForceModel ));
00096         bindMessage( "^OUT FF3D : picobg=\\((.*), (.*), (.*)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$", 
00097                 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePicobGForceModel ));
00098         
00099         pb = new Playback();
00100         pb->SetPlaybackSpeed(100);
00101         pb->CreateControllersForOmni();
00102 
00103         // set the error threshold in mm
00104         pb->SetErrorThreshold(8);
00105         
00106         // avoid force wind up above 2N
00107         pb->SetIntegratorForceCap(2);
00108 
00109         // used in the Omni callback to set the initial state of the playback
00110         pb->LoadGestureFile("SavedTrajectory.txt");
00111         fopen_s(&log, "d3.txt", "a");
00112 }
00113 
00114 FF3DDeviceOutputAgent::~FF3DDeviceOutputAgent()
00115 {
00116         delete _fm;
00117         delete pb;
00118 //      delete _transform;
00119 }
00120 
00121 void FF3DDeviceOutputAgent::handlePointForceModel(MicoleBus *app, int argc, const char **argv)
00122 {
00123         if (argc < 3)
00124                 return;
00125         Vec3f position;
00126         try
00127         {
00128                 position.x = atof(argv[0]);
00129                 position.y = atof(argv[1]);
00130                 position.z = atof(argv[2]);
00131                 fprintf(log, "%f, %f, %f\n", position.x, position.y, position.z);
00132         }
00133         catch (...) //can append for truncated packet or bad transmission
00134         {
00135                 return;
00136         }
00137 
00138         _transform->translation->set(Vec3f(0,0,0));
00139         _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00140 
00141         setForceModel(new FF3DPointForceModel(pb, position));
00142 }
00143 
00144 void FF3DDeviceOutputAgent::handleLinearForceModel(MicoleBus *app, int argc, const char **argv)
00145 {
00146                 if (argc < 6)
00147                 return;
00148         Vec3f pt1;
00149         Vec3f pt2;
00150         try
00151         {
00152                 pt1.x = atof(argv[0]);
00153                 pt1.y = atof(argv[1]);
00154                 pt1.z = atof(argv[2]);
00155 
00156                 //_transform->translation->set(pt1);
00157                 pt2.x = atof(argv[3]);
00158                 pt2.y = atof(argv[4]);
00159                 pt2.z = atof(argv[5]);
00160         }
00161         catch (...) //can append for truncated packet or bad transmission
00162         {
00163                 return;
00164         }
00165 
00166         setForceModel(new FF3DLinearForceModel(pt1,pt2));
00167 
00168         //we compute the euclidian norma
00169         Vec3f vec_line = pt1 - pt2;
00170         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00171         _transform->translation->set( (pt1+pt2)/2 ); 
00172 }
00173 
00174 void FF3DDeviceOutputAgent::handlePlanarForceModel(MicoleBus *app, int argc, const char **argv)
00175 {
00176         if (argc < 6)
00177                 return;
00178 
00179         Vec3f pt1;
00180         Vec3f pt2;
00181         Vec3f pt3;
00182         try
00183         {
00184                 pt1.x = atof(argv[0]);
00185                 pt1.y = atof(argv[1]);
00186                 pt1.z = atof(argv[2]);
00187                 _transform->translation->set(pt1);
00188 
00189                 pt2.x = atof(argv[3]);
00190                 pt2.y = atof(argv[4]);
00191                 pt2.z = atof(argv[5]);
00192         }
00193         catch (...) //can append for truncated packet or bad transmission
00194         { 
00195                 return;
00196         }
00197 
00198         /*pt3.x = atof(argv[6]);
00199         pt3.y = atof(argv[7]);
00200         pt3.z = atof(argv[8]);*/
00201 
00202         Vec3f vec_line = pt1 - pt2;
00203         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00204         _transform->translation->set( pt1 ); 
00205 
00206         setForceModel(new FF3DPlanarForceModel(pt1,pt2));
00207 }
00208 
00209 void FF3DDeviceOutputAgent::handleSphericalForceModel(MicoleBus *app, int argc, const char **argv)
00210 {
00211         if (argc < 4)
00212                 return;
00213 
00214         Vec3f position;
00215         mgFloat range;
00216         try
00217         {
00218                 position.x = atof(argv[0]);
00219                 position.y = atof(argv[1]);
00220                 position.z = atof(argv[2]);
00221                 range = atof(argv[3]);
00222         }
00223         catch (...) //can append for truncated packet or bad transmission
00224         {
00225                 return;
00226         }
00227 
00228         _transform->translation->set(position);
00229         _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00230 
00231         //setForceModel(new FF3DPointForceModel(position));
00232         setForceModel( new FF3DSphericalForceModel(Vec3f(0,0,0),range) );
00233 }
00234 
00235 void FF3DDeviceOutputAgent::handleDiscForceModel(MicoleBus *app, int argc, const char **argv)
00236 {
00237         if (argc < 7)
00238                 return;
00239 
00240         Vec3f pt1;
00241         Vec3f pt2;
00242         Vec3f pt3;
00243         try
00244         {
00245                 pt1.x = atof(argv[0]);
00246                 pt1.y = atof(argv[1]);
00247                 pt1.z = atof(argv[2]);
00248                 _transform->translation->set(pt1);
00249 
00250                 pt2.x = atof(argv[3]);
00251                 pt2.y = atof(argv[4]);
00252                 pt2.z = atof(argv[5]);
00253         }
00254         catch (...) //can append for truncated packet or bad transmission
00255         {
00256                 return;
00257         }
00258 
00259         mgFloat range = atof(argv[6]);
00260         
00261         Vec3f vec_line = pt1 - pt2;
00262         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00263         _transform->translation->set( pt1 ); 
00264 
00265         setForceModel(new FF3DDiscForceModel(pt1,pt2,range));
00266 }
00267 
00268 void FF3DDeviceOutputAgent::handleNoForceModel(MicoleBus *app, int argc, const char **argv)
00269 {
00270         setForceModel(NULL);
00271 }
00272 
00273 void FF3DDeviceOutputAgent::handlePicobHgForceModel(MicoleBus *app, int argc, const char **argv)
00274 {
00275         if (argc < 9)
00276                 return;
00277 
00278         Vec3f pt1;
00279         Vec3f pt2;
00280         try
00281         {
00282                 pt1.x = atof(argv[0]);
00283                 pt1.y = atof(argv[1]);
00284                 pt1.z = atof(argv[2]);
00285 
00286                 //_transform->translation->set(pt1);
00287                 pt2.x = atof(argv[3]);
00288                 pt2.y = atof(argv[4]);
00289                 pt2.z = atof(argv[5]);
00290         }
00291         catch (...)
00292         { //can happen with truncated packet or bad transmission
00293         }
00294 
00295         //we compute the euclidian norma
00296         Vec3f vec_line = pt1 - pt2;
00297         _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00298         _transform->translation->set( (pt1+pt2)/2 ); 
00299         
00300         vector<Vec3f> bumpList;
00301         Picob::readPicobList(argv[6], bumpList);
00302         setForceModel(new FF3DPicobHGForceModel(pt1, pt2, bumpList, atof(argv[7]), atof(argv[8])));
00303 }
00304 
00305 void FF3DDeviceOutputAgent::handlePicobGForceModel(MicoleBus *app, int argc, const char **argv)
00306 {
00307         if (argc < 6)
00308                 return;
00309 
00310         Vec3f pt;
00311         try
00312         {
00313                 pt.x = atof(argv[0]);
00314                 pt.y = atof(argv[1]);
00315                 pt.z = atof(argv[2]);
00316         }
00317         catch (...)
00318         { //can happen with truncated packet or bad transmission
00319         }
00320 
00321         vector<Vec3f> bumpList;
00322         Picob::readPicobList(argv[3], bumpList);
00323         setForceModel(new FF3DPicobGForceModel(pt, bumpList, atof(argv[4]), atof(argv[5])));
00324 
00325         _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00326         _transform->translation->set(Vec3f(0,0,0));
00327 }

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7