prismatic_model.cpp
Go to the documentation of this file.
00001 /*
00002  * prismatic_model.cpp
00003  *
00004  *  Created on: Oct 21, 2009
00005  *      Author: sturm
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 #include <iomanip>
00021 #define VEC(a) setprecision(5)<<fixed<<a.x()<<" "<<a.y()<<" "<<a.z()<<" "<<a.w()<<" l="<<a.length()
00022 #define VEC2(a) "t=["<<VEC(a.getOrigin())<<"] r=[]"<<VEC(a.getRotation())<<"]"
00023 #define PRINT(a) cout << #a <<"=" << VEC(a)<<endl;
00024 #define PRINT2(a) cout << #a <<"=" << VEC2(a)<<endl;
00025 
00026 namespace articulation_models {
00027 
00028 PrismaticModel::PrismaticModel() {
00029         prismatic_dir = tf::Vector3(0,0,0);
00030 
00031         complexity = 6+2; // rigid + 2 (orientation, without yaw)
00032 }
00033 
00034 // -- params
00035 void PrismaticModel::readParamsFromModel() {
00036         RigidModel::readParamsFromModel();
00037         getParam("prismatic_dir",prismatic_dir);
00038 }
00039 
00040 void PrismaticModel::writeParamsToModel() {
00041         RigidModel::writeParamsToModel();
00042         setParam("prismatic_dir",prismatic_dir,ParamMsg::PARAM);
00043 }
00044 
00045 V_Configuration PrismaticModel::predictConfiguration(geometry_msgs::Pose pose) {
00046         tf::Vector3 diff = (positionToVector(pose.position) - rigid_position);
00047 
00048         V_Configuration q( 1 );
00049         q(0) = diff.dot(prismatic_dir);
00050 
00051         return q;
00052 }
00053 
00054 geometry_msgs::Pose PrismaticModel::predictPose(V_Configuration q) {
00055 //      cout << "predictPose q(0)=" <<q(0) << endl;
00056 //      PRINT(rigid_orientation);
00057 //      PRINT(rigid_position);
00058 //      PRINT(prismatic_dir);
00059         return transformToPose( tf::Transform( rigid_orientation, rigid_position + q(0) * prismatic_dir ) );
00060 }
00061 
00062 M_CartesianJacobian PrismaticModel::predictHessian(V_Configuration q,double delta) {
00063         M_CartesianJacobian H;
00064         H.setZero(3*getDOFs(),getDOFs());
00065         return H;
00066 }
00067 
00068 bool PrismaticModel::guessParameters() {
00069         if(model.track.pose.size() < 2)
00070                 return false;
00071 
00072         size_t i,j;
00073         do{
00074                 i = rand() % getSamples();
00075                 j = rand() % getSamples();
00076         } while (i==j);
00077 
00078         tf::Transform pose1 = poseToTransform(model.track.pose[i]);
00079         tf::Transform pose2 = poseToTransform(model.track.pose[j]);
00080 
00081         rigid_position = pose1.getOrigin();
00082         rigid_orientation = pose1.getRotation();
00083         prismatic_dir =  pose2.getOrigin() - pose1.getOrigin();
00084         prismatic_dir.normalize();
00085 
00086         if(!check_values(rigid_position)) return false;
00087         if(!check_values(rigid_orientation)) return false;
00088         if(!check_values(prismatic_dir)) return false;
00089 
00090         return true;
00091 }
00092 
00093 void PrismaticModel::updateParameters(std::vector<double> delta) {
00094         RigidModel::updateParameters(delta);
00095 
00096         tf::Quaternion q;
00097         q.setRPY(delta[6],delta[7],0.00);
00098         prismatic_dir = tf::Matrix3x3(q) * prismatic_dir;
00099 }
00100 bool PrismaticModel::normalizeParameters() {
00101         if(model.track.pose.size()>2) {
00102                 rigid_position = rigid_position + predictConfiguration(model.track.pose.front())[0] * prismatic_dir;
00103                 if(predictConfiguration(model.track.pose.back())[0]<0)
00104                         prismatic_dir *= -1;
00105         }
00106         return true;
00107 }
00108 
00109 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


articulation_models
Author(s): Juergen Sturm
autogenerated on Wed Dec 26 2012 15:35:18