00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
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
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
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
00134 };
00135
00136
00137
00138
00139
00140
00141
00142
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
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
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
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
00249
00250
00251
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
00268
00269
00270
00271
00272
00273 class AbstractMotorComponent : public AbstractComponent {
00274 protected:
00275 dJointID joint_id;
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
00285
00286
00287
00288 };
00289
00290
00291 class MotorWire : public IBidirectionalWire {
00292 AbstractMotorComponent *p_motor;
00293
00294 public:
00295 MotorWire(AbstractMotorComponent *_p_motor = NULL);
00296
00297
00298 IComponent &get_component() const;
00299
00300 dReal get() const;
00301 void put(dReal value);
00302 };
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 class UniversalMotorComponent : public AbstractMotorComponent {
00314 protected:
00315 char axis;
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
00335
00336
00337
00338
00339
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
00366
00367
00368
00369
00370
00371
00372
00373
00374
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
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
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
00416
00417
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
00434
00435
00436
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