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 "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
00101
00102
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
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
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
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
00199
00200
00201
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
00218
00219
00220
00221
00222
00223 class AbstractMotorComponent : public AbstractComponent {
00224 protected:
00225 dJointID joint_id;
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
00235
00236
00237
00238 };
00239
00240
00241 class MotorWire : public IBidirectionalWire {
00242 AbstractMotorComponent *p_motor;
00243
00244 public:
00245 MotorWire(AbstractMotorComponent *_p_motor = NULL);
00246
00247
00248 IComponent &get_component() const;
00249
00250 dReal get() const;
00251 void put(dReal value);
00252 };
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 class UniversalMotorComponent : public AbstractMotorComponent {
00264 protected:
00265 char axis;
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
00285
00286
00287
00288
00289
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
00316
00317
00318
00319
00320
00321
00322
00323
00324
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
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
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
00366
00367
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
00384
00385
00386
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