00001
00002
00003
00004
00005
00006
00007
00008 #include "articulation_models/models/prismatic_model.h"
00009 #include "articulation_models/utils.h"
00010
00011 using namespace std;
00012
00013 #include "Eigen/Core"
00014 #include <Eigen/SVD>
00015
00016 using namespace Eigen;
00017
00018 using namespace articulation_msgs;
00019
00020 USING_PART_OF_NAMESPACE_EIGEN
00021
00022 #include <iomanip>
00023 #define VEC(a) setprecision(5)<<fixed<<a.x()<<" "<<a.y()<<" "<<a.z()<<" "<<a.w()<<" l="<<a.length()
00024 #define VEC2(a) "t=["<<VEC(a.getOrigin())<<"] r=[]"<<VEC(a.getRotation())<<"]"
00025 #define PRINT(a) cout << #a <<"=" << VEC(a)<<endl;
00026 #define PRINT2(a) cout << #a <<"=" << VEC2(a)<<endl;
00027
00028 namespace articulation_models {
00029
00030 PrismaticModel::PrismaticModel() {
00031 prismatic_dir = btVector3(0,0,0);
00032
00033 complexity = 6+2;
00034 }
00035
00036
00037 void PrismaticModel::readParamsFromModel() {
00038 RigidModel::readParamsFromModel();
00039 getParam("prismatic_dir",prismatic_dir);
00040 }
00041
00042 void PrismaticModel::writeParamsToModel() {
00043 RigidModel::writeParamsToModel();
00044 setParam("prismatic_dir",prismatic_dir,ParamMsg::PARAM);
00045 }
00046
00047 V_Configuration PrismaticModel::predictConfiguration(geometry_msgs::Pose pose) {
00048 btVector3 diff = (positionToVector(pose.position) - rigid_position);
00049
00050 V_Configuration q( 1 );
00051 q(0) = diff.dot(prismatic_dir);
00052
00053 return q;
00054 }
00055
00056 geometry_msgs::Pose PrismaticModel::predictPose(V_Configuration q) {
00057
00058
00059
00060
00061 return transformToPose( btTransform( rigid_orientation, rigid_position + q(0) * prismatic_dir ) );
00062 }
00063
00064 M_CartesianJacobian PrismaticModel::predictHessian(V_Configuration q,double delta) {
00065 M_CartesianJacobian H;
00066 H.resize(3*getDOFs(),getDOFs());
00067 H.setZero();
00068 return H;
00069 }
00070
00071 bool PrismaticModel::guessParameters() {
00072 if(model.track.pose.size() < 2)
00073 return false;
00074
00075 size_t i,j;
00076 do{
00077 i = rand() % getSamples();
00078 j = rand() % getSamples();
00079 } while (i==j);
00080
00081 btTransform pose1 = poseToTransform(model.track.pose[i]);
00082 btTransform pose2 = poseToTransform(model.track.pose[j]);
00083
00084 rigid_position = pose1.getOrigin();
00085 rigid_orientation = pose1.getRotation();
00086 prismatic_dir = pose2.getOrigin() - pose1.getOrigin();
00087 prismatic_dir.normalize();
00088
00089 if(!check_values(rigid_position)) return false;
00090 if(!check_values(rigid_orientation)) return false;
00091 if(!check_values(prismatic_dir)) return false;
00092
00093 return true;
00094 }
00095
00096 void PrismaticModel::updateParameters(std::vector<double> delta) {
00097 RigidModel::updateParameters(delta);
00098
00099 btQuaternion q;
00100 q.setRPY(delta[6],delta[7],0.00);
00101 prismatic_dir = btMatrix3x3(q) * prismatic_dir;
00102 }
00103 bool PrismaticModel::normalizeParameters() {
00104 if(model.track.pose.size()>2) {
00105 rigid_position = rigid_position + predictConfiguration(model.track.pose.front())[0] * prismatic_dir;
00106 if(predictConfiguration(model.track.pose.back())[0]<0)
00107 prismatic_dir *= -1;
00108 }
00109 return true;
00110 }
00111
00112 }