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 #include <ode/objects.h>
00042 #include "mathutils.h"
00043 #include "angularmotor.h"
00044
00045
00046 namespace lpzrobots {
00047
00048 AngularMotor::AngularMotor(const OdeHandle& odeHandle, Joint* joint){
00049 const Primitive* p1 = joint->getPart1();
00050 const Primitive* p2 = joint->getPart2();
00051 motor = dJointCreateAMotor(odeHandle.world, 0);
00052 dJointAttach(motor, p1->getBody(), p2->getBody());
00053 }
00054
00055
00056
00057
00058
00059
00060 int AngularMotor::set(const double* velocities, int len){
00061 int n = min(len, getNumberOfAxes());
00062 for(int i=0; i< n; i++){
00063 set(i, velocities[i]);
00064 }
00065 return n;
00066 }
00067
00068
00069
00070
00071
00072
00073 int AngularMotor::get(double* velocities, int len){
00074 int n = min(len, getNumberOfAxes());
00075 for(int i=0; i< n; i++){
00076 velocities[i] = get(i);
00077 }
00078 return n;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088 AngularMotor1Axis::AngularMotor1Axis(const OdeHandle& odeHandle, OneAxisJoint* joint, double power)
00089 : AngularMotor(odeHandle, joint), joint(joint) {
00090 dJointSetAMotorNumAxes(motor, 1);
00091 const Axis& a =joint->getAxis1();
00092 dJointSetAMotorAxis(motor, 0, 0, a.x(), a.y(), a.z() );
00093 dJointSetAMotorParam(motor, dParamFMax, power);
00094 dJointSetAMotorParam(motor, dParamVel, 0);
00095 }
00096
00097
00098
00099
00100
00101
00102 void AngularMotor1Axis::set(int axisNumber, double velocity){
00103 dJointSetAMotorParam(motor, dParamVel, velocity);
00104 }
00105
00106
00107
00108
00109 double AngularMotor1Axis::get(int axisNumber){
00110 return joint->getPosition1Rate();
00111 }
00112
00113
00114
00115 void AngularMotor1Axis::setPower(double power){
00116 dJointSetAMotorParam(motor, dParamFMax, power);
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126 AngularMotor2Axis::AngularMotor2Axis(const OdeHandle& odeHandle, TwoAxisJoint* joint,
00127 double power1, double power2)
00128 : AngularMotor(odeHandle, joint), joint(joint) {
00129
00130 dJointSetAMotorNumAxes(motor, 2);
00131 const Axis& a0 =joint->getAxis1();
00132 dJointSetAMotorAxis(motor, 0, 0, a0.x(), a0.y(), a0.z() );
00133 const Axis& a1 =joint->getAxis2();
00134 dJointSetAMotorAxis(motor, 1, 0, a1.x(), a1.y(), a1.z() );
00135
00136
00137 dJointSetAMotorParam(motor, dParamFMax, power1);
00138 dJointSetAMotorParam(motor, dParamFMax2, power2);
00139
00140 dJointSetAMotorParam(motor, dParamVel, 0);
00141 dJointSetAMotorParam(motor, dParamVel2, 0);
00142 }
00143
00144
00145
00146
00147
00148 void AngularMotor2Axis::set(int axisNumber, double velocity){
00149 int param;
00150 switch (axisNumber) {
00151 case 0:
00152 param = dParamVel;
00153 break;
00154 case 1:
00155 param = dParamVel2;
00156 break;
00157 }
00158 dJointSetAMotorParam(motor, param, velocity);
00159 }
00160
00161
00162 double AngularMotor2Axis::get(int axisNumber){
00163 switch (axisNumber) {
00164 case 0:
00165 return joint->getPosition1Rate();
00166 case 1:
00167 return joint->getPosition2Rate();
00168 default:
00169 return 0;
00170 }
00171 }
00172
00173
00174
00175 void AngularMotor2Axis::setPower(double power){
00176 dJointSetAMotorParam(motor, dParamFMax, power);
00177 dJointSetAMotorParam(motor, dParamFMax2, power);
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 AngularMotorNAxis::AngularMotorNAxis(const OdeHandle& odeHandle, Joint* joint,
00191 std::list<std::pair<double, Axis > > axis)
00192 : AngularMotor(odeHandle, joint), joint(joint) {
00193
00194 int len = axis.size();
00195
00196 dJointSetAMotorNumAxes(motor, len);
00197 int j=0;
00198 for(std::list<std::pair<double, Axis > >::iterator i = axis.begin();
00199 i!= axis.end(); i++, j++){
00200 const Axis& a = (*i).second;
00201 dJointSetAMotorAxis(motor, j, 0, a.x(), a.y(), a.z() );
00202 double pwr = (*i).first;
00203 int param;
00204 switch (j) {
00205 case 0:
00206 param = dParamFMax; break;
00207 case 1:
00208 param = dParamFMax2; break;
00209 case 2:
00210 param = dParamFMax3; break;
00211 default:
00212 continue;
00213 }
00214 dJointSetAMotorParam(motor, param, pwr);
00215
00216 switch (j) {
00217 case 0:
00218 param = dParamVel; break;
00219 case 1:
00220 param = dParamVel2; break;
00221 case 2:
00222 param = dParamVel3; break;
00223 default:
00224 continue;
00225 }
00226 dJointSetAMotorParam(motor, param, 0);
00227 }
00228 }
00229
00230
00231 int AngularMotorNAxis::getNumberOfAxes(){
00232 return dJointGetAMotorNumAxes(motor);
00233 }
00234
00235
00236
00237
00238
00239 void AngularMotorNAxis::set(int axisNumber, double velocity){
00240 int param;
00241 switch (axisNumber) {
00242 case 0:
00243 param = dParamVel;
00244 break;
00245 case 1:
00246 param = dParamVel2;
00247 break;
00248 case 2:
00249 param = dParamVel3;
00250 break;
00251 default:
00252 return;
00253 }
00254 dJointSetAMotorParam(motor, param, velocity);
00255 }
00256
00257
00258 double AngularMotorNAxis::get(int axisNumber){
00259 int param;
00260 switch (axisNumber) {
00261 case 0:
00262 param = dParamVel;
00263 break;
00264 case 1:
00265 param = dParamVel2;
00266 break;
00267 case 2:
00268 param = dParamVel3;
00269 break;
00270 }
00271 return dJointGetAMotorParam(motor, param);
00272 }
00273
00274
00275
00276 void AngularMotorNAxis::setPower(double power){
00277 int param;
00278 for(int i; i<getNumberOfAxes(); i++) {
00279 switch (i) {
00280 case 0:
00281 param = dParamFMax; break;
00282 case 1:
00283 param = dParamFMax2; break;
00284 case 2:
00285 param = dParamFMax3; break;
00286 default:
00287 continue;
00288 }
00289 dJointSetAMotorParam(motor, param, power);
00290 }
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 AngularMotor3AxisEuler::AngularMotor3AxisEuler(const OdeHandle& odeHandle, BallJoint* joint,
00304 const Axis& axis1, const Axis& axis3, double power)
00305 : AngularMotor(odeHandle, joint), joint(joint) {
00306
00307 dJointSetAMotorNumAxes(motor, 3);
00308 dJointSetAMotorMode (motor, dAMotorEuler);
00309
00310 dJointSetAMotorAxis(motor, 0, 1, axis1.x(), axis1.y(), axis1.z() );
00311 dJointSetAMotorAxis(motor, 2, 2, axis3.x(), axis3.y(), axis3.z() );
00312
00313
00314 dJointSetAMotorParam(motor, dParamFMax, power);
00315 dJointSetAMotorParam(motor, dParamFMax2, power);
00316 dJointSetAMotorParam(motor, dParamFMax3, power);
00317 }
00318
00319
00320
00321
00322
00323 void AngularMotor3AxisEuler::set(int axisNumber, double velocity){
00324 int param;
00325 switch (axisNumber) {
00326 case 0:
00327 param = dParamVel;
00328 break;
00329 case 1:
00330 param = dParamVel2;
00331 break;
00332 case 2:
00333 param = dParamVel3;
00334 break;
00335 default:
00336 return;
00337 }
00338 dJointSetAMotorParam(motor, param, velocity);
00339 }
00340
00341
00342 double AngularMotor3AxisEuler::get(int axisNumber){
00343 switch (axisNumber) {
00344 case 0:
00345 return dJointGetAMotorAngleRate(motor, 0);
00346 case 1:
00347 return dJointGetAMotorAngleRate(motor, 1);
00348 case 2:
00349 return dJointGetAMotorAngleRate(motor, 2);
00350 default:
00351 return 0;
00352 }
00353 }
00354
00355
00356
00357 void AngularMotor3AxisEuler::setPower(double power){
00358 dJointSetAMotorParam(motor, dParamFMax, power);
00359 dJointSetAMotorParam(motor, dParamFMax2, power);
00360 dJointSetAMotorParam(motor, dParamFMax3, power);
00361 }
00362
00363
00364 }
00365
00366