Robotsystem from Robot Group Leipzig: component2.h Source File

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

- File List
- File Members

# component2.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  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  *                                                                         *
    00022  *   $Log: component2.h,v $
    00023  *   Revision 1.1.2.1  2005/12/06 10:13:24  martius
    00024  *   openscenegraph integration started
    00025  *
    00026  *   Revision 1.7.4.1  2005/11/14 17:37:09  martius
    00027  *   moved to selforg
    00028  *
    00029  *   Revision 1.7  2005/11/14 12:48:32  martius
    00030  *   *** empty log message ***
    00031  *
    00032  *   Revision 1.6  2005/11/09 13:27:32  fhesse
    00033  *   GPL added
    00034  *                                                                *
    00035  ***************************************************************************/
    00036
    00037 /**
    00038  * component.h
    00039  *
    00040  * components are the building parts for robots
    00041  * components can be composed of zero or more sub components
    00042  * components can be bodies + geometry, sensors, ...
    00043  * components may expose wires
    00044  *
    00045  * the interface to control the robot is a set of wires.
    00046  */
    00047
    00048
    00049
    00050 #include <math.h>
    00051 #include <drawstuff/drawstuff.h>
    00052 #include <ode/ode.h>
    00053 #include <iostream>
    00054 #include <typeinfo>
    00055
    00056 #include <vector>
    00057 #include <list>
    00058
    00059 #include "exceptions.h"
    00060 #include "odehandle.h"
    00061 #include "oderobot.h"
    00062 #include <selforg/configurable.h>
    00063 #include <selforg/Position.h>
    00064
    00065 #ifndef __component_h
    00066 #define __component_h
    00067
    00068 namespace university_of_leipzig {
    00069 namespace robots {
    00070
    00071 class IWire;
    00072 class IComponent;
    00073 class AbstractMotorComponent;
    00074 class UniversalMotorComponent;
    00075 class MotorWire;
    00076
    00077 typedef struct {
    00078   double val;
    00079   std::string name;
    00080 } Wire;
    00081
    00082 typedef Position Angle;
    00083 typedef std::list< Angle >  AngleList;
    00084
    00085 typedef std::list<IComponent*> ComponentList;
    00086 typedef std::list<Wire*> WireList;
    00087
    00088
    00089 class OdeObject {
    00090 public:
    00091   dGeomID getGeom();
    00092   dBodyID getBody();
    00093
    00094   virtual bool collision_callback(OdeHandle *p_ode_handle,
    00095                                   dGeomID geom_id_0,
    00096                                   dGeomID geom_id_1) const = 0;
    00097 };
    00098
    00099 /**
    00100  * Component
    00101  *
    00102  * the building parts for robots
    00103  *
    00104  *
    00105  */
    00106   class IComponent : public Configurable : public OdeObject : public OSGNode
    00107 {
    00108 public:
    00109
    00110   virtual ComponentList getChilds() const = 0;
    00111   virtual WireList getWires() const = 0;
    00112
    00113 };
    00114
    00115
    00116 /**
    00117  * AbstractComponent
    00118  *
    00119  *
    00120  */
    00121 class AbstractComponent : public IComponent {
    00122  protected:
    00123   OdeHandle ode_handle;
    00124
    00125  public:
    00126   AbstractComponent(OdeHandle &r_ode_handle);
    00127   virtual ~AbstractComponent();
    00128
    00129   virtual unsigned   get_sub_component_count() const;
    00130   virtual IComponent &get_sub_component(unsigned index) const;
    00131
    00132   virtual unsigned   expose_wires(WireContainer &r_wire_set);
    00133
    00134   virtual const IComponent* does_contain_geom(const dGeomID geom_id,
    00135                                               bool b_recursive) const;
    00136
    00137
    00138   paramkey getName() const;
    00139   virtual paramlist getParamList() const;
    00140   virtual paramval  getParam(const paramkey& key) const;
    00141   virtual bool      setParam(const paramkey& key, paramval val);
    00142 };
    00143
    00144
    00145 /**
    00146  * AbstractCompoundComponent
    00147  *
    00148  *
    00149  */
    00150 class AbstractCompoundComponent : public AbstractComponent {
    00151  protected:
    00152   ComponentContainer component_container;
    00153
    00154  public:
    00155   AbstractCompoundComponent(OdeHandle &r_ode_handle);
    00156   virtual ~AbstractCompoundComponent();
    00157
    00158   virtual unsigned   get_sub_component_count() const;
    00159   virtual IComponent &get_sub_component(unsigned index) const;
    00160
    00161   virtual unsigned   expose_wires(WireContainer &r_wire_set);
    00162
    00163   virtual const IComponent* does_contain_geom(const dGeomID geom_id,
    00164                                               bool b_recursive) const;
    00165
    00166   virtual void draw() const;
    00167
    00168   virtual paramlist getParamList() const;
    00169   virtual paramval  getParam(const paramkey& key) const;
    00170   virtual bool      setParam(const paramkey& key, paramval val);
    00171 };
    00172
    00173
    00174
    00175 /**
    00176  * SimplePhysicalComponent
    00177  *
    00178  *
    00179  */
    00180 class SimplePhysicalComponent : public AbstractComponent {
    00181  protected:
    00182   dBodyID body_id;
    00183   dGeomID geom_id;
    00184
    00185  public:
    00186   SimplePhysicalComponent(OdeHandle &r_ode_handle,
    00187                           dBodyID _body_id = NULL,
    00188                           dGeomID _geom_id = NULL);
    00189
    00190
    00191   void    set_body_id(dBodyID _body_id);
    00192   dBodyID get_body_id() const;
    00193
    00194   virtual void    set_geom_id(dGeomID _geom_id);
    00195   virtual dGeomID get_geom_id() const;
    00196
    00197   /*
    00198   virtual unsigned expose_wires(WireContainer &out_r_wire_container);
    00199
    00200   virtual unsigned get_sub_component_count() const;
    00201   virtual IComponent &get_sub_component(unsigned index) const;
    00202   */
    00203
    00204   virtual const IComponent* does_contain_geom(const dGeomID _geom_id,
    00205                                               bool b_recursive) const;
    00206
    00207
    00208   virtual bool collision_callback(OdeHandle *p_ode_handle,
    00209                                   dGeomID geom_id_0, dGeomID geom_id_1) const;
    00210
    00211   virtual void draw() const;
    00212 };
    00213
    00214
    00215
    00216 /**
    00217  * AbstractMotorComponent
    00218  *
    00219  *
    00220  * a motor has output wires (new angular velocity)
    00221  * and input wire (current angular velocity)
    00222  */
    00223 class AbstractMotorComponent : public AbstractComponent {
    00224  protected:
    00225   dJointID joint_id; // the joint the motor is attached to
    00226
    00227  public:
    00228   AbstractMotorComponent(dJointID _joint_id);
    00229
    00230
    00231   virtual void    set_angular_velocity(dReal angular_velocity)       = 0;
    00232   virtual dReal get_angular_velocity()                         const = 0;
    00233
    00234   // a motor usually exposes 2 wires: one for controlling the angular velocity
    00235   // and one for retrieving the current velocity
    00236   // some motors may also return wires for setting/getting the maximum force
    00237   //virtual unsigned expose_wires(WireContainer &out_r_wire_container) const = 0;
    00238 };
    00239
    00240
    00241 class MotorWire : public IBidirectionalWire {
    00242   AbstractMotorComponent *p_motor;
    00243
    00244  public:
    00245   MotorWire(AbstractMotorComponent *_p_motor = NULL);
    00246
    00247   //UniversalMotorComponent *get_component() const;
    00248   IComponent &get_component() const;
    00249
    00250   dReal get()            const;
    00251   void  put(dReal value);
    00252 };
    00253
    00254
    00255 /**
    00256  * UniversalMotorComponent
    00257  *
    00258  *
    00259  * a motor wrapper.
    00260  *
    00261  * must be attached to one of the 2 axis of a universal joint
    00262  */
    00263 class UniversalMotorComponent : public AbstractMotorComponent {
    00264  protected:
    00265   char axis; // 0 for the one attached to body 0, 1 for the other one
    00266
    00267   MotorWire wire;
    00268
    00269   bool param_show_axis;
    00270
    00271  public:
    00272   UniversalMotorComponent(dJointID _joint_id, char _axis);
    00273
    00274   void  set_angular_velocity(dReal angular_velocity);
    00275   dReal get_angular_velocity() const;
    00276
    00277   unsigned expose_wires(WireContainer &out_r_wire_container);
    00278
    00279   void draw() const;
    00280
    00281   bool collision_callback(OdeHandle *p_ode_handle,
    00282                           dGeomID geom_id_0, dGeomID geom_id_1) const;
    00283   /*
    00284   const IComponent* does_contain_geom(const dGeomID geom_id,
    00285                                       bool b_recursive) const;
    00286   */
    00287   /*
    00288   unsigned get_sub_component_count() const;
    00289   IComponent &get_sub_component(unsigned index) const;
    00290   */
    00291
    00292   virtual paramlist getParamList() const;
    00293   virtual paramval  getParam(const paramkey& key) const;
    00294   virtual bool      setParam(const paramkey& key, paramval val);
    00295 };
    00296
    00297
    00298
    00299
    00300
    00301 class RobotArmDescription {
    00302  public:
    00303   OdeHandle *p_ode_handle;
    00304
    00305   dReal segment_radius;
    00306   dReal segment_mass;
    00307
    00308   Vector3<dReal> v3_position;
    00309   VertexList *p_vertex_list;
    00310 };
    00311
    00312
    00313
    00314 /**
    00315  * RobotArmComponent
    00316  *
    00317  *
    00318  * creates a robot arm, based on a RobotArmDescription
    00319  *
    00320  *
    00321  * sub components are the motors
    00322  *
    00323  *
    00324  * CCU = Capped Cyliner Universal (joint)
    00325  */
    00326 class CCURobotArmComponent : public AbstractCompoundComponent
    00327 {
    00328  protected:
    00329   dJointGroupID joint_group_id;
    00330
    00331  public:
    00332   CCURobotArmComponent(const RobotArmDescription &r_desc);
    00333   virtual ~CCURobotArmComponent();
    00334
    00335
    00336   // functions specific for this class
    00337   // (that means interface functions which go beyond the scope of IComponent)
    00338
    00339   /* not implemented yet
    00340   unsigned get_segment_count();
    00341   dBodyID  get_segment      (unsigned index);
    00342
    00343
    00344   unsigned get_joint_count  ();
    00345   dJointID get_joint_id     (unsigned index);
    00346   */
    00347   /*
    00348   unsigned get_sub_component_count() const;
    00349   IComponent &get_sub_component(unsigned index) const;
    00350   */
    00351
    00352   // returns "wires" to the motors
    00353   // the number of exposes wires equals the number of motors
    00354   // that is twice the (number of segments - 1)
    00355   // note that there are two motors between each 2 segments
    00356   // unsigned expose_wires(WireContainer &out_r_wire_container);
    00357   const IComponent* does_contain_geom(const dGeomID geom_id,
    00358                                       bool b_recursive) const;
    00359
    00360   void draw() const;
    00361   bool collision_callback(OdeHandle *p_ode_handle,
    00362                           dGeomID geom_id_0,
    00363                           dGeomID geom_id_1) const;
    00364
    00365   // some function that might come in the future:
    00366   // insert_segment, remove_segment
    00367   // so that the segmnets can be dynamically reconfigured
    00368 };
    00369
    00370
    00371
    00372
    00373 class PlaneComponentDescription {
    00374  public:
    00375   PlaneComponentDescription();
    00376
    00377   OdeHandle      *p_ode_handle;
    00378   Vector3<dReal> v3_normal;
    00379   dReal          d;
    00380 };
    00381
    00382 /*
    00383 class PlaneComponent : public SimplePhysicalComponent {
    00384  public:
    00385   PlaneComponent(const PlaneComponentDescription &r_desc);
    00386   virtual ~PlaneComponent();
    00387 };
    00388 */
    00389
    00390
    00391
    00392 class SpiderDescription {
    00393  public:
    00394   SpiderDescription();
    00395
    00396   OdeHandle *p_ode_handle;
    00397
    00398   Vertex position;
    00399   double sphere_mass;
    00400   double sphere_radius;
    00401
    00402   dReal segment_mass;
    00403   dReal segment_radius;
    00404   dReal segment_length;
    00405   dReal segment_count;
    00406
    00407   AngleList *p_angle_list;
    00408 };
    00409
    00410
    00411 class SpiderComponent : public AbstractCompoundComponent
    00412 {
    00413  protected:
    00414   dJointGroupID joint_group_id;
    00415
    00416  public:
    00417   SpiderComponent(const SpiderDescription &r_desc);
    00418
    00419   bool collision_callback(OdeHandle *p_ode_handle,
    00420                           dGeomID geom_id_0,
    00421                           dGeomID geom_id_1) const;
    00422
    00423 };
    00424
    00425
    00426
    00427 }
    00428 }
    00429
    00430
    00431 #endif