component.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: component.h,v $ 00024 * Revision 1.13 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.12 2006/10/20 13:52:33 robot8 00031 * -update of the evolution projekt 00032 * -only changed some parameter 00033 * 00034 * Revision 1.11 2006/09/11 12:01:31 martius 00035 * *** empty log message *** 00036 * 00037 * * 00038 ***************************************************************************/ 00039 00040 #ifndef _component_h 00041 #define _component_h 00042 00043 #include <typeinfo> 00044 #include <vector> 00045 #include <list> 00046 00047 #include <ode/ode.h> 00048 #include <math.h> 00049 00050 #include "oderobot.h" 00051 #include "joint.h" 00052 00053 namespace lpzrobots 00054 { 00055 typedef struct _ComponentConf 00056 { 00057 bool completesensormode; //if true, the controler of the Component also gets the sensor values of the robot of the component 00058 bool completemotormode; //if true, the controler of the component also controls the robot of the component 00059 double max_force; 00060 double speed; 00061 } ComponentConf; 00062 00063 /** 00064 * This is the abstract base class of the component system. A component includes the routines for managing sensor and motor values from a controller. 00065 * With a bunch of components it is possible to create a tree like structure. There is always a root structure. 00066 * Components could be used as normal robot objects, so they can get motor and sensor values. These values are shared with all components in the tree structure of a component. 00067 * Between the differnt objects of the component class could exist connections, which are physical represented by Ode-Joints. 00068 * The components use the motor values they get, to control the joints between them. 00069 * From these joints sensor values are read out, which where send with the getSensor () function like a normal robot does. 00070 * But the arrray of sensor values comes from all components within the structure beneth the component, from which the function was called. 00071 * You could say that each component is a non physical shell around a physical object like a primitive or a robot in classical meaning of this project. 00072 * These shells build a connection between the physical parts and control these connections, which could be also physical existend. 00073 */ 00074 class Component : public OdeRobot 00075 { 00076 public: 00077 ComponentConf conf; 00078 00079 public: 00080 00081 /** 00082 *This is the structure of one connection between two components. 00083 **/ 00084 typedef struct 00085 { 00086 Component* subcomponent; 00087 Joint* joint; 00088 bool softlink; //if true the connection ends the recursion, false = normal 00089 void *data; 00090 } componentConnection; 00091 00092 std::vector <componentConnection> connection; 00093 std::vector <Component*> backwardreference; 00094 00095 public: 00096 Component* originComponent; 00097 Component* directOriginComponent; 00098 00099 public: 00100 00101 Component ( const OdeHandle &odeHandle, const OsgHandle &osgHandle, const ComponentConf& conf); 00102 00103 ~Component (); 00104 00105 static ComponentConf getDefaultConf() 00106 { 00107 ComponentConf conf; 00108 conf.completesensormode = true; 00109 conf.completemotormode = false; 00110 conf.max_force = 1; 00111 conf.speed = 1; 00112 return conf; 00113 } 00114 00115 public: 00116 00117 /** 00118 *Returns number of sensors; recursivly adding of the number of sensors all subcomponents and the robots of all Subcomponents. 00119 *@return number of sensors of the component and all its subcomponents 00120 **/ 00121 virtual int getSensorNumber (); 00122 00123 /** 00124 *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. 00125 *@return number of motors of the component and all its subcomponents 00126 **/ 00127 virtual int getMotorNumber (); 00128 00129 /** 00130 *Use this, to get all sensor values of all the joints of all subcomponents, and the sensors of all robots, belonging to all subcompionents. 00131 *The sensor values have the following sequence: 00132 *values of the component connecting joints, values of the robot of the component, 00133 *values of component connecting joints of the first subcomponent, values of the robot of the first subcomponent, ... 00134 *@robot sensor values of the connecting joints of this component and all subcomponents 00135 **/ 00136 virtual int getSensors (sensor *sensors, int sensornumber); //returns actual sensorvalues; only for the connecting joints 00137 00138 00139 /** 00140 *Sets the motor values for the joints connecting the component with its subcomponents, an recursivly the joints of all subComponents. 00141 *The motors of all robots of the subcomponents is not set. 00142 *@param 00143 **/ 00144 virtual void setMotors (const motor *motors, int motornumber); //sets actual motorcommands; only for the connecting joints 00145 00146 /** 00147 *This sets all motors in the component structure to zero, starting from this component. 00148 **/ 00149 virtual void resetMotorsRecursive ( ); 00150 00151 //virtual int getSensorNumber () = 0; //returns number of sensors; recursivly adding of the number of sensors all subcomponents and the robots of all Subcomponents. 00152 00153 //virtual int getMotorNumber () = 0; //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. 00154 00155 virtual void update () = 0;//update the OSG notes here; update of the underlying robot or Primitive and recursive update of all Components in the Connection-vector 00156 00157 virtual void place (const Pos &pos) = 0;//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 00158 00159 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? 00160 00161 virtual void doInternalStuff (const GlobalData &globalData);// this function is called in each timestep.; maybee usefull 00162 00163 // virtual void setColor (const Color &col); sets color of the robot; not nessecary 00164 00165 virtual Position getPosition () const = 0; //returns position of the object; relates to the robot or Primitive belonging to the component 00166 00167 /** 00168 *Gets the distance between two components. 00169 *@return distance in space 00170 **/ 00171 virtual double getDistanceToComponent ( Component* comp ); 00172 00173 //virtual Position getSpeed () const;//returns linear speed vector of the object; must be computed from all sub-robots 00174 00175 //virtual matrix::Matrix getOrientation () const;//returns the orientation of the object; 00176 00177 00178 /** 00179 *This is only a simple function, calculating the coordinates of the point exactly between two directly connected components. 00180 *@return Vector containing the Position 00181 *@param index number of the position 00182 **/ 00183 virtual osg::Vec3 getPositionbetweenComponents ( Component* component ); 00184 00185 /** 00186 *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. 00187 **/ 00188 virtual Primitive* getMainPrimitive () const = 0; 00189 00190 /** 00191 *Gets the Number of subcomponents of this component. 00192 *@return Number of subcomponents 00193 **/ 00194 virtual int getNumberSubcomponents (); 00195 00196 00197 /** 00198 *Gets the Number of all Subcomponents recursivly connected. 00199 *@return Number of subcomponents 00200 **/ 00201 virtual int getNumberSubcomponentsAll (); 00202 00203 /** 00204 *This method adds an existing Component as a subcomponent to this component 00205 *@param subcomponent to add 00206 *@param reference to external created joint, which connects both components 00207 *@param true if connection should be a softlink, false else 00208 **/ 00209 virtual void addSubcomponent ( Component* newsubcomponent , Joint* newconnectingjoint , bool softlink ); 00210 00211 /** 00212 *This method removes an existing Component as a subcomponent of this component. This also removes all Subcomponents of the subcomponent. 00213 *@param subcomponent number to remove 00214 *@return reference to the removed subcomponent, so that it could be used to do other things 00215 **/ 00216 virtual Component* removeSubcomponent ( int removedsubcomponentnumber ); 00217 00218 /** 00219 *This method removes an existing Component as a subcomponent of this component. This also removes all Subcomponents of the subcomponent. 00220 *@param subcomponent to remove 00221 *@return reference to the removed subcomponent, so that it could be used to do other things 00222 **/ 00223 virtual Component* removeSubcomponent ( Component* removedsubcomponent ); 00224 00225 /** 00226 *This removes all subcomponents of THIS component, and all their subcomponents, till the whole structure is destroyed. 00227 **/ 00228 virtual void removeAllSubcomponentsRecursive (); 00229 00230 /** 00231 *This updates the origin references within the component tree. If this is a removed subcomponent for examble, then parent should be this itself, so it is the top of the tree. 00232 *@param the component wich is the top of the tree structure, could also be this component itself 00233 **/ 00234 virtual void updateOriginsRecursive ( Component* parent ); 00235 00236 /** 00237 *This removes all softlinks of the structure that has THIS as his origin. 00238 **/ 00239 virtual void removeSoftlinksRecursive (); 00240 00241 00242 00243 /** 00244 *This method looks if a special component is a subcomponent of this component. Only direct subcomponents are registrated. 00245 *Components which are only connected by softlink are a connection here as well. 00246 *@param the component, which could be a subcomponent of this component 00247 *@return true if it is a subcomponent, false if not 00248 **/ 00249 virtual bool hasSubcomponent ( Component* subcomp ); 00250 00251 00252 /** 00253 *This method looks if a special component is a subcomponent of this component and all its recursive subcomponents. 00254 *Softlinks count as connected, but are not recursivly counted. 00255 *@param the component, which could be a subcomponent 00256 *@return true if it is a subcomponent, false if not 00257 **/ 00258 //virtual bool hasSubcomponentAll ( Component* subcomp ); 00259 00260 00261 /** 00262 *This method looks if a special component somehow connected to this component. 00263 *@param the component, which could be connected 00264 *@return true if it is connected, false if not 00265 **/ 00266 virtual bool isComponentConnected ( Component* connectedComp ); 00267 00268 /** 00269 *This garants an direct access to the connections between the components. Be carefull with using the given references. 00270 *@param the number of the connection 00271 *@return the reference of connection element 00272 **/ 00273 virtual componentConnection* getConnection ( unsigned int connectionnumber ); 00274 00275 /** 00276 *This returns the connection that connects to the target component. 00277 *@param the reference to the component which is subcomponent in the searched connection 00278 *@return the reference of connection element 00279 **/ 00280 virtual componentConnection* getConnection ( Component* targetcomponent ); 00281 00282 /** 00283 *Sets the connection between the component and one of its subcomponents to be a softlink. That means that the recusion for this branch stops here. 00284 *@param number of the subcomponent in the subcomponent list of the component 00285 *@param true = connection becomes a softlink 00286 **/ 00287 virtual bool setSoftlink ( unsigned int position , bool state ); 00288 00289 /** 00290 *This divides the component structure, following this component into two seperate component structures 00291 *@param the relation between the two new component structures, if it is 1/2 the structures would have the same number of components or only have a difference by one if the whole structures has an odd number of components 00292 *@param maximum size of the whole Component structure of the first call of this function 00293 *@param the best component for dividing at the moment of calling this function; it should be NULL for the first call of the function, so that no best component is set up till now 00294 *@return the best Componet for dividing at the moment the function is finished 00295 */ 00296 virtual Component* getBestDivideComponent ( double targetrelation , int maxsize , Component* currentBestDivideComponent ); 00297 00298 00299 00300 }; 00301 00302 00303 } 00304 #endif

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