atomcomponent.h

Go to the documentation of this file.
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.11 2006/11/30 08:51:39 robot8 00025 * -update of the evolution projekt 00026 * -fitness changed 00027 * -replication changed 00028 * -added copy function 00029 * 00030 * Revision 1.10 2006/09/12 09:29:45 robot8 00031 * -working simulation is possible, but no fitness calculation and no selection at the moment 00032 * 00033 * Revision 1.9 2006/09/11 12:01:31 martius 00034 * *** empty log message *** 00035 * 00036 * * 00037 ***************************************************************************/ 00038 00039 00040 #include "component.h" 00041 #include <osgprimitive.h> 00042 00043 #include <selforg/abstractcontroller.h> 00044 00045 00046 #ifndef atomcomponent_h 00047 #define atomcomponent_h 00048 00049 00050 00051 namespace lpzrobots 00052 { 00053 00054 typedef struct 00055 { 00056 lpzrobots::Component* startComponent; 00057 lpzrobots::Component* endComponent; 00058 lpzrobots::SliderJoint* slider; 00059 double startingdistance; 00060 int bindingcounter; 00061 } repSlider; 00062 00063 00064 typedef struct 00065 { 00066 double core_radius; 00067 double shell_radius; 00068 double mass; 00069 int max_bindings; //maximum possible number of fused atoms on this atom 00070 double binding_energy; //the value of kinetic energy that is necessary, to fuse two AtomComponents 00071 double min_fission_energy; //this is the minimum value of fission that has to be reached 00072 00073 bool leadingatom;//this value sais, that a atomcomponent is the first component a component structure, that is controlled by a robot controller; 00074 //it only is important for the origin of an component structure 00075 00076 bool fusionDisabled; //this value can disable or enable the ability of an atom to fuse with another one 00077 00078 std::vector <repSlider>* replicationSliderHandle; //this handle tells the atom, where to sve the slider-joints temporary used while replication 00079 00080 } AtomConf; 00081 00082 typedef struct 00083 { 00084 Component* original; 00085 Component* copy; 00086 } TableLine; 00087 00088 00089 /** 00090 * AtomComponent 00091 * 00092 * 00093 */ 00094 class AtomComponent : public Component 00095 { 00096 00097 00098 public: 00099 AtomConf atomconf; 00100 00101 00102 00103 public: 00104 00105 class connectionAddition 00106 { 00107 public: 00108 double binding_strength; 00109 double fitness; 00110 00111 connectionAddition () 00112 { 00113 binding_strength = 0; 00114 fitness = 0; 00115 } 00116 00117 ~connectionAddition () 00118 { 00119 } 00120 }; 00121 00122 00123 00124 private: 00125 //only one of this two should reference to an object 00126 OSGSphere* core; 00127 Primitive* shell; 00128 00129 00130 public: 00131 00132 AtomComponent ( const OdeHandle &odeHandle, const OsgHandle &osgHandle, const ComponentConf& conf, const AtomConf& aconf ); 00133 00134 ~AtomComponent (); 00135 00136 00137 static AtomConf getDefaultAtomConf() 00138 { 00139 AtomConf conf; 00140 00141 conf.core_radius = 0.05; 00142 conf.shell_radius = 0.1; 00143 conf.mass = 1; 00144 conf.max_bindings = 4; 00145 conf.binding_energy = 3; 00146 conf.min_fission_energy = 0; 00147 conf.leadingatom = false; 00148 conf.fusionDisabled = false; 00149 conf.replicationSliderHandle = NULL; 00150 00151 return conf; 00152 } 00153 00154 virtual void deleteStructureRecursive (); 00155 00156 /** 00157 *Use this, to get all sensor values of all the joints of all subcomponents, and the sensors of all robots, belonging to all subcomponents. 00158 *The sensor values have the following sequence: 00159 *values of the component connecting joints, values of the robot of the component, 00160 *values of component connecting joints of the first subcomponent, values of the robot of the first subcomponent, ... 00161 *@param robot sensor values of the connecting joints of this component and all subcomponents 00162 **/ 00163 virtual int getSensors (sensor *sensors, int sensornumber); //returns actual sensorvalues; only for the connecting joints 00164 00165 /** 00166 *Sets the motor values for the joints connecting the component with its subcomponents, an recursivly the joints of all subComponents. 00167 *@param 00168 **/ 00169 virtual void setMotors (const motor *motors, int motornumber); //sets actual motorcommands; only for the connecting joints 00170 00171 virtual int getSensorNumber (); //returns number of sensors; recursivly adding of the number of sensors all subcomponents and the robots of all Subcomponents. 00172 00173 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. 00174 00175 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 00176 00177 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 00178 virtual void place (const osg::Matrix &pose);//sets the pose of the vehicle; also recursive place of all subComponents; does nothing at the moment 00179 00180 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? 00181 00182 virtual bool shellCollision ( dGeomID o1 , dGeomID o2 ); //testing function for collisions with the atom shell 00183 00184 virtual void doInternalStuff (const GlobalData &globalData);// this function is called in each timestep.; maybee usefull 00185 00186 // virtual void setColor (const Color &col); sets color of the robot; not nessecary 00187 00188 virtual Position getPosition () const; //returns position of the object; relates to the robot or Primitive belonging to the component 00189 00190 //virtual Position getSpeed () const;//returns linear speed vector of the object; must be computed from all sub-robots 00191 00192 /** 00193 *This is only a simple function, calculating the coordinates of the point exactly between two directly connected components. 00194 *@return Vector containing the Position 00195 *@param index number of the position 00196 **/ 00197 virtual osg::Vec3 getPositionbetweenComponents ( Component* component ); 00198 00199 /** 00200 *@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. 00201 **/ 00202 virtual Primitive* getMainPrimitive () const; 00203 00204 /** 00205 *Searches for the softlink in the substructure of THIS component which has the highest binding strength. 00206 *@return the softlink connection within the substructure of THIS component. 00207 **/ 00208 virtual componentConnection* getStrongestSoftlinkofStructure (); 00209 00210 /** 00211 *This changes the structure of all components connected with this component, so that this component will become the new root of this structure. 00212 **/ 00213 virtual void makeComponentStructureRoot(); 00214 00215 00216 /** 00217 *Calculates the linear force the Component has at the time of calling this function 00218 *@return force (mass*linear velocity) 00219 **/ 00220 virtual double getMotionForce (); 00221 00222 /** 00223 *Calculates the linear force between two components at the moment of calling this function. 00224 *@return force (masses*linear velocity of both atoms) 00225 **/ 00226 virtual double getCollisionForce ( AtomComponent* collAtom ); 00227 00228 /** 00229 *Tests if the conditions for fusion of two atoms are fulfilled. 00230 *@param Geom reference to the first atom 00231 *@param Geom reference to the second atom 00232 *@return true if fulfilled false if not 00233 **/ 00234 virtual bool fusionCondition ( dGeomID o1 , dGeomID o2 ); 00235 00236 /** 00237 *Tests if the conditions for fission of two atoms are fulfilled. 00238 *@param Geom reference to the first atom 00239 *@param Geom reference to the second atom 00240 *@return true if fulfilled false if not 00241 **/ 00242 virtual bool fissionCondition ( dGeomID o1 , dGeomID o2 , double force ); 00243 00244 /** 00245 *Test which collisions should not be handled. 00246 *@param Geom reference to the first atom 00247 *@param Geom reference to the second atom 00248 *@return true if fulfilled false if not 00249 **/ 00250 virtual bool collisionExclusionCondition ( dGeomID o1 , dGeomID o2 ); 00251 00252 /** 00253 *fuses this AtomComponent with an other one 00254 *@param the AtomComponent, to fuse with 00255 *@retuen true if the fusion was successfull, false if not 00256 **/ 00257 virtual bool fusion ( AtomComponent* atom_to_fuse ); 00258 00259 /**Sets all teh fusionDisable parameters of the structure belonging to THIS atom to true, so that no fusion will occur. 00260 * 00261 **/ 00262 virtual void disableStructureFusionRecursive (); 00263 00264 /**Sets all teh fusionDisable parameters of the structure belonging to THIS atom to false, so that fusion will occur. 00265 * 00266 **/ 00267 virtual void enableStructureFusionRecursive (); 00268 00269 /** 00270 *fissions a AtomComponent from this AtomComponent 00271 *@param the AtomComponent, to fission 00272 *@retuen true if the fission was successfull, false if not 00273 **/ 00274 virtual bool fission ( double force ); 00275 00276 virtual void fissionOf ( componentConnection* tmpconnection ); 00277 00278 virtual AtomComponent* getLeastFittestDivideComponent ( int minsize , AtomComponent* currentBestDivideComponent ); 00279 00280 00281 virtual AtomComponent* getCopyOutofTable ( std::vector<TableLine> &table ); 00282 00283 virtual AtomComponent* copyBaseStructure ( osg::Vec3 deltaposition , std::vector<TableLine> &copytable ); 00284 00285 virtual AtomComponent* copySoftlinkStructure ( std::vector<TableLine> &copytable ); 00286 00287 virtual AtomComponent* copyCompleteStructure ( osg::Vec3 deltaposition , AtomComponent* copystartcomponent); 00288 00289 /** 00290 *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. 00291 *@param the AtomComponent which belongs to the structure to replicate with, and which is the point where the replication will happen 00292 *@return true if replication was successfull, else false 00293 **/ 00294 virtual bool replication ( AtomComponent* atom_to_recplicate ); 00295 00296 virtual bool replication_old ( AtomComponent* atom_to_recplicate ); 00297 00298 virtual void setConnectionFitness ( unsigned int number , double value ); 00299 00300 virtual void setConnectionFitnessAll ( double value ); 00301 00302 virtual double getConnectionFitness ( unsigned int number ); 00303 00304 virtual double getConnectionFitness ( AtomComponent* searchedsubcomponent ); 00305 00306 virtual double getStructureFitness (); 00307 00308 virtual void updateConnectionFitnessAll ( AbstractController* controller ); 00309 00310 }; 00311 00312 00313 00314 } 00315 #endif

Generated on Tue Jan 16 02:14:34 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8