00001
00002
00003
00004
00005
00006
00007 #ifndef BHKINEMATIC_H
00008 #define BHKINEMATIC_H
00009
00010 #include <math.h>
00011 #include <iostream>
00012 #include "rccl.h"
00013
00016 #define NUM_FINGERS 3
00017
00020 #define JOINTS_PER_FINGER 2
00021
00030 namespace BHandKin{
00031
00034 enum FINGER{
00035 F1 = 1,
00036 F2 = 2,
00037 F3 = 3
00038 };
00039 }
00043 struct FingerTransforms{
00044 TRSF_PTR Pos[NUM_FINGERS];
00045 };
00046
00049 struct FingerJoints{
00050 double Joint[JOINTS_PER_FINGER];
00051 };
00052
00057 struct BHandJoints{
00058 FingerJoints F[NUM_FINGERS];
00059 FingerJoints Spread;
00060 bool TorqueSwitch[NUM_FINGERS];
00061 double TSActivationPoint[NUM_FINGERS];
00062 };
00063
00064
00067 static const char* BHKinematicException_info[] = {
00068 "Angle value to big",
00069 "Angle value to small (< 0)",
00070 "Position value to big.",
00071 "Position value to small (< 0).",
00072 "Angle out of Range",
00073 "Position out of Range",
00074 "UNDEF"};
00075
00076
00082 class BHKinematicException
00083 {
00084 public:
00085
00088 enum error
00089 {
00090 EXCP_ANGLE_TO_BIG,
00091 EXCP_ANGLE_TO_SMALL,
00092 EXCP_POSITION_TO_BIG,
00093 EXCP_POSITION_TO_SMALL,
00094 EXCP_ANGLE_OUT_OF_RANGE,
00095 EXCP_POSITION_OUT_OF_RANGE,
00096 EXCP_UNDEF
00097 };
00098
00099
00102 BHKinematicException(const error e);
00103 BHKinematicException(){};
00104
00105
00108 const void show();
00109
00112 friend std::ostream& operator<<(std::ostream& os,const BHKinematicException& e);
00113
00116 bool operator==(error e);
00117
00119 error Err;
00120
00121 protected:
00122 std::string Msg;
00123 };
00124
00125
00126
00127
00128 inline BHKinematicException::BHKinematicException(const error e)
00129 {
00130 Msg = BHKinematicException_info[e];
00131 Err = e;
00132 }
00133
00134
00135
00136
00137 inline const void BHKinematicException::show ()
00138 {
00139 std::cout << Msg << std::endl;
00140 }
00141
00142
00143
00144
00145
00146 inline std::ostream& operator<<(std::ostream& os,const BHKinematicException& e)
00147 {
00148 os << e.Msg << std::endl;
00149 return os;
00150 }
00151
00152
00153
00154
00155
00156 inline bool BHKinematicException:: operator==(error e)
00157 {
00158 return (Err == e);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00179 class BHKinematic
00180 {
00181
00182 public:
00185 BHKinematic();
00186
00189 ~BHKinematic();
00190
00191
00198 void motor2Joint(double *result, int *motorValues);
00199
00206 void motor2Joint(const int &finger, const int &motor, double &joint0, double &joint1);
00207
00208
00209 unsigned int joint2Motor(const BHandKin::FINGER finger, const double &joint);
00210
00215 void joint2MotorJoint1(const BHandKin::FINGER finger , double &joint, int &motor, double &joint1);
00216
00222 int joint2Spread(const double &joint);
00223
00230 void joint2SpreadJoint1(double &joint, int &motor, double &joint1);
00231
00237 void joint2Motor(int result[4], double joints[8]);
00238
00239
00246 void joint2Motor(int result[4], double joints[3], double spread);
00247
00254 void updateJointValues(int *motorValues);
00255
00256
00257
00260 void showJointValues();
00261
00264 void forwardKinematics();
00265
00269 void forwardKinematics(const BHandKin::FINGER finger);
00270
00274 TRSF_PTR getTrsf(const BHandKin::FINGER finger);
00275
00278 void showTrsf() const;
00279
00283 void showTrsf(const BHandKin::FINGER finger) const;
00284
00289 void setTS(const BHandKin::FINGER finger, const bool flag = true);
00290
00295 bool getTS(const BHandKin::FINGER finger);
00296
00297 double getTSActivationPoint(const BHandKin::FINGER finger) const;
00298
00299
00300 bool invKinematic(const BHandKin::FINGER f, const VECT ziel, float &angle, float &spread);
00301
00302
00306 void resetKinematic();
00307
00308
00315 static const double FM2JNoTorque;
00319 static const double FM2JTorque;
00323 static const double SM2J;
00325
00332 static const double J2FMNoTorque;
00336 static const double J2FMTorque;
00339 static const double J2SM;
00341
00342
00349 static const double JOINT1STDVALUE_DEG;
00352 static const double JOINT1MAX_DEG;
00353
00356 static const double JOINT1STDVALUE_RAD;
00359 static const double JOINT1MAX_RAD;
00360
00363 static const double JOINT0STDVALUE_DEG;
00366 static const double JOINT0MAX_DEG;
00367
00370 static const double JOINT0STDVALUE_RAD;
00373 static const double JOINT0MAX_RAD;
00375
00382 static const double JOINT1STDVALUE_KIN_DEG;
00385 static const double JOINT1STDVALUE_KIN_RAD;
00386
00389 static const double JOINT1STDVALUE_DIFF_KIN_DEG;
00392 static const double JOINT1STDVALUE_DIFF_KIN_RAD;
00394
00395
00399 static const double Aw;
00400 static const double A1;
00401 static const double A2;
00402 static const double A3;
00403 static const double Dw;
00404 static const double D3;
00405 static const double Rho2;
00406
00408
00409 protected:
00410
00411 bool reducedProblem(VECT &ziel, float &angle);
00412
00416
00421 double clipJ1(const double &value)const;
00422
00427 double clipJ0(const double &value) const;
00429
00430
00431
00434 BHandJoints JointValues;
00435
00438 FingerTransforms FingerTrsf;
00439
00440 };
00441
00442
00443
00444
00445
00446 inline double BHKinematic::clipJ1(const double &value)const
00447 {
00448 double result = (value < JOINT1STDVALUE_DEG)? 45.0 : value;
00449 result = (result > JOINT1MAX_DEG) ? JOINT1MAX_DEG : result;
00450 return result;
00451 }
00452
00453
00454
00455
00456 inline double BHKinematic::clipJ0(const double &value)const
00457 {
00458 double result = (value < JOINT0STDVALUE_DEG) ? 2.46 : value;
00459 result = (result > JOINT0MAX_DEG) ? JOINT0MAX_DEG : result;
00460 return result;
00461 }
00462
00463
00464
00465
00466 inline TRSF_PTR BHKinematic::getTrsf(const BHandKin::FINGER finger)
00467 {
00468 return FingerTrsf.Pos[finger-1];
00469 }
00470
00471
00472
00473
00474 inline void BHKinematic::setTS(const BHandKin::FINGER finger, const bool flag)
00475 {
00476 JointValues.TorqueSwitch[finger-1] = flag;
00477
00478 JointValues.TSActivationPoint[finger-1] =
00479 (flag) ? JointValues.F[finger-1].Joint[0] : 0.0;
00480
00481 std::cout << " inline void BHKinematic::setTS(const BHandKin::FINGER finger, const bool flag)\n"
00482 << " *** Value: " << JointValues.TSActivationPoint[finger-1] << std::endl;
00483
00484
00485 }
00486
00487
00488
00489
00490
00491 inline bool BHKinematic::getTS(const BHandKin::FINGER finger)
00492 {
00493 return JointValues.TorqueSwitch[finger-1];
00494 }
00495
00496
00497
00498
00499 inline double BHKinematic::getTSActivationPoint(const BHandKin::FINGER finger) const
00500 {
00501 return JointValues.TSActivationPoint[finger-1];
00502 }
00503
00504
00505 #endif