00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __ARM_H
00025 #define __ARM_H
00026
00027 #include <selforg/inspectable.h>
00028 #include <list>
00029 #include <vector>
00030 #include <cmath>
00031
00032 #include <string.h>
00033 #include <iostream>
00034
00035 #include <selforg/matrix.h>
00036 #include "oderobot.h"
00037
00038 #include "primitive.h"
00039 #include "oneaxisservo.h"
00040 #include "joint.h"
00041 #include "sensor.h"
00042
00043
00044 #include "osgprimitive.h"
00045
00046 using namespace matrix;
00047
00048 namespace lpzrobots{
00049
00050
00051 enum parts
00052 {
00053 base,
00054 shoulder1,
00055 shoulder2,
00056 upperArm,
00057 foreArm,
00058 hand
00059 };
00060
00061 typedef struct
00062 {
00063 double body_mass;
00064 double body_height;
00065 double body_width;
00066 double body_depth;
00067
00068 double shoulder_mass;
00069 double shoulder_radius;
00070 double joint_offset;
00071
00072 double upperarm_mass;
00073 double upperarm_radius;
00074 double upperarm_length;
00075
00076 double forearm_mass;
00077 double forearm_radius;
00078 double forearm_length;
00079
00080 double elevation_min;
00081 double elevation_max;
00082 double humeral_min;
00083 double humeral_max;
00084 double azimuthal_min;
00085 double azimuthal_max;
00086 double elbow_min;
00087 double elbow_max;
00088
00089 double motorPower;
00090 double damping;
00091 double servoFactor;
00092 double scaleMotorElbow;
00093
00094 bool withContext;
00095 bool useJointSensors;
00096
00097 std::list<Sensor*> sensors;
00098
00099 } ArmConf;
00100
00101 class Arm : public OdeRobot
00102 {
00103 public:
00104
00105 Arm(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const ArmConf& conf, const std::string& name);
00106
00107 static ArmConf getDefaultConf()
00108 {
00109 ArmConf conf;
00110
00111 conf.motorPower=5;
00112 conf.damping=0.2;
00113
00114 conf.upperarm_radius = 0.05;
00115 conf.forearm_radius = 0.05;
00116
00117
00118 conf.body_mass = 1.0;
00119 conf.body_height = 5.0;
00120 conf.body_width = 2.0;
00121 conf.body_depth = 0.5;
00122
00123 conf.shoulder_mass=0.005;
00124 conf.shoulder_radius=0.03;
00125 conf.joint_offset=0.005;
00126
00127 conf.upperarm_mass = 0.1;
00128 conf.upperarm_length = 1.5;
00129
00130 conf.forearm_mass = 0.1;
00131 conf.forearm_length = 1.2;
00132
00133 conf.elevation_min=-M_PI/3;
00134 conf.elevation_max=M_PI/3;
00135 conf.humeral_min=-M_PI/4;
00136 conf.humeral_max=M_PI/4;
00137 conf.azimuthal_min=-M_PI/4;
00138 conf.azimuthal_max=M_PI/3;
00139 conf.elbow_min=-M_PI/3.5;
00140 conf.elbow_max=M_PI/3.5;
00141 conf.servoFactor=1;
00142 conf.scaleMotorElbow=0.6;
00143 conf.useJointSensors=true;
00144 conf.withContext=false;
00145
00146 return conf;
00147 }
00148
00149 virtual ~Arm(){};
00150
00151 virtual paramkey getName() const {return "Arm";};
00152
00153
00154
00155
00156
00157 virtual void place(const osg::Matrix& pose);
00158
00159
00160
00161
00162 virtual void update();
00163
00164
00165
00166
00167
00168
00169
00170 virtual int getSensors(sensor* sensors, int sensornumber);
00171
00172
00173
00174
00175
00176
00177 virtual void setMotors(const motor* motors, int motornumber);
00178
00179
00180
00181
00182 virtual int getSensorNumber()
00183 {
00184 return sensorno;
00185 };
00186
00187
00188
00189
00190 virtual int getMotorNumber()
00191 {
00192 return motorno;
00193 };
00194
00195
00196
00197
00198
00199
00200 virtual int getSegmentsPosition(std::vector<Position> &poslist);
00201
00202
00203
00204
00205
00206 void getEndeffectorPosition(double* position);
00207
00208 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
00209
00210
00211
00212
00213
00214
00215 virtual void doInternalStuff(GlobalData& globalData);
00216
00217
00218
00219
00220 paramlist getParamList() const;
00221
00222 virtual paramval getParam(const paramkey& key) const;
00223
00224 virtual bool setParam(const paramkey& key, paramval val);
00225
00226 virtual Primitive* getMainObject() const{
00227 return objects[base];
00228 }
00229
00230
00231
00232
00233 virtual Primitive* getMainPrimitive() const
00234 {
00235 return objects[hand];
00236 }
00237
00238 void setDlearnTargetHack(double* post);
00239 void setDmotorTargetHack(double* post);
00240
00241 protected:
00242
00243
00244
00245
00246
00247
00248 virtual void create(const osg::Matrix& pose);
00249
00250
00251
00252
00253 virtual void destroy();
00254
00255 static void mycallback(void *data, dGeomID o1, dGeomID o2);
00256
00257 void hitTarget();
00258
00259 double dBodyGetPositionAll ( dBodyID basis , int para );
00260 double dGeomGetPositionAll ( dGeomID basis , int para );
00261
00262 void BodyCreate(int n, dMass m, dReal x, dReal y, dReal z, dReal qx, dReal qy, dReal qz, dReal qangle);
00263
00264
00265
00266
00267
00268
00269
00270
00271 ArmConf conf;
00272 matrix::Matrix endeff;
00273
00274 paramval factorSensors;
00275 paramval print;
00276
00277 std::vector <Primitive*> objects;
00278 std::vector <Joint*> joints;
00279 std::vector <HingeServo*> hingeServos;
00280
00281 int sensorno;
00282 int motorno;
00283
00284 bool created;
00285
00286 dSpaceID parentspace;
00287
00288 int printed;
00289
00290 };
00291 }
00292 #endif