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  *                                                                         *
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: component.h,v $
00023  *   Revision 1.7.4.2  2005/12/06 10:13:23  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 "vector.h"
00060 #include "exceptions.h"
00061 #include "cubic_spline.h"
00062 
00063 #include "odehandle.h"
00064 #include <selforg/configurable.h>
00065 #include "oderobot.h"
00066 
00067 
00068 #ifdef dDOUBLE
00069 #define dsDrawBox dsDrawBoxD
00070 #define dsDrawSphere dsDrawSphereD
00071 #define dsDrawCylinder dsDrawCylinderD
00072 #define dsDrawCappedCylinder dsDrawCappedCylinderD
00073 #endif
00074 
00075 
00076 #ifndef component_h
00077 #define component_h
00078 
00079 
00080 namespace lpzrobots {
00081 
00082 
00083 class IWire;
00084 class IComponent;
00085 class AbstractMotorComponent;
00086 class UniversalMotorComponent;
00087 class MotorWire;
00088 
00089 
00090 typedef std::list<IComponent*> ComponentContainer;
00091 typedef Vector3<dReal>              Vertex;
00092 typedef std::list< Vertex > VertexList;
00093 
00094 
00095 typedef Vector3<dReal>      Angle;
00096 typedef std::list< Angle >  AngleList;
00097 
00098 typedef std::list<IWire*> WireContainer;
00099 //typedef std::vector<dJointID> joint_id_list;
00100 
00101 
00102 
00103 
00104 
00105 
00106 /**
00107  * Wire
00108  *
00109  *
00110  * a wire is always attached to a component
00111  */
00112 class IWire {
00113  public:
00114   virtual IComponent& get_component() const = 0;
00115 };
00116 
00117 
00118 
00119 class IInputWire : virtual public IWire {
00120  public:
00121   virtual void put(dReal value) = 0;
00122 };
00123 
00124 
00125 class IOutputWire : virtual public IWire {
00126  public:
00127   virtual dReal get() const = 0;
00128 };
00129 
00130 class IBidirectionalWire : virtual public IInputWire,
00131                            virtual public IOutputWire {
00132  public:
00133   // no new members required
00134 };
00135 
00136 
00137 
00138 
00139 /**
00140  * Component
00141  *
00142  * the building parts for robots
00143  *
00144  *
00145  */
00146 class IComponent : public Configurable
00147 {
00148  public:
00149   virtual unsigned get_sub_component_count() const = 0;
00150 
00151   virtual IComponent &get_sub_component(unsigned index) const = 0;
00152 
00153   virtual unsigned expose_wires(WireContainer &r_wire_set) = 0;
00154   
00155   virtual void draw() const = 0;
00156 
00157   virtual const IComponent* does_contain_geom(const dGeomID geom_id,
00158                                               bool b_recursive) const = 0;
00159 
00160   virtual bool collision_callback(OdeHandle *p_ode_handle, 
00161                                   dGeomID geom_id_0, 
00162                                   dGeomID geom_id_1) const = 0;
00163 };
00164 
00165  
00166 /**
00167  * AbstractComponent
00168  *
00169  *
00170  */
00171 class AbstractComponent : public IComponent {
00172  protected:
00173   OdeHandle ode_handle;
00174   
00175  public:
00176   AbstractComponent(OdeHandle &r_ode_handle);
00177   virtual ~AbstractComponent();
00178 
00179   virtual unsigned   get_sub_component_count() const;
00180   virtual IComponent &get_sub_component(unsigned index) const;
00181   
00182   virtual unsigned   expose_wires(WireContainer &r_wire_set);
00183 
00184   virtual const IComponent* does_contain_geom(const dGeomID geom_id,
00185                                               bool b_recursive) const;
00186 
00187 
00188   paramkey getName() const;
00189   virtual paramlist getParamList() const;
00190   virtual paramval  getParam(const paramkey& key) const;
00191   virtual bool      setParam(const paramkey& key, paramval val);
00192 };
00193  
00194 
00195 /**
00196  * AbstractCompoundComponent
00197  *
00198  *
00199  */
00200 class AbstractCompoundComponent : public AbstractComponent {
00201  protected:
00202   ComponentContainer component_container;
00203   
00204  public:
00205   AbstractCompoundComponent(OdeHandle &r_ode_handle);
00206   virtual ~AbstractCompoundComponent();
00207 
00208   virtual unsigned   get_sub_component_count() const;
00209   virtual IComponent &get_sub_component(unsigned index) const;
00210    
00211   virtual unsigned   expose_wires(WireContainer &r_wire_set);
00212 
00213   virtual const IComponent* does_contain_geom(const dGeomID geom_id,
00214                                               bool b_recursive) const;
00215 
00216   virtual void draw() const;
00217 
00218   virtual paramlist getParamList() const;
00219   virtual paramval  getParam(const paramkey& key) const;
00220   virtual bool      setParam(const paramkey& key, paramval val);
00221 };
00222  
00223 
00224 
00225 /**
00226  * SimplePhysicalComponent
00227  *
00228  *
00229  */
00230 class SimplePhysicalComponent : public AbstractComponent {
00231  protected:
00232   dBodyID body_id;
00233   dGeomID geom_id;
00234 
00235  public:
00236   SimplePhysicalComponent(OdeHandle &r_ode_handle,
00237                           dBodyID _body_id = NULL,
00238                           dGeomID _geom_id = NULL);
00239 
00240 
00241   void    set_body_id(dBodyID _body_id);
00242   dBodyID get_body_id() const;
00243 
00244   virtual void    set_geom_id(dGeomID _geom_id);
00245   virtual dGeomID get_geom_id() const;
00246 
00247   /*
00248   virtual unsigned expose_wires(WireContainer &out_r_wire_container);
00249 
00250   virtual unsigned get_sub_component_count() const;
00251   virtual IComponent &get_sub_component(unsigned index) const;
00252   */
00253   
00254   virtual const IComponent* does_contain_geom(const dGeomID _geom_id, 
00255                                               bool b_recursive) const;
00256   
00257  
00258   virtual bool collision_callback(OdeHandle *p_ode_handle, 
00259                                   dGeomID geom_id_0, dGeomID geom_id_1) const;
00260 
00261   virtual void draw() const;
00262 };
00263 
00264 
00265 
00266 /**
00267  * AbstractMotorComponent
00268  *
00269  *
00270  * a motor has output wires (new angular velocity)
00271  * and input wire (current angular velocity)
00272  */
00273 class AbstractMotorComponent : public AbstractComponent {
00274  protected:
00275   dJointID joint_id; // the joint the motor is attached to
00276 
00277  public:
00278   AbstractMotorComponent(dJointID _joint_id);
00279 
00280 
00281   virtual void    set_angular_velocity(dReal angular_velocity)       = 0;
00282   virtual dReal get_angular_velocity()                         const = 0;
00283 
00284   // a motor usually exposes 2 wires: one for controlling the angular velocity
00285   // and one for retrieving the current velocity
00286   // some motors may also return wires for setting/getting the maximum force
00287   //virtual unsigned expose_wires(WireContainer &out_r_wire_container) const = 0;
00288 };
00289 
00290 
00291 class MotorWire : public IBidirectionalWire {
00292   AbstractMotorComponent *p_motor;
00293 
00294  public:
00295   MotorWire(AbstractMotorComponent *_p_motor = NULL);
00296 
00297   //UniversalMotorComponent *get_component() const;
00298   IComponent &get_component() const;
00299 
00300   dReal get()            const;
00301   void  put(dReal value);
00302 };
00303 
00304 
00305 /**
00306  * UniversalMotorComponent
00307  *
00308  *
00309  * a motor wrapper.
00310  *
00311  * must be attached to one of the 2 axis of a universal joint
00312  */
00313 class UniversalMotorComponent : public AbstractMotorComponent {
00314  protected:
00315   char axis; // 0 for the one attached to body 0, 1 for the other one
00316 
00317   MotorWire wire;
00318 
00319   bool param_show_axis;
00320 
00321  public:
00322   UniversalMotorComponent(dJointID _joint_id, char _axis);
00323 
00324   void  set_angular_velocity(dReal angular_velocity);
00325   dReal get_angular_velocity() const;
00326 
00327   unsigned expose_wires(WireContainer &out_r_wire_container);
00328 
00329   void draw() const;
00330 
00331   bool collision_callback(OdeHandle *p_ode_handle, 
00332                           dGeomID geom_id_0, dGeomID geom_id_1) const;
00333   /*
00334   const IComponent* does_contain_geom(const dGeomID geom_id, 
00335                                       bool b_recursive) const;
00336   */
00337   /*
00338   unsigned get_sub_component_count() const;
00339   IComponent &get_sub_component(unsigned index) const;
00340   */
00341 
00342   virtual paramlist getParamList() const;
00343   virtual paramval  getParam(const paramkey& key) const;
00344   virtual bool      setParam(const paramkey& key, paramval val);
00345 };
00346 
00347 
00348 
00349 
00350 
00351 class RobotArmDescription {
00352  public:
00353   OdeHandle *p_ode_handle;
00354 
00355   dReal segment_radius;
00356   dReal segment_mass;
00357 
00358   Vector3<dReal> v3_position;
00359   VertexList *p_vertex_list;
00360 };
00361 
00362 
00363 
00364 /**
00365  * RobotArmComponent
00366  *
00367  *
00368  * creates a robot arm, based on a RobotArmDescription
00369  *
00370  *
00371  * sub components are the motors
00372  *
00373  *
00374  * CCU = Capped Cyliner Universal (joint)
00375  */
00376 class CCURobotArmComponent : public AbstractCompoundComponent
00377 {
00378  protected:
00379   dJointGroupID joint_group_id;
00380 
00381  public:
00382   CCURobotArmComponent(const RobotArmDescription &r_desc);
00383   virtual ~CCURobotArmComponent();
00384 
00385 
00386   // functions specific for this class
00387   // (that means interface functions which go beyond the scope of IComponent)
00388 
00389   /* not implemented yet 
00390   unsigned get_segment_count();
00391   dBodyID  get_segment      (unsigned index);
00392 
00393 
00394   unsigned get_joint_count  ();
00395   dJointID get_joint_id     (unsigned index);
00396   */
00397   /*
00398   unsigned get_sub_component_count() const;
00399   IComponent &get_sub_component(unsigned index) const;
00400   */
00401 
00402   // returns "wires" to the motors
00403   // the number of exposes wires equals the number of motors
00404   // that is twice the (number of segments - 1)
00405   // note that there are two motors between each 2 segments
00406   // unsigned expose_wires(WireContainer &out_r_wire_container);
00407   const IComponent* does_contain_geom(const dGeomID geom_id, 
00408                                       bool b_recursive) const;
00409 
00410   void draw() const;
00411   bool collision_callback(OdeHandle *p_ode_handle, 
00412                           dGeomID geom_id_0, 
00413                           dGeomID geom_id_1) const;
00414 
00415   // some function that might come in the future:
00416   // insert_segment, remove_segment
00417   // so that the segmnets can be dynamically reconfigured
00418 };
00419 
00420 
00421 
00422 
00423 class PlaneComponentDescription {
00424  public:
00425   PlaneComponentDescription();
00426 
00427   OdeHandle      *p_ode_handle;
00428   Vector3<dReal> v3_normal;
00429   dReal          d;
00430 };
00431 
00432 /*
00433 class PlaneComponent : public SimplePhysicalComponent {
00434  public:
00435   PlaneComponent(const PlaneComponentDescription &r_desc);
00436   virtual ~PlaneComponent();
00437 };
00438 */
00439 
00440 
00441 
00442 class SpiderDescription {
00443  public:
00444   SpiderDescription();
00445 
00446   OdeHandle *p_ode_handle;
00447 
00448   Vertex position;
00449   double sphere_mass;
00450   double sphere_radius;
00451 
00452   dReal segment_mass;
00453   dReal segment_radius;
00454   dReal segment_length;
00455   dReal segment_count;
00456 
00457   AngleList *p_angle_list;
00458 };
00459 
00460 
00461 class SpiderComponent : public AbstractCompoundComponent
00462 {
00463  protected:
00464   dJointGroupID joint_group_id;
00465 
00466  public:
00467   SpiderComponent(const SpiderDescription &r_desc);
00468 
00469   bool collision_callback(OdeHandle *p_ode_handle, 
00470                           dGeomID geom_id_0, 
00471                           dGeomID geom_id_1) const;
00472 
00473 };
00474 
00475 
00476 
00477 }
00478 
00479 
00480 #endif

Generated on Tue Apr 4 19:05:03 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5