Robotsystem of the Robot Group Leipzig: component.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Examples

- Search for |

- File List
- File Members

# 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
    00024
    00025 #include <math.h>
    00026 #include <ode/ode.h>
    00027 #include <typeinfo>
    00028
    00029 #include <vector>
    00030 #include <list>
    00031
    00032
    00033 #include "oderobot.h"
    00034 #include "joint.h"
    00035
    00036
    00037
    00038 #ifndef component_h
    00039 #define component_h
    00040
    00041
    00042 namespace lpzrobots
    00043 {
    00044     typedef struct
    00045     {
    00046         bool completesensormode; //if true, the controler of the Component also gets the sensor values of the robot of the component
    00047         bool completemotormode; //if true, the controler of the component also controls the robot of the component
    00048         double max_force;
    00049         double speed;
    00050     } ComponentConf;
    00051
    00052 /**
    00053  * Component
    00054  *
    00055  *
    00056  */
    00057 class Component : public OdeRobot
    00058 {
    00059  public:
    00060     ComponentConf conf;
    00061
    00062  public:
    00063
    00064     typedef struct
    00065     {
    00066         Component* subcomponent;
    00067         Joint* joint;
    00068         bool softlink; //if true the connection ends the recursion, false = normal
    00069         void *data;
    00070     } componentConnection;
    00071
    00072     std::vector <componentConnection> connection;
    00073     std::vector <Component*> backwardreference;
    00074
    00075 public:
    00076     Component* originComponent;
    00077     Component* directOriginComponent;
    00078
    00079  public:
    00080
    00081     Component ( const OdeHandle &odeHandle, const OsgHandle &osgHandle, const ComponentConf& conf);
    00082
    00083     ~Component ();
    00084
    00085 static ComponentConf getDefaultConf()
    00086 {
    00087     ComponentConf conf;
    00088     conf.completesensormode = true;
    00089     conf.completemotormode = false;
    00090     conf.max_force = 1;
    00091     conf.speed = 1;
    00092     return conf;
    00093 }
    00094
    00095  public:
    00096
    00097 virtual int     getSensorNumber (); //returns number of sensors; recursivly adding of the number of sensors all subcomponents and the robots of all Subcomponents.
    00098
    00099 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.
    00100
    00101 /**
    00102  *Use this, to get all sensor values of all the joints of all subcomponents, and the sensors of all robots, belonging to all subcompionents.
    00103  *The sensor values have the following sequence:
    00104  *values of the component connecting joints, values of the robot of the component,
    00105  *values of component connecting joints of the first subcomponent, values of the robot of the first subcomponent, ...
    00106  *@robot sensor values of the connecting joints of this component and all subcomponents
    00107  **/
    00108 virtual int     getSensors (sensor *sensors, int sensornumber); //returns actual sensorvalues; only for the connecting joints
    00109
    00110
    00111 /**
    00112  *Sets the motor values for the joints connecting the component with its subcomponents, an recursivly the joints of all subComponents.
    00113  *The motors of all robots of the subcomponents is not set.
    00114  *@param
    00115  **/
    00116 //virtual void  setMotors (const motor *motors, int motornumber); //sets actual motorcommands; only for the connecting joints
    00117 virtual void    setMotors (const motor *motors, int motornumber); //sets actual motorcommands; only for the connecting joints
    00118 /**
    00119  *This sets all motors in the component structure to zero, starting from this component.
    00120  **/
    00121 virtual void    resetMotorsRecursive ( );
    00122
    00123 //virtual int   getSensorNumber () = 0; //returns number of sensors; recursivly adding of the number of sensors all subcomponents and the robots of all Subcomponents.
    00124
    00125 //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.
    00126
    00127 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
    00128
    00129 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
    00130
    00131 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?
    00132
    00133 virtual void    doInternalStuff (const GlobalData &globalData);// this function is called in each timestep.; maybee usefull
    00134
    00135 // virtual void         setColor (const Color &col);    sets color of the robot; not nessecary
    00136
    00137 virtual Position getPosition () const = 0; //returns position of the object; relates to the robot or Primitive belonging to the component
    00138
    00139 //virtual Position getSpeed () const;//returns linear speed vector of the object; must be computed from all sub-robots
    00140
    00141 //virtual matrix::Matrix        getOrientation () const;//returns the orientation of the object;
    00142
    00143
    00144 /**
    00145  *This is only a simple function, calculating the coordinates of the point exactly between two directly connected components.
    00146  *@return Vector containing the Position
    00147  *@param index number of the position
    00148  **/
    00149 virtual osg::Vec3 getPositionbetweenComponents ( Component* component );
    00150
    00151 /**
    00152  *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.
    00153  **/
    00154 virtual Primitive* getMainPrimitive () const = 0;
    00155
    00156 /**
    00157  *Gets the Number of subcomponents of this component.
    00158  *@return Number of subcomponents
    00159  **/
    00160 virtual int getNumberSubcomponents ();
    00161
    00162
    00163 /**
    00164  *Gets the Number of all Subcomponents recursivly connected.
    00165  *@return Number of subcomponents
    00166  **/
    00167 virtual int getNumberSubcomponentsAll ();
    00168
    00169 /**
    00170  *This method adds an existing Component as a subcomponent to this component
    00171  *@param subcomponent to add
    00172  *@param reference to external created joint, which connects both components
    00173  **/
    00174 virtual void addSubcomponent ( Component* newsubcomponent , Joint* newconnectingjoint , bool softlink );
    00175
    00176 /**
    00177  *This method removes an existing Component as a subcomponent of this component. This also removes all Subcomponents of the subcomponent.
    00178  *@param subcomponent number to remove
    00179  *@return reference to the removed subcomponent, so that it could be used to do other things
    00180  **/
    00181 virtual Component* removeSubcomponent ( int removedsubcomponentnumber );
    00182
    00183 /**
    00184  *This method removes an existing Component as a subcomponent of this component. This also removes all Subcomponents of the subcomponent.
    00185  *@param subcomponent to remove
    00186  *@return reference to the removed subcomponent, so that it could be used to do other things
    00187  **/
    00188 virtual Component* removeSubcomponent ( Component* removedsubcomponent );
    00189
    00190 /**
    00191  *This removes all subcomponents of THIS component, and all their subcomponents, till the whole structure is destroyed.
    00192  **/
    00193 //virtual void removeAllSubcomponentsRecursive ();
    00194
    00195 /**
    00196  *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.
    00197  *@param the component wich is the top of the tree structure, could also be this component itself
    00198  **/
    00199  virtual void updateOriginsRecursive ( Component* parent );
    00200
    00201 /**
    00202  *This removes all softlinks of the structure that has THIS as his origin.
    00203  **/
    00204  virtual void removeSoftlinksRecursive ();
    00205
    00206 /**
    00207  *This method looks if a special component is a subcomponent of this component. Only direct subcomponents are registrated.
    00208  *Components which are only connected by softlink are a connection here as well.
    00209  *@param the component, which could be a subcomponent of this component
    00210  *@return true if it is a subcomponent, false if not
    00211  **/
    00212 virtual bool hasSubcomponent ( Component* subcomp );
    00213
    00214
    00215 /**
    00216  *This method looks if a special component is a subcomponent of this component and all its recursive subcomponents.
    00217  *Softlinks count as connected, but are not recursivly counted.
    00218  *@param the component, which could be a subcomponent
    00219  *@return true if it is a subcomponent, false if not
    00220  **/
    00221 //virtual bool hasSubcomponentAll ( Component* subcomp );
    00222
    00223 /**
    00224  *This method looks if a special component somehow connected to this component.
    00225  *@param the component, which could be connected
    00226  *@return true if it is connected, false if not
    00227  **/
    00228 virtual bool isComponentConnected ( Component* connectedComp );
    00229
    00230 /**
    00231  *This garants an direct access to the connections between the components. Be carefull with using the given references.
    00232  *@param the number of the connection
    00233  *@return the reference of connection element
    00234  **/
    00235 virtual componentConnection* getConnection ( int connectionnumber );
    00236
    00237 /**
    00238  *This returns the connection that connects to the target component.
    00239  *@param the reference to the component which is subcomponent in the searched connection
    00240  *@return the reference of connection element
    00241  **/
    00242 virtual componentConnection* getConnection ( Component* targetcomponent );
    00243
    00244 /**
    00245  *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.
    00246  *@param number of the subcomponent in the subcomponent list of the component
    00247  *@param true = connection becomes a softlink
    00248  **/
    00249 //virtual bool setSoftlink ( unsigned int position , bool state );
    00250
    00251 /**
    00252  *This divides the component structure, following this component into two seperate component structures
    00253  *@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
    00254  *@param maximum size of the whole Component structure of the first call of this function
    00255  *@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
    00256  *@return the best Componet for dividing at the moment the function is finished
    00257  */
    00258 virtual Component* getBestDivideComponent ( double targetrelation , int maxsize , Component* currentBestDivideComponent );
    00259
    00260 };
    00261
    00262
    00263 }
    00264 #endif