00001
00002 #ifndef INCLUDED_IKThreeLink_h_
00003 #define INCLUDED_IKThreeLink_h_
00004
00005 #include "Shared/RobotInfo.h"
00006 #if (defined(TGT_HAS_LEGS) && !defined(TGT_IS_AIBO)) || defined(TGT_HAS_HEAD)
00007
00008 #include "IKSolver.h"
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 class IKThreeLink : public IKSolver {
00024 public:
00025
00026 IKThreeLink() : IKSolver(), invertThird(false), hasInverseSolution(false), inverseKnee() {}
00027
00028 virtual bool solve(const Point& pEff, const Rotation& oriEff, KinematicJoint& j, const Position& pTgt, float posPri, const Orientation& oriTgt, float oriPri) const;
00029 using IKSolver::solve;
00030
00031 virtual IKSolver::StepResult_t step(const Point& pEff, const Rotation& oriEff, KinematicJoint& j, const Position& pTgt, float pDist, float posPri, const Orientation& oriTgt, float oriDist, float oriPri) const;
00032 using IKSolver::step;
00033
00034 protected:
00035
00036 static const float EPSILON;
00037
00038 static unsigned int setLinks(KinematicJoint& eff, KinematicJoint* links[], unsigned int remain);
00039
00040
00041 void computeFirstLink(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool& valid) const {
00042 if(curlink.jointType==KinematicJoint::PRISMATIC) {
00043 computeFirstLinkPrismatic(curlink,Pobj,endlink,Plink,valid);
00044 } else {
00045 computeFirstLinkRevolute(curlink,Pobj,endlink,Plink,valid);
00046 }
00047 }
00048
00049 void computeFirstLinkRevolute(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool& valid) const;
00050
00051 void computeFirstLinkPrismatic(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool& valid) const;
00052
00053
00054 void computeSecondLink(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool invert, bool& valid) const {
00055 if(curlink.jointType==KinematicJoint::PRISMATIC) {
00056 computeSecondLinkPrismatic(curlink,Pobj,endlink,Plink,invert,valid);
00057 } else {
00058 computeSecondLinkRevolute(curlink,Pobj,endlink,Plink,invert,valid);
00059 }
00060 }
00061
00062 void computeSecondLinkRevolute(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool invert, bool& valid) const;
00063
00064 void computeSecondLinkPrismatic(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool invert, bool& valid) const;
00065
00066
00067 void computeThirdLink(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool invert, bool& valid) const {
00068 if(curlink.jointType==KinematicJoint::PRISMATIC) {
00069 computeThirdLinkPrismatic(curlink,Pobj,endlink,Plink,invert,valid);
00070 } else {
00071 computeThirdLinkRevolute(curlink,Pobj,endlink,Plink,invert,valid);
00072 }
00073 }
00074
00075 void computeThirdLinkRevolute(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool invert, bool& valid) const;
00076
00077 void computeThirdLinkPrismatic(KinematicJoint& curlink, const fmat::Column<3>& Pobj, KinematicJoint& endlink, const fmat::Column<3>& Plink, bool invert, bool& valid) const;
00078
00079
00080 static fmat::fmatReal computePrismaticQ(fmat::fmatReal objD2, fmat::fmatReal neckD2, fmat::fmatReal inner);
00081
00082
00083 static float normalize_angle(float x) { return x - static_cast<float>( rint(x/(2*M_PI)) * (2*M_PI) ); }
00084
00085 bool invertThird;
00086
00087 mutable bool hasInverseSolution;
00088 mutable float inverseKnee;
00089
00090 private:
00091
00092 static const std::string autoRegisterIKThreeLink;
00093 };
00094
00095
00096
00097
00098
00099 #endif
00100
00101 #endif