00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * marcel@informatik.uni-leipzig.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 * * 00023 * $Log: atomcomponent.h,v $ 00024 * Revision 1.14 2008/05/07 16:45:51 martius 00025 * code cosmetics and documentation 00026 * 00027 * Revision 1.13 2008/05/06 17:14:17 martius 00028 * buildsystem further tuned, 00029 * help in Makefile 00030 * osg/data directory is also installed and registered at osg_robots 00031 * 00032 * Revision 1.12 2007/11/07 13:21:15 martius 00033 * doInternal stuff changed signature 00034 * 00035 * Revision 1.11 2006/11/30 08:51:39 robot8 00036 * -update of the evolution projekt 00037 * -fitness changed 00038 * -replication changed 00039 * -added copy function 00040 * 00041 * Revision 1.10 2006/09/12 09:29:45 robot8 00042 * -working simulation is possible, but no fitness calculation and no selection at the moment 00043 * 00044 * Revision 1.9 2006/09/11 12:01:31 martius 00045 * *** empty log message *** 00046 * 00047 * * 00048 ***************************************************************************/ 00049 00050 #ifndef atomcomponent_h 00051 #define atomcomponent_h 00052 00053 #include <ode_robots/component.h> 00054 #include <ode_robots/osgprimitive.h> 00055 00056 #include <selforg/abstractcontroller.h> 00057 00058 00059 00060 namespace lpzrobots 00061 { 00062 00063 typedef struct 00064 { 00065 lpzrobots::Component* startComponent; 00066 lpzrobots::Component* endComponent; 00067 lpzrobots::SliderJoint* slider; 00068 double startingdistance; 00069 int bindingcounter; 00070 } repSlider; 00071 00072 00073 typedef struct 00074 { 00075 double core_radius; 00076 double shell_radius; 00077 double mass; 00078 int max_bindings; //maximum possible number of fused atoms on this atom 00079 double binding_energy; //the value of kinetic energy that is necessary, to fuse two AtomComponents 00080 double min_fission_energy; //this is the minimum value of fission that has to be reached 00081 00082 bool leadingatom;//this value sais, that a atomcomponent is the first component a component structure, that is controlled by a robot controller; 00083 //it only is important for the origin of an component structure 00084 00085 bool fusionDisabled; //this value can disable or enable the ability of an atom to fuse with another one 00086 00087 std::vector <repSlider>* replicationSliderHandle; //this handle tells the atom, where to sve the slider-joints temporary used while replication 00088 00089 } AtomConf; 00090 00091 typedef struct 00092 { 00093 Component* original; 00094 Component* copy; 00095 } TableLine; 00096 00097 00098 /** 00099 * AtomComponent 00100 * 00101 * 00102 */ 00103 class AtomComponent : public Component 00104 { 00105 00106 00107 public: 00108 AtomConf atomconf; 00109 00110 00111 00112 public: 00113 00114 class connectionAddition 00115 { 00116 public: 00117 double binding_strength; 00118 double fitness; 00119 00120 connectionAddition () 00121 { 00122 binding_strength = 0; 00123 fitness = 0; 00124 } 00125 00126 ~connectionAddition () 00127 { 00128 } 00129 }; 00130 00131 00132 00133 private: 00134 //only one of this two should reference to an object 00135 OSGSphere* core; 00136 Primitive* shell; 00137 00138 00139 public: 00140 00141 AtomComponent ( const OdeHandle &odeHandle, const OsgHandle &osgHandle, const ComponentConf& conf, const AtomConf& aconf ); 00142 00143 ~AtomComponent (); 00144 00145 00146 static AtomConf getDefaultAtomConf() 00147 { 00148 AtomConf conf; 00149 00150 conf.core_radius = 0.05; 00151 conf.shell_radius = 0.1; 00152 conf.mass = 1; 00153 conf.max_bindings = 4; 00154 conf.binding_energy = 3; 00155 conf.min_fission_energy = 0; 00156 conf.leadingatom = false; 00157 conf.fusionDisabled = false; 00158 conf.replicationSliderHandle = NULL; 00159 00160 return conf; 00161 } 00162 00163 virtual void deleteStructureRecursive (); 00164 00165 /** 00166 Use this, to get all sensor values of all the joints of all subcomponents, and the sensors of all robots, belonging to all subcomponents. 00167 The sensor values have the following sequence: 00168 values of the component connecting joints, values of the robot of the component, 00169 values of component connecting joints of the first subcomponent, values of the robot of the first subcomponent, ... 00170 @param robot sensor values of the connecting joints of this component and all subcomponents 00171 **/ 00172 virtual int getSensors (sensor *sensors, int sensornumber); //returns actual sensorvalues; only for the connecting joints 00173 00174 /** 00175 *Sets the motor values for the joints connecting the component with its subcomponents, an recursivly the joints of all subComponents. 00176 *@param 00177 **/ 00178 virtual void setMotors (const motor *motors, int motornumber); //sets actual motorcommands; only for the connecting joints 00179 00180 virtual int getSensorNumber (); //returns number of sensors; recursivly adding of the number of sensors all subcomponents and the robots of all Subcomponents. 00181 00182 virtual int getMotorNumber (); //returns number of motors; recursivly adding of the number of sensors all subcomponents; at the moment only counts Hinge-, Slider-, Hinge2 and Universal-Joints; The Motor-Numbers of the robots of the Components is not counted. 00183 00184 virtual void update ();//update the OSG notes here; update of the underlying robot or Primitive and recursive update of all Components in the Connection-vector 00185 00186 virtual void place (const Pos &pos);//sets the vehicle to position pos - desired position of the robot; the first component is seen as center of the robot, on which the position pos refers; also recursive place of all subComponents 00187 virtual void place (const osg::Matrix &pose);//sets the pose of the vehicle; also recursive place of all subComponents; does nothing at the moment 00188 00189 virtual bool collisionCallback (void *data, dGeomID o1, dGeomID o2);// checks for internal collisions and treats them.; should do nothing, because there should not be any ode-objects belonging to the component, which are not handled elsewhere....and what is with Primitives? are they automaticaly handled? 00190 00191 virtual bool shellCollision ( dGeomID o1 , dGeomID o2 ); //testing function for collisions with the atom shell 00192 00193 virtual void doInternalStuff (GlobalData &globalData);// this function is called in each timestep.; maybee usefull 00194 00195 // virtual void setColor (const Color &col); sets color of the robot; not nessecary 00196 00197 virtual Position getPosition () const; //returns position of the object; relates to the robot or Primitive belonging to the component 00198 00199 //virtual Position getSpeed () const;//returns linear speed vector of the object; must be computed from all sub-robots 00200 00201 /** 00202 *This is only a simple function, calculating the coordinates of the point exactly between two directly connected components. 00203 *@return Vector containing the Position 00204 *@param index number of the position 00205 **/ 00206 virtual osg::Vec3 getPositionbetweenComponents ( Component* component ); 00207 00208 /** 00209 *@return reference to the simple Primitive, or to the main Primitive of the robot assigend to the component. If nothimng is assigned, NULL is returned. 00210 **/ 00211 virtual Primitive* getMainPrimitive () const; 00212 00213 /** 00214 *Searches for the softlink in the substructure of THIS component which has the highest binding strength. 00215 *@return the softlink connection within the substructure of THIS component. 00216 **/ 00217 virtual componentConnection* getStrongestSoftlinkofStructure (); 00218 00219 /** 00220 *This changes the structure of all components connected with this component, so that this component will become the new root of this structure. 00221 **/ 00222 virtual void makeComponentStructureRoot(); 00223 00224 00225 /** 00226 *Calculates the linear force the Component has at the time of calling this function 00227 *@return force (mass*linear velocity) 00228 **/ 00229 virtual double getMotionForce (); 00230 00231 /** 00232 *Calculates the linear force between two components at the moment of calling this function. 00233 *@return force (masses*linear velocity of both atoms) 00234 **/ 00235 virtual double getCollisionForce ( AtomComponent* collAtom ); 00236 00237 /** 00238 *Tests if the conditions for fusion of two atoms are fulfilled. 00239 *@param Geom reference to the first atom 00240 *@param Geom reference to the second atom 00241 *@return true if fulfilled false if not 00242 **/ 00243 virtual bool fusionCondition ( dGeomID o1 , dGeomID o2 ); 00244 00245 /** 00246 *Tests if the conditions for fission of two atoms are fulfilled. 00247 *@param Geom reference to the first atom 00248 *@param Geom reference to the second atom 00249 *@return true if fulfilled false if not 00250 **/ 00251 virtual bool fissionCondition ( dGeomID o1 , dGeomID o2 , double force ); 00252 00253 /** 00254 *Test which collisions should not be handled. 00255 *@param Geom reference to the first atom 00256 *@param Geom reference to the second atom 00257 *@return true if fulfilled false if not 00258 **/ 00259 virtual bool collisionExclusionCondition ( dGeomID o1 , dGeomID o2 ); 00260 00261 /** 00262 *fuses this AtomComponent with an other one 00263 *@param the AtomComponent, to fuse with 00264 *@retuen true if the fusion was successfull, false if not 00265 **/ 00266 virtual bool fusion ( AtomComponent* atom_to_fuse ); 00267 00268 /**Sets all teh fusionDisable parameters of the structure belonging to THIS atom to true, so that no fusion will occur. 00269 * 00270 **/ 00271 virtual void disableStructureFusionRecursive (); 00272 00273 /**Sets all teh fusionDisable parameters of the structure belonging to THIS atom to false, so that fusion will occur. 00274 * 00275 **/ 00276 virtual void enableStructureFusionRecursive (); 00277 00278 /** 00279 *fissions a AtomComponent from this AtomComponent 00280 *@param the AtomComponent, to fission 00281 *@retuen true if the fission was successfull, false if not 00282 **/ 00283 virtual bool fission ( double force ); 00284 00285 virtual void fissionOf ( componentConnection* tmpconnection ); 00286 00287 virtual AtomComponent* getLeastFittestDivideComponent ( int minsize , AtomComponent* currentBestDivideComponent ); 00288 00289 00290 virtual AtomComponent* getCopyOutofTable ( std::vector<TableLine> &table ); 00291 00292 virtual AtomComponent* copyBaseStructure ( osg::Vec3 deltaposition , std::vector<TableLine> ©table ); 00293 00294 virtual AtomComponent* copySoftlinkStructure ( std::vector<TableLine> ©table ); 00295 00296 virtual AtomComponent* copyCompleteStructure ( osg::Vec3 deltaposition , AtomComponent* copystartcomponent); 00297 00298 /** 00299 *This is a special fusion of two AtomComponents. They have to belong to two robots, so that touching each ofer causes a crossing over in her structure. 00300 *@param the AtomComponent which belongs to the structure to replicate with, and which is the point where the replication will happen 00301 *@return true if replication was successfull, else false 00302 **/ 00303 virtual bool replication ( AtomComponent* atom_to_recplicate ); 00304 00305 virtual bool replication_old ( AtomComponent* atom_to_recplicate ); 00306 00307 virtual void setConnectionFitness ( unsigned int number , double value ); 00308 00309 virtual void setConnectionFitnessAll ( double value ); 00310 00311 virtual double getConnectionFitness ( unsigned int number ); 00312 00313 virtual double getConnectionFitness ( AtomComponent* searchedsubcomponent ); 00314 00315 virtual double getStructureFitness (); 00316 00317 virtual void updateConnectionFitnessAll ( AbstractController* controller ); 00318 00319 }; 00320 00321 00322 00323 } 00324 #endif