calibrator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * $Id: file.cpp 3496 2011-11-22 15:14:32Z fnovotny $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Contact visp@irisa.fr if any conditions of this licensing are
34  * not clear to you.
35  *
36  * Description:
37  * Calibrator node
38  *
39  * Authors:
40  * Filip Novotny
41  *
42  *
43  *****************************************************************************/
44 
50 #include "calibrator.h"
51 #include <visp_bridge/3dpose.h>
52 #include "names.h"
53 #include <visp/vpCalibration.h>
54 #include <visp/vpHomogeneousMatrix.h>
55 
56 
58 {
59  void Calibrator::cameraObjectCallback(const geometry_msgs::Transform::ConstPtr& trans)
60  {
61  ROS_DEBUG("new cMo: [%f,%f,%f -- %f,%f,%f,%f]", trans->translation.x,trans->translation.y,trans->translation.z,trans->rotation.x,trans->rotation.y,trans->rotation.z,trans->rotation.w);
62  vpHomogeneousMatrix cMo;
64  cMo_vec_.push_back(cMo);
65  }
66 
67  void Calibrator::worldEffectorCallback(const geometry_msgs::Transform::ConstPtr& trans)
68  {
69  ROS_DEBUG("new wMe: [%f,%f,%f -- %f,%f,%f,%f]", trans->translation.x,trans->translation.y,trans->translation.z,trans->rotation.x,trans->rotation.y,trans->rotation.z,trans->rotation.w);
70  vpHomogeneousMatrix wMe;
72  wMe_vec_.push_back(wMe);
73  }
74 
76  visp_hand2eye_calibration::compute_effector_camera::Request &req,
77  visp_hand2eye_calibration::compute_effector_camera::Response &res)
78  {
79  if (cMo_vec_.size() != wMe_vec_.size() || wMe_vec_.size() < 2)
80  {
81  ROS_ERROR("transformation vectors have different sizes or contain too few elements");
82  return false;
83  }
84 
85  ROS_INFO("computing %d values...",(int)wMe_vec_.size());
86  vpHomogeneousMatrix eMc;
87  #if VISP_VERSION_INT > (2<<16 | 6<<8 | 1)
88  vpCalibration::calibrationTsai(cMo_vec_, wMe_vec_, eMc);
89  #else
90  vpCalibration::calibrationTsai(cMo_vec_.size(),&(cMo_vec_[0]),&(wMe_vec_[0]),eMc);
91  #endif
92  geometry_msgs::Transform trans;
94 
95  res.effector_camera = trans;
96  return true;
97  }
98 
100  visp_hand2eye_calibration::compute_effector_camera_quick::Request &req,
101  visp_hand2eye_calibration::compute_effector_camera_quick::Response &res)
102  {
103  visp_hand2eye_calibration::TransformArray camera_object = req.camera_object;
104  visp_hand2eye_calibration::TransformArray world_effector = req.world_effector;
105  std::vector<vpHomogeneousMatrix> cMo_vec;
106  std::vector<vpHomogeneousMatrix> wMe_vec;
107  for(unsigned int i=0;i<camera_object.transforms.size();i++){
108  cMo_vec.push_back(visp_bridge::toVispHomogeneousMatrix(camera_object.transforms[i]));
109  wMe_vec.push_back(visp_bridge::toVispHomogeneousMatrix(world_effector.transforms[i]));
110  }
111  if (camera_object.transforms.size() != world_effector.transforms.size() || world_effector.transforms.size() < 2)
112  {
113  ROS_ERROR("transformation vectors have different sizes or contain too few elements");
114  return false;
115  }
116 
117  ROS_INFO("computing...");
118  vpHomogeneousMatrix eMc;
119  #if VISP_VERSION_INT > (2<<16 | 6<<8 | 1)
120  vpCalibration::calibrationTsai(cMo_vec, wMe_vec, eMc);
121  #else
122  vpCalibration::calibrationTsai(cMo_vec.size(),&(cMo_vec[0]),&(wMe_vec[0]),eMc);
123  #endif
124  geometry_msgs::Transform trans;
126  res.effector_camera = trans;
127  return true;
128  }
129 
130  bool Calibrator::resetCallback(visp_hand2eye_calibration::reset::Request &req,
131  visp_hand2eye_calibration::reset::Response &res)
132  {
133  ROS_INFO("reseting...");
134  cMo_vec_.clear();
135  wMe_vec_.clear();
136  return true;
137  }
138 
140  check_inputs_(ros::NodeHandle(), ros::this_node::getName()),
141  queue_size_(1000)
142  {
143 
144  //prepare function objects
145  camera_object_subscriber_callback_t camera_object_callback = boost::bind(&Calibrator::cameraObjectCallback, this, _1);
146  world_effector_subscriber_t world_effector_callback = boost::bind(&Calibrator::worldEffectorCallback, this, _1);
147 
148  compute_effector_camera_service_callback_t compute_effector_camera_callback =
149  boost::bind(&Calibrator::computeEffectorCameraCallback, this, _1, _2);
150  compute_effector_camera_quick_service_callback_t compute_effector_camera_quick_callback =
151  boost::bind(&Calibrator::computeEffectorCameraQuickCallback, this, _1, _2);
152  reset_service_callback_t reset_callback = boost::bind(&Calibrator::resetCallback, this, _1, _2);
153 
154  //define services
157  compute_effector_camera_callback);
160  compute_effector_camera_quick_callback);
162 
163  ros::V_string topics;
166 
167 
168  check_inputs_.start(topics, 60.0);
169  if (!ros::ok())
170  return;
171  //define subscribers
173  camera_object_callback);
175  world_effector_callback);
176 
177 
178  }
179 
181  {
182  ros::spin();
183  }
185  {
186 
187  }
188 }
std::string camera_object_topic
ros::Subscriber camera_object_subscriber_
Definition: calibrator.h:73
Calibrator node implementing a quick compute service, a compute service and 2 subscribers to world_ef...
vpHomogeneousMatrix toVispHomogeneousMatrix(const geometry_msgs::Transform &trans)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void start(const ros::V_string &topics, double duration)
ros::ServiceServer compute_effector_camera_service_
Definition: calibrator.h:70
std::vector< vpHomogeneousMatrix > cMo_vec_
Definition: calibrator.h:77
std::string getName(void *handle)
std::string compute_effector_camera_service
std::vector< vpHomogeneousMatrix > wMe_vec_
Definition: calibrator.h:78
void worldEffectorCallback(const geometry_msgs::Transform::ConstPtr &trans)
callback corresponding to the world->effector topic.
Definition: calibrator.cpp:67
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
boost::function< void(const geometry_msgs::Transform::ConstPtr &)> camera_object_subscriber_callback_t
subscriber type declaration for camera->object topic subscriber
Definition: calibrator.h:137
bool resetCallback(visp_hand2eye_calibration::reset::Request &req, visp_hand2eye_calibration::reset::Response &res)
service reseting the acumulated data
Definition: calibrator.cpp:130
ROSCPP_DECL void spin(Spinner &spinner)
ros::Subscriber world_effector_subscriber_
Definition: calibrator.h:74
Calibrator()
advertises services and subscribes to topics
Definition: calibrator.cpp:139
std::string world_effector_topic
std::vector< std::string > V_string
#define ROS_INFO(...)
boost::function< bool(visp_hand2eye_calibration::compute_effector_camera::Request &, visp_hand2eye_calibration::compute_effector_camera::Response &res)> compute_effector_camera_service_callback_t
service type declaration for effector->camera computation service
Definition: calibrator.h:127
ROSCPP_DECL bool ok()
image_proc::AdvertisementChecker check_inputs_
Definition: calibrator.h:75
boost::function< bool(visp_hand2eye_calibration::compute_effector_camera_quick::Request &, visp_hand2eye_calibration::compute_effector_camera_quick::Response &res)> compute_effector_camera_quick_service_callback_t
service type declaration for quick effector->camera computation service
Definition: calibrator.h:130
void cameraObjectCallback(const geometry_msgs::Transform::ConstPtr &trans)
callback corresponding to the camera->object topic.
Definition: calibrator.cpp:59
bool computeEffectorCameraCallback(visp_hand2eye_calibration::compute_effector_camera::Request &req, visp_hand2eye_calibration::compute_effector_camera::Response &res)
service computing world->effector transformation from accumulated data.
Definition: calibrator.cpp:75
geometry_msgs::Transform toGeometryMsgsTransform(const vpHomogeneousMatrix &mat)
boost::function< void(const geometry_msgs::Transform::ConstPtr &trans)> world_effector_subscriber_t
subscriber type declaration for world->effector topic subscriber
Definition: calibrator.h:140
boost::function< bool(visp_hand2eye_calibration::reset::Request &, visp_hand2eye_calibration::reset::Response &res)> reset_service_callback_t
service type declaration for reset service
Definition: calibrator.h:133
bool computeEffectorCameraQuickCallback(visp_hand2eye_calibration::compute_effector_camera_quick::Request &req, visp_hand2eye_calibration::compute_effector_camera_quick::Response &res)
service computing world->effector transformation from parameter-passed data.
Definition: calibrator.cpp:99
std::string compute_effector_camera_quick_service
#define ROS_ERROR(...)
ros::ServiceServer compute_effector_camera_quick_service_
Definition: calibrator.h:71
void spin()
spins the ros node
Definition: calibrator.cpp:180
#define ROS_DEBUG(...)


visp_hand2eye_calibration
Author(s): Filip Novotny
autogenerated on Wed Jul 3 2019 19:48:05