1 #ifndef _PIVOT_CALIBRATION_VREP_PLUGIN_HPP_     2 #define _PIVOT_CALIBRATION_VREP_PLUGIN_HPP_     7 #include <boost/log/trivial.hpp>     8 #include <boost/exception/all.hpp>     9 #include <boost/algorithm/string.hpp>    13 #include "TRTK/PivotCalibration.hpp"    19 inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& out,  std::vector<T>& v)
    22     size_t last = v.size() - 1;
    23     for(
size_t i = 0; i < v.size(); ++i) {
    48   static const bool debug = 
false;
    66         return std::make_tuple(
   101   algorithm = algorithm_;
   107    BOOST_LOG_TRIVIAL(trace) << 
"Adding pivot calibration frame #" << ++frameCount << std::endl;
   112       firstToolTipInToolBaseInverse             = toolTipInToolBase.inverse();
   113       isFirstFrame = 
false;
   116     auto toolTipInFirstTipBase      = firstToolTipInToolBaseInverse * toolTipInToolBase;        
   119     rvecsArm.push_back(     toolTipInFirstTipBase.rotation().matrix());
   120     tvecsArm.push_back(     toolTipInFirstTipBase.translation()     );
   125      std::cout << 
"\ntoolTipInToolBase:\n" << poseString(toolTipInToolBase) << 
"\n";
   127      std::cout << 
"\ntoolTipInFirstTipBase:\n" << poseString(toolTipInFirstTipBase) << 
"\n";
   131      BOOST_LOG_TRIVIAL(info) << 
"\n" << poseString(ToolTipToFiducial,
"expected ToolBaseToToolTip (simulation only): ") << std::endl;
   142    BOOST_LOG_TRIVIAL(trace) << 
"Running Pivot Calibration Estimate with the following numbers of entries in each category:  rvecsFiducial" << 
" rvecsArm: " << rvecsArm.size() << 
" tvecsArm: " << tvecsArm.size() << std::endl;
   144    BOOST_VERIFY(allHandlesSet);
   147    TRTK::PivotCalibrationTwoStep<double> pivotCalib;
   148    pivotCalib.setLocations(TRTK::make_range(tvecsArm));
   149    pivotCalib.setRotations(TRTK::make_range(rvecsArm));
   154    pivotCalib.compute();
   156    transformEstimate.translation() = pivotCalib.getPivotPoint();
   161     if(ret==-1) BOOST_THROW_EXCEPTION(std::runtime_error(
"PivotCalibrationVrepPlugin: Could not get position"));
   163     if(ret==-1) BOOST_THROW_EXCEPTION(std::runtime_error(
"PivotCalibrationVrepPlugin: Could not get quaternion"));
   168      BOOST_LOG_TRIVIAL(info) << 
"\n" << poseString(ToolTipToFiducial,
"expected ToolBaseToToolTip (simulation only): ") << std::endl;
   171    BOOST_LOG_TRIVIAL(info) << 
"\n" << poseString(transformEstimate,
"estimated toolBaseMeasured to toolTipMeasured:") << std::endl;
   174    Eigen::Quaterniond eigenQuat(transformEstimate.rotation());
   175    BOOST_LOG_TRIVIAL(info) << 
"Pivot Calibration Estimate quat wxyz\n: " << eigenQuat.w() << 
" " << eigenQuat.x() << 
" " << eigenQuat.y() << 
" " << eigenQuat.z() << 
" " << 
" translation xyz: " << transformEstimate.translation().x() << 
" " << transformEstimate.translation().y() << 
" " << transformEstimate.translation().z() << 
" " << std::endl;
   177     BOOST_LOG_TRIVIAL(info) << 
"Optical Tracker Base Measured quat wxyz\n: " << detectedObjectQuaternion[0] << 
" " << detectedObjectQuaternion[1] << 
" " << detectedObjectQuaternion[2] << 
" " << detectedObjectQuaternion[3] << 
" " << 
" translation xyz: " << detectedObjectPosition[0] << 
" " << detectedObjectPosition[1] << 
" " << detectedObjectPosition[2] << 
" " << std::endl;
   192    return transformEstimate;
   216     toolTip                         = grl::vrep::getHandleFromParam<ToolTipToMeasureName>                   (params_);                  
   217     toolBase                        = grl::vrep::getHandleFromParam<ToolBaseToMeasureName>                  (params_);
   218     toolTipToModify                 = grl::vrep::getHandleFromParam<ToolTipToModifyName>                    (params_);                  
   219     toolBaseToModify                = grl::vrep::getHandleFromParam<ToolBaseToModifyName>                   (params_);
   221     allHandlesSet  = 
true;
   225 std::string algorithm = 
"TWO_STEP_PROCEDURE";
   227 std::vector<typename TRTK::PivotCalibrationTwoStep<double>::Matrix3T > rvecsArm;
   228 std::vector<typename TRTK::PivotCalibrationTwoStep<double>::Vector3T > tvecsArm;
   231 std::size_t frameCount;
   232 Eigen::Affine3d firstToolTipInToolBaseInverse;
   235 std::array<float,3> detectedObjectPosition;
   236 std::array<float,4> detectedObjectQuaternion;
   238 Eigen::Affine3d transformEstimate;
   242 int toolTipToModify = -1;
   243 int toolBaseToModify = -1;
   248 bool allHandlesSet = 
false;
   255   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 void applyEstimate()
Will apply the stored estimate to the v-rep simulation value. 
 
static const Params defaultParams()
 
std::tuple< std::string, std::string, std::string, std::string > Params
 
void restoreSensorPosition()
Correct modified transform for measured optical tracker data. 
 
V-REP handle string for the tip of the tool that will be measured 
 
Eigen::Affine3d getObjectTransform(int objectHandle, int relativeToObjectHandle=-1)
 
V-REP handle string for the base of the tool that will be modified 
 
V-REP handle string for the tip of the tool that will be modified 
 
ptrSimGetObjectPosition simGetObjectPosition
 
ptrSimSetObjectPosition simSetObjectPosition
 
void setAlgorithm(std::string algorithm_)
 
void setObjectTransform(int objectHandle, int relativeToObjectHandle, T &transform)
 
void estimatePivotOffset()
run solver to estimate the unknown transform and set the simulation to the estimated value ...
 
ptrSimSetObjectQuaternion simSetObjectQuaternion
 
V-REP handle string for the base of the tool that will be measured 
 
ptrSimGetObjectQuaternion simGetObjectQuaternion
 
PivotCalibrationVrepPlugin(Params params=defaultParams())
 
Eigen::Affine3d getEstimate()