3
@author Shin'ichiro Nakaoka
6
#include "CompositeIK.h"
11
using namespace boost;
12
using namespace cnoid;
15
CompositeIK::CompositeIK(BodyPtr body, Link* targetLink)
18
targetLink_ = targetLink;
19
isAnalytical_ = false;
23
CompositeIK::~CompositeIK()
29
bool CompositeIK::addBaseLink(Link* baseLink)
31
if(baseLink && targetLink_){
32
JointPathPtr path = body_->getJointPath(targetLink_, baseLink);
34
isAnalytical_ = pathList.empty() ? path->hasAnalyticalIK() : (isAnalytical_ && path->hasAnalyticalIK());
37
info.p0 = baseLink->p;
38
info.R0 = baseLink->R;
39
pathList.push_back(info);
47
void CompositeIK::setMaxIKerror(double e)
49
for(size_t i=0; i < pathList.size(); ++i){
50
pathList[i].path->setMaxIKerror(e);
55
bool CompositeIK::hasAnalyticalIK() const
64
bool CompositeIK::calcInverseKinematics(const Vector3& p, const Matrix3& R)
66
const int n = body_->numJoints();
68
Vector3 p0 = targetLink_->p;
69
Matrix3 R0 = targetLink_->R;
70
std::vector<double> q0(n);
71
for(int i=0; i < n; ++i){
72
q0[i] = body_->joint(i)->q;
78
for(size_t i=0; i < pathList.size(); ++i){
79
PathInfo& info = pathList[i];
80
solved = info.path->calcInverseKinematics(p, R, info.p0, info.R0);
84
Link* endLink = info.path->endLink();
92
for(int i=0; i < n; ++i){
93
body_->joint(i)->q = q0[i];
95
for(size_t i=0; i < pathList.size(); ++i){
96
PathInfo& info = pathList[i];
97
info.path->calcForwardKinematics();
98
Link* endLink = info.path->endLink();
100
endLink->R = info.R0;