client.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * $Id: file.h 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  * Client node
38  *
39  * Authors:
40  * Filip Novotny
41  *
42  *
43  *****************************************************************************/
44 
50 #include "client.h"
51 #include <geometry_msgs/Transform.h>
52 #include "visp_hand2eye_calibration/TransformArray.h"
53 #include <visp_bridge/3dpose.h>
54 #include "names.h"
55 
56 #include <visp/vpCalibration.h>
57 #include <visp/vpExponentialMap.h>
58 
60 {
62 {
64  = n_.advertise<geometry_msgs::Transform> (visp_hand2eye_calibration::camera_object_topic, 1000);
66  = n_.advertise<geometry_msgs::Transform> (visp_hand2eye_calibration::world_effector_topic, 1000);
67 
69  = n_.serviceClient<visp_hand2eye_calibration::reset> (visp_hand2eye_calibration::reset_service);
71  = n_.serviceClient<visp_hand2eye_calibration::compute_effector_camera> (
74  = n_.serviceClient<visp_hand2eye_calibration::compute_effector_camera_quick> (
76 }
77 
79 {
80  ROS_INFO("Waiting for topics...");
81  ros::Duration(1.).sleep();
83  if(!ros::ok()) return;
84  ros::Duration(1).sleep();
85  }
86 
87 
88  // We want to calibrate the hand to eye extrinsic camera parameters from 6 couple of poses: cMo and wMe
89  const int N = 6;
90  // Input: six couple of poses used as input in the calibration proces
91  vpHomogeneousMatrix cMo; // eye (camera) to object transformation. The object frame is attached to the calibrartion grid
92  vpHomogeneousMatrix wMe; // world to hand (end-effector) transformation
93  vpHomogeneousMatrix eMc; // hand (end-effector) to eye (camera) transformation
94 
95  // Initialize an eMc transformation used to produce the simulated input transformations cMo and wMe
96  vpTranslationVector etc(0.1, 0.2, 0.3);
97  vpThetaUVector erc;
98  erc[0] = vpMath::rad(10); // 10 deg
99  erc[1] = vpMath::rad(-10); // -10 deg
100  erc[2] = vpMath::rad(25); // 25 deg
101 
102  eMc.buildFrom(etc, erc);
103  ROS_INFO("1) GROUND TRUTH:");
104 
105  ROS_INFO_STREAM("hand to eye transformation: " <<std::endl<<visp_bridge::toGeometryMsgsTransform(eMc)<<std::endl);
106 
107  vpColVector v_c(6); // camera velocity used to produce 6 simulated poses
108  for (int i = 0; i < N; i++)
109  {
110  v_c = 0;
111  if (i == 0)
112  {
113  // Initialize first poses
114  cMo.buildFrom(0, 0, 0.5, 0, 0, 0); // z=0.5 m
115  wMe.buildFrom(0, 0, 0, 0, 0, 0); // Id
116  }
117  else if (i == 1)
118  v_c[3] = M_PI / 8;
119  else if (i == 2)
120  v_c[4] = M_PI / 8;
121  else if (i == 3)
122  v_c[5] = M_PI / 10;
123  else if (i == 4)
124  v_c[0] = 0.5;
125  else if (i == 5)
126  v_c[1] = 0.8;
127 
128  vpHomogeneousMatrix cMc; // camera displacement
129  cMc = vpExponentialMap::direct(v_c); // Compute the camera displacement due to the velocity applied to the camera
130  if (i > 0)
131  {
132  // From the camera displacement cMc, compute the wMe and cMo matrixes
133  cMo = cMc.inverse() * cMo;
134  wMe = wMe * eMc * cMc * eMc.inverse();
135 
136  }
137 
138  geometry_msgs::Transform pose_c_o;
139  pose_c_o = visp_bridge::toGeometryMsgsTransform(cMo);
140  geometry_msgs::Transform pose_w_e;
141  pose_w_e = visp_bridge::toGeometryMsgsTransform(wMe);
144  emc_quick_comm.request.camera_object.transforms.push_back(pose_c_o);
145  emc_quick_comm.request.world_effector.transforms.push_back(pose_w_e);
146 
147  }
148  ros::Duration(1.).sleep();
149 
150 }
151 
153 {
154  vpHomogeneousMatrix eMc;
155  vpThetaUVector erc;
156  ROS_INFO("2) QUICK SERVICE:");
158  {
159  ROS_INFO_STREAM("hand_camera: "<< std::endl << emc_quick_comm.response.effector_camera);
160  }
161  else
162  {
163  ROS_ERROR("Failed to call service");
164  }
165 }
166 
168 {
169  vpHomogeneousMatrix eMc;
170  vpThetaUVector erc;
171  ROS_INFO("3) TOPIC STREAM:");
173  {
174  ROS_INFO_STREAM("hand_camera: " << std::endl << emc_comm.response.effector_camera);
175  }
176  else
177  {
178  ROS_ERROR("Failed to call service");
179  }
180 
181 }
182 }
183 
184 /*
185  * Local variables:
186  * c-basic-offset: 2
187  * End:
188  */
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
std::string camera_object_topic
void publish(const boost::shared_ptr< M > &message) const
ros::ServiceClient reset_service_
Definition: client.h:64
bool sleep() const
visp_hand2eye_calibration::compute_effector_camera_quick emc_quick_comm
Definition: client.h:70
bool call(MReq &req, MRes &res)
std::string compute_effector_camera_service
ros::ServiceClient compute_effector_camera_quick_service_
Definition: client.h:66
std::string world_effector_topic
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::ServiceClient compute_effector_camera_service_
Definition: client.h:65
geometry_msgs::Transform toGeometryMsgsTransform(const vpHomogeneousMatrix &mat)
#define ROS_INFO_STREAM(args)
Client node calling a quick compute service, a compute service and 2 publishing to world_effector_top...
visp_hand2eye_calibration::reset reset_comm
Definition: client.h:68
ros::Publisher world_effector_publisher_
Definition: client.h:63
std::string compute_effector_camera_quick_service
#define ROS_ERROR(...)
visp_hand2eye_calibration::compute_effector_camera emc_comm
Definition: client.h:69
ros::Publisher camera_object_publisher_
Definition: client.h:62


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