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 #if VISP_VERSION_INT >= (3<<16 | 2<<8 | 0)
54 # include <visp3/vision/vpHandEyeCalibration.h>
55 #else
56 # include <visp3/vision/vpCalibration.h>
57 #endif
58 #include <visp3/core/vpHomogeneousMatrix.h>
59 
60 
62 {
63  void Calibrator::cameraObjectCallback(const geometry_msgs::Transform::ConstPtr& trans)
64  {
65  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);
66  vpHomogeneousMatrix cMo;
68  cMo_vec_.push_back(cMo);
69  }
70 
71  void Calibrator::worldEffectorCallback(const geometry_msgs::Transform::ConstPtr& trans)
72  {
73  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);
74  vpHomogeneousMatrix wMe;
76  wMe_vec_.push_back(wMe);
77  }
78 
80  visp_hand2eye_calibration::compute_effector_camera::Request &req,
81  visp_hand2eye_calibration::compute_effector_camera::Response &res)
82  {
83  if (cMo_vec_.size() != wMe_vec_.size() || wMe_vec_.size() < 2)
84  {
85  ROS_ERROR("transformation vectors have different sizes or contain too few elements");
86  return false;
87  }
88 
89  ROS_INFO("computing %d values...",(int)wMe_vec_.size());
90  vpHomogeneousMatrix eMc;
91 
92 #if VISP_VERSION_INT >= (3<<16 | 2<<8 | 0)
93  vpHandEyeCalibration::calibrate(cMo_vec_, wMe_vec_, eMc);
94 #elif VISP_VERSION_INT > (2<<16 | 6<<8 | 1)
95  vpCalibration::calibrationTsai(cMo_vec_, wMe_vec_, eMc);
96 #else
97  vpCalibration::calibrationTsai(cMo_vec_.size(), &(cMo_vec_[0]), &(wMe_vec_[0]), eMc);
98 #endif
99  geometry_msgs::Transform trans;
101 
102  res.effector_camera = trans;
103  return true;
104  }
105 
107  visp_hand2eye_calibration::compute_effector_camera_quick::Request &req,
108  visp_hand2eye_calibration::compute_effector_camera_quick::Response &res)
109  {
110  visp_hand2eye_calibration::TransformArray camera_object = req.camera_object;
111  visp_hand2eye_calibration::TransformArray world_effector = req.world_effector;
112  std::vector<vpHomogeneousMatrix> cMo_vec;
113  std::vector<vpHomogeneousMatrix> wMe_vec;
114  for(unsigned int i=0;i<camera_object.transforms.size();i++){
115  cMo_vec.push_back(visp_bridge::toVispHomogeneousMatrix(camera_object.transforms[i]));
116  wMe_vec.push_back(visp_bridge::toVispHomogeneousMatrix(world_effector.transforms[i]));
117  }
118  if (camera_object.transforms.size() != world_effector.transforms.size() || world_effector.transforms.size() < 2)
119  {
120  ROS_ERROR("transformation vectors have different sizes or contain too few elements");
121  return false;
122  }
123 
124  ROS_INFO("computing...");
125  vpHomogeneousMatrix eMc;
126 #if VISP_VERSION_INT >= (3<<16 | 2<<8 | 0)
127  vpHandEyeCalibration::calibrate(cMo_vec, wMe_vec, eMc);
128 #elif VISP_VERSION_INT > (2<<16 | 6<<8 | 1)
129  vpCalibration::calibrationTsai(cMo_vec, wMe_vec, eMc);
130 #else
131  vpCalibration::calibrationTsai(cMo_vec.size(), &(cMo_vec[0]), &(wMe_vec[0]),eMc);
132 #endif
133  geometry_msgs::Transform trans;
135  res.effector_camera = trans;
136  return true;
137  }
138 
139  bool Calibrator::resetCallback(visp_hand2eye_calibration::reset::Request &req,
140  visp_hand2eye_calibration::reset::Response &res)
141  {
142  ROS_INFO("reseting...");
143  cMo_vec_.clear();
144  wMe_vec_.clear();
145  return true;
146  }
147 
149  check_inputs_(ros::NodeHandle(), ros::this_node::getName()),
150  queue_size_(1000)
151  {
152 
153  //prepare function objects
154  camera_object_subscriber_callback_t camera_object_callback = boost::bind(&Calibrator::cameraObjectCallback, this, _1);
155  world_effector_subscriber_t world_effector_callback = boost::bind(&Calibrator::worldEffectorCallback, this, _1);
156 
157  compute_effector_camera_service_callback_t compute_effector_camera_callback =
158  boost::bind(&Calibrator::computeEffectorCameraCallback, this, _1, _2);
159  compute_effector_camera_quick_service_callback_t compute_effector_camera_quick_callback =
160  boost::bind(&Calibrator::computeEffectorCameraQuickCallback, this, _1, _2);
161  reset_service_callback_t reset_callback = boost::bind(&Calibrator::resetCallback, this, _1, _2);
162 
163  //define services
166  compute_effector_camera_callback);
169  compute_effector_camera_quick_callback);
171 
172  ros::V_string topics;
175 
176 
177  check_inputs_.start(topics, 60.0);
178  if (!ros::ok())
179  return;
180  //define subscribers
182  camera_object_callback);
184  world_effector_callback);
185 
186 
187  }
188 
190  {
191  ros::spin();
192  }
194  {
195 
196  }
197 }
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:71
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:139
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:148
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:63
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:79
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:106
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:189
#define ROS_DEBUG(...)


visp_hand2eye_calibration
Author(s): Filip Novotny
autogenerated on Sat Mar 13 2021 03:20:04