Skip to content
Snippets Groups Projects
Commit 3fe4c800 authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

[effector] split computeDistanceCostFunction in two and change return type

parent 1c2a04e2
No related branches found
No related tags found
No related merge requests found
...@@ -188,31 +188,37 @@ void computeConstraintsMatrix(const ProblemData& pData,const std::vector<waypoin ...@@ -188,31 +188,37 @@ void computeConstraintsMatrix(const ProblemData& pData,const std::vector<waypoin
b.segment<DIM_POINT>(i*DIM_POINT) = Vector3(10,10,10);*/ b.segment<DIM_POINT>(i*DIM_POINT) = Vector3(10,10,10);*/
} }
std::pair<MatrixXX,VectorX> computeDistanceCostFunction(int numPoints,const ProblemData& pData, double T,std::vector<point3_t> pts_path){
template <typename Path> assert(numPoints == pts_path.size() && "Pts_path size must be equal to numPoints");
void computeDistanceCostFunction(int numPoints,const ProblemData& pData, double T,const Path& path, MatrixXX& H,VectorX& g){
double step = 1./(numPoints-1); double step = 1./(numPoints-1);
std::vector<point_t> pi = computeConstantWaypoints(pData,T); std::vector<point_t> pi = computeConstantWaypoints(pData,T);
std::vector<waypoint_t> cks; waypoint_t c_wp;
for(size_t i = 0 ; i < numPoints ; ++i){ MatrixXX H = MatrixXX::Zero(dimVar(pData),dimVar(pData));
cks.push_back(evaluateCurveWaypointAtTime(pData,pi,i*step)); VectorX g = VectorX::Zero(dimVar(pData));
}
H = MatrixXX::Zero(dimVar(pData),dimVar(pData));
g = VectorX::Zero(dimVar(pData));
point3_t pk; point3_t pk;
size_t i = 0; for(size_t i = 0 ; i < numPoints ; ++i){
for (std::vector<waypoint_t>::const_iterator ckcit = cks.begin(); ckcit != cks.end(); ++ckcit){ c_wp = evaluateCurveWaypointAtTime(pData,pi,i*step);
pk=path(i*step); pk = pts_path[i];
// std::cout<<"pk = "<<pk.transpose()<<std::endl; // std::cout<<"pk = "<<pk.transpose()<<std::endl;
// std::cout<<"coef First : "<<ckcit->first<<std::endl; // std::cout<<"coef First : "<<ckcit->first<<std::endl;
// std::cout<<"coef second : "<<ckcit->second.transpose()<<std::endl; // std::cout<<"coef second : "<<ckcit->second.transpose()<<std::endl;
H += (ckcit->first.transpose() * ckcit->first); H += (c_wp.first.transpose() * c_wp.first);
g += ((ckcit->second - pk).transpose() * ckcit->first).transpose(); g += ((c_wp.second - pk).transpose() * c_wp.first).transpose();
i++;
} }
double norm=H.norm(); double norm=H.norm();
H /= norm; H /= norm;
g /= norm; g /= norm;
return std::make_pair(H,g);
}
template <typename Path>
std::pair<MatrixXX,VectorX> computeDistanceCostFunction(int numPoints,const ProblemData& pData, double T,const Path& path){
double step = 1./(numPoints-1);
std::vector<point3_t> pts_path;
for(size_t i = 0 ; i < numPoints ; ++i)
pts_path.push_back(path((double)(i*step)));
return computeDistanceCostFunction(numPoints,pData,T,pts_path);
} }
//TODO //TODO
...@@ -329,15 +335,15 @@ std::pair<MatrixXX,VectorX> computeEndEffectorCost(const ProblemData& pData,cons ...@@ -329,15 +335,15 @@ std::pair<MatrixXX,VectorX> computeEndEffectorCost(const ProblemData& pData,cons
double weightSmooth = 1. - weightDistance; double weightSmooth = 1. - weightDistance;
const int DIM_VAR = dimVar(pData); const int DIM_VAR = dimVar(pData);
// compute distance cost function (discrete integral under the curve defined by 'path') // compute distance cost function (discrete integral under the curve defined by 'path')
MatrixXX H_rrt,H; MatrixXX H;
VectorX g_rrt,g; VectorX g;
std::pair<MatrixXX,VectorX> Hg_smooth; std::pair<MatrixXX,VectorX> Hg_smooth,Hg_rrt;
if(weightDistance>0) if(weightDistance>0)
computeDistanceCostFunction<Path>(50,pData,T,path,H_rrt,g_rrt); Hg_rrt = computeDistanceCostFunction<Path>(50,pData,T,path);
else{ else{
H_rrt=MatrixXX::Zero(DIM_VAR,DIM_VAR); Hg_rrt.first=MatrixXX::Zero(DIM_VAR,DIM_VAR);
g_rrt=VectorX::Zero(DIM_VAR); Hg_rrt.second=VectorX::Zero(DIM_VAR);
} }
Hg_smooth = computeVelocityCost(pData,T,pi); Hg_smooth = computeVelocityCost(pData,T,pi);
...@@ -350,8 +356,8 @@ std::pair<MatrixXX,VectorX> computeEndEffectorCost(const ProblemData& pData,cons ...@@ -350,8 +356,8 @@ std::pair<MatrixXX,VectorX> computeEndEffectorCost(const ProblemData& pData,cons
// add the costs : // add the costs :
H = MatrixXX::Zero(DIM_VAR,DIM_VAR); H = MatrixXX::Zero(DIM_VAR,DIM_VAR);
g = VectorX::Zero(DIM_VAR); g = VectorX::Zero(DIM_VAR);
H = weightSmooth*(Hg_smooth.first) + weightDistance*H_rrt; H = weightSmooth*(Hg_smooth.first) + weightDistance*Hg_rrt.first;
g = weightSmooth*(Hg_smooth.second) + weightDistance*g_rrt; g = weightSmooth*(Hg_smooth.second) + weightDistance*Hg_rrt.second;
// H = Hg_smooth.first; // H = Hg_smooth.first;
// g = Hg_smooth.second; // g = Hg_smooth.second;
...@@ -369,6 +375,8 @@ ResultDataCOMTraj solveEndEffector(const ProblemData& pData,const Path& path, co ...@@ -369,6 +375,8 @@ ResultDataCOMTraj solveEndEffector(const ProblemData& pData,const Path& path, co
std::pair<MatrixXX, VectorX> Ab = computeEndEffectorConstraints(pData,T,pi); std::pair<MatrixXX, VectorX> Ab = computeEndEffectorConstraints(pData,T,pi);
std::pair<MatrixXX, VectorX> Hg = computeEndEffectorCost(pData,path,T,weightDistance,useVelCost,pi); std::pair<MatrixXX, VectorX> Hg = computeEndEffectorCost(pData,path,T,weightDistance,useVelCost,pi);
if(verbose){ if(verbose){
std::cout<<"End eff A = "<<std::endl<<Ab.first<<std::endl;
std::cout<<"End eff b = "<<std::endl<<Ab.second<<std::endl;
std::cout<<"End eff H = "<<std::endl<<Hg.first<<std::endl; std::cout<<"End eff H = "<<std::endl<<Hg.first<<std::endl;
std::cout<<"End eff g = "<<std::endl<<Hg.second<<std::endl; std::cout<<"End eff g = "<<std::endl<<Hg.second<<std::endl;
std::cout<<"Dim Var = "<<dimVar(pData)<<std::endl; std::cout<<"Dim Var = "<<dimVar(pData)<<std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment