MILDRobotModelWithExactIK.cpp
Go to the documentation of this file.
1 
20 #include <glpk.h>
21 #include <limits>
22 #include <ros/ros.h>
23 #include <ros/node_handle.h>
24 
31 
32 #include "nav_msgs/GetPlan.h"
33 #include "geometry_msgs/PoseStamped.h"
34 #include "geometry_msgs/Point.h"
35 
36 #include "urdf/model.h"
37 #include "urdf_model/joint.h"
38 #include <tf/tf.h>
39 #include <tf_conversions/tf_eigen.h>
40 #include <tf/transform_datatypes.h>
41 #include <tf_conversions/tf_eigen.h>
42 //#include <robot_state_publisher/robot_state_publisher.h>
43 #include <kdl_parser/kdl_parser.hpp>
44 #include <kdl/chain.hpp>
45 #include <kdl/chainfksolver.hpp>
46 #include <kdl/chainfksolverpos_recursive.hpp>
47 #include <tf_conversions/tf_eigen.h>
48 
49 #include <locale>
50 
51 #include <visualization_msgs/Marker.h>
52 
53 namespace robot_model_services {
56 
57  mDebugHelperPtr->write(std::stringstream() << "STARTING MILD ROBOT MODEL WITH EXACT IK", DebugHelper::ROBOT_MODEL);
58 
59  navigationCostClient = n.serviceClient<nav_msgs::GetPlan>("/move_base/make_plan");
60  double inverseKinematicIterationAccuracy_, ncp_, fcp_;
61  int panAngleSamplingStepsPerIteration_;
62  bool visualizeIK_;
63  std::string IKAngleRating_;
64  n.getParam("panAngleSamplingStepsPerIteration", panAngleSamplingStepsPerIteration_);
65  n.getParam("inverseKinematicIterationAccuracy", inverseKinematicIterationAccuracy_);
66  n.getParam("visualizeIK", visualizeIK_);
67  n.getParam("ncp", ncp_);
68  n.getParam("fcp", fcp_);
69  if (visualizeIK_)
70  {
71  mDebugHelperPtr->write("IK Visualization ENABLED", DebugHelper::PARAMETERS);
72  }
73  else
74  {
75  mDebugHelperPtr->write("IK Visualization DISABLED", DebugHelper::PARAMETERS);
76  }
77  mPanAngleSamplingStepsPerIteration = panAngleSamplingStepsPerIteration_;
78  mViewPointDistance = (ncp_ + fcp_)/2.0;
79  mInverseKinematicIterationAccuracy = inverseKinematicIterationAccuracy_;
80  mVisualizeIK = visualizeIK_;
81  mDebugHelperPtr->write(std::stringstream() << "mPanAngleSamplingStepsPerIteration: " << mPanAngleSamplingStepsPerIteration, DebugHelper::PARAMETERS);
82  mDebugHelperPtr->write(std::stringstream() << "mInverseKinematicIterationAccuracy: " << mInverseKinematicIterationAccuracy, DebugHelper::PARAMETERS);
83  mDebugHelperPtr->write(std::stringstream() << "mViewPointDistance: " << mViewPointDistance, DebugHelper::PARAMETERS);
84  //Temporary Visualization Publisher
85  std::string IKVisualization;
86  n.getParam("IKVisualization", IKVisualization);
87  vis_pub = n.advertise<visualization_msgs::Marker>(IKVisualization, 1000);
89  n.getParam("IKAngleRating", IKAngleRating_);
90  //IKAngleRating_ = std::toupper(IKAngleRating_);
91  if (IKAngleRating_ == "ANGLE_APPROXIMATION")
92  {
94  mDebugHelperPtr->write(std::stringstream() << "Using AngleApproximation as IK angle rating algorithm", DebugHelper::PARAMETERS);
95  }
96  else if (IKAngleRating_ == "NAVIGATION_PATH")
97  {
99  mDebugHelperPtr->write(std::stringstream() << "Using NavigationPath as IK angle rating algorithm", DebugHelper::PARAMETERS);
100  }
101  else if (IKAngleRating_ == "SIMPLE")
102  {
104  mDebugHelperPtr->write(std::stringstream() << "Using SimpleIKRating as IK angle rating algorithm", DebugHelper::PARAMETERS);
105  }
106  else
107  {
109  ROS_WARN_STREAM("'" << IKAngleRating_ << "' is not a valid IK rating algorithm! Using the SimpleIKRating algorithm instead.");
110  }
111  mNumberIKCalls = 0;
112  mnTotalIKTime = 0.0;
114  }
115 
117 
118  void MILDRobotModelWithExactIK::setViewPointDistance(float viewPointDistance) {
119  this->mViewPointDistance = viewPointDistance;
120  mDebugHelperPtr->write(std::stringstream() << "viewPointDistance set to: " << viewPointDistance, DebugHelper::PARAMETERS);
121 
122  }
123 
124 
126  {
127  MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
128  //Make sure the necessary geometry parameters are initialized
129  mDebugHelperPtr->writeNoticeably("STARTING CALCULATE-CAMERA-POSE-CORRECTION METHOD", DebugHelper::ROBOT_MODEL);
131  {
134  {
135  ROS_ERROR_STREAM("Could not extract parameters from tf.");
136  mDebugHelperPtr->writeNoticeably("ENDING CALCULATE-CAMERA-POSE-CORRECTION METHOD", DebugHelper::ROBOT_MODEL);
137  return PTUConfig(0.0,0.0);
138  }
139  }
140  Eigen::Vector3d basePosition(sourceMILDRobotState->x, sourceMILDRobotState->y, 0.0);
141  //Calculate pose of the pan joint
142  Eigen::Affine3d basePoseEigen = Eigen::Translation3d(basePosition) * Eigen::AngleAxisd((double)(sourceMILDRobotState->rotation), Eigen::Vector3d::UnitZ());
143  Eigen::Affine3d panJointEigen = basePoseEigen * baseToPanEigen;
144  //Calculate the target center point
145  Eigen::Quaterniond targetOrientation(orientation.w(), orientation.x(), orientation.y(), orientation.z());
146  Eigen::Vector3d targetViewVector = targetOrientation.toRotationMatrix() * Eigen::Vector3d::UnitX();
147  Eigen::Vector3d target_view_center_point = Eigen::Vector3d(position[0], position[1], position[2]) + targetViewVector*mViewPointDistance;
148  //Visualize target view
149  if (vis_pub.getNumSubscribers() > 0)
150  {
151  Eigen::Vector3d target_cam_point(position[0], position[1], position[2]);
152  visualizeIKCameraTarget(target_view_center_point, target_cam_point);
153  }
154  //Calculate PAN
155  Eigen::Vector3d panJointToCenterPointProjected(target_view_center_point[0] - panJointEigen(0,3), target_view_center_point[1] - panJointEigen(1,3), 0.0);
156  double viewTriangleXYPlane_sideA = panJointToCenterPointProjected.norm();
157  double viewTriangleXYPlane_sideB = sqrt(pow(viewTriangleXYPlane_sideA, 2.0) - pow(viewTriangleXYPlane_sideC, 2.0));
158  double viewTriangleXYPlane_AngleBeta = pow(viewTriangleXYPlane_sideA, 2.0) + pow(viewTriangleXYPlane_sideC, 2.0) - pow(viewTriangleXYPlane_sideB, 2.0);
159  viewTriangleXYPlane_AngleBeta = viewTriangleXYPlane_AngleBeta/(2.0*viewTriangleXYPlane_sideA*viewTriangleXYPlane_sideC);
160  viewTriangleXYPlane_AngleBeta = acos(viewTriangleXYPlane_AngleBeta);
161  Eigen::Vector3d panJointXAxis(panJointEigen(0,0), panJointEigen(1,0), panJointEigen(2,0));
162  Eigen::Vector3d panJointYAxis(panJointEigen(0,1), panJointEigen(1,1), panJointEigen(2,1));
163  panJointXAxis.normalize();
164  panJointYAxis.normalize();
165  panJointToCenterPointProjected.normalize();
166  double panAngle = viewTriangleXYPlane_AngleBeta - (M_PI/2.0 - asin(panJointToCenterPointProjected.dot(panJointYAxis)));
167  if(panJointToCenterPointProjected.dot(panJointXAxis) < 0) panAngle = M_PI - panAngle; //If target is behind the robot, correct angle
168  mDebugHelperPtr->write(std::stringstream() << "viewTriangleXYPlane_sideA: " << viewTriangleXYPlane_sideA, DebugHelper::ROBOT_MODEL);
169  mDebugHelperPtr->write(std::stringstream() << "viewTriangleXYPlane_sideB: " << viewTriangleXYPlane_sideB, DebugHelper::ROBOT_MODEL);
170  mDebugHelperPtr->write(std::stringstream() << "viewTriangleXYPlane_sideC: " << viewTriangleXYPlane_sideC, DebugHelper::ROBOT_MODEL);
171  mDebugHelperPtr->write(std::stringstream() << "viewTriangleXYPlane_AngleBeta: " << viewTriangleXYPlane_AngleBeta, DebugHelper::ROBOT_MODEL);
172  mDebugHelperPtr->write(std::stringstream() << "asin(panJointToCenterPointProjected.dot(panJointYAxis)): " << asin(panJointToCenterPointProjected.dot(panJointYAxis)),
174  mDebugHelperPtr->write(std::stringstream() << "mPanAngleOffset: " << mPanAngleOffset, DebugHelper::ROBOT_MODEL);
175  mDebugHelperPtr->write(std::stringstream() << "panJointToCenterPointProjected.dot(panJointXAxis): " << panJointToCenterPointProjected.dot(panJointXAxis),
177  //Calculate TILT
178  Eigen::Affine3d panJointRotatedEigen = panJointEigen * Eigen::AngleAxisd(panAngle, Eigen::Vector3d::UnitZ());
179  Eigen::Affine3d tiltJointEigen = panJointRotatedEigen * panToTiltEigen;
180  Eigen::Vector3d tiltJointToViewCenter = target_view_center_point - Eigen::Vector3d(tiltJointEigen(0,3), tiltJointEigen(1,3), tiltJointEigen(2,3));
181  Eigen::Vector3d tiltJointYAxis(tiltJointEigen(0,1), tiltJointEigen(1,1), tiltJointEigen(2,1));
182  tiltJointYAxis.normalize();
183  Eigen::Vector3d tiltJointToViewCenterProjected = tiltJointToViewCenter - tiltJointYAxis.dot(tiltJointToViewCenter) * tiltJointYAxis;
184  double viewTriangleZPlane_sideA = tiltJointToViewCenterProjected.norm();
186  double viewTriangleZPlane_sideC = - bTimesCos/2.0 + sqrt(pow(bTimesCos,2.0)/4.0-pow(viewTriangleZPlane_sideB,2.0)+pow(viewTriangleZPlane_sideA,2.0));
187 
188  mDebugHelperPtr->write(std::stringstream() << "viewTriangleZPlane_sideA: " << viewTriangleZPlane_sideA, DebugHelper::ROBOT_MODEL);
189  mDebugHelperPtr->write(std::stringstream() << "viewTriangleZPlane_sideB: " << viewTriangleZPlane_sideB, DebugHelper::ROBOT_MODEL);
190  mDebugHelperPtr->write(std::stringstream() << "viewTriangleZPlane_sideC: " << viewTriangleZPlane_sideC, DebugHelper::ROBOT_MODEL);
191 
192  double viewTriangleZPlane_angleGamma = pow(viewTriangleZPlane_sideB, 2.0) + pow(viewTriangleZPlane_sideA, 2.0) - pow(viewTriangleZPlane_sideC, 2.0);
193  viewTriangleZPlane_angleGamma = acos(viewTriangleZPlane_angleGamma / (2.0*viewTriangleZPlane_sideB*viewTriangleZPlane_sideA));
194  double tiltAngle = viewTriangleZPlane_angleGamma - acos(tiltJointToViewCenter[2]/tiltJointToViewCenter.norm());
195 
196  //Check angle angle constrains and truncate values if neccessaire
197  double tiltMin = mTiltLimits.get<0>();
198  double tiltMax = mTiltLimits.get<1>();
199  if (tiltAngle < tiltMin)
200  {
201  if (tiltAngle < tiltMin - 10.0) {
202  ROS_WARN_STREAM("Calculated Tilt-Angle was too small: " << tiltAngle*(180.0/M_PI));
203  } else {
204  mDebugHelperPtr->write(std::stringstream() << "Calculated Tilt-Angle was too small: " << tiltAngle*(180.0/M_PI), DebugHelper::ROBOT_MODEL);
205  }
206  tiltAngle = tiltMin;
207  }
208  if (tiltAngle > tiltMax)
209  {
210  if (tiltAngle > tiltMax + 10.0) {
211  ROS_WARN_STREAM("Calculated Tilt-Angle was too high: " << tiltAngle*(180.0/M_PI));
212  } else {
213  mDebugHelperPtr->write(std::stringstream() << "Calculated Tilt-Angle was too high: " << tiltAngle*(180.0/M_PI), DebugHelper::ROBOT_MODEL);
214  }
215  tiltAngle = tiltMax;
216  }
217 
218  double panMin = mPanLimits.get<0>();
219  double panMax = mPanLimits.get<1>();
220  if (panAngle < panMin)
221  {
222  if (panAngle < panMin - 10.0) {
223  ROS_WARN_STREAM("Calculated Pan-Angle was too small: " << panAngle*(180.0/M_PI));
224  } else {
225  mDebugHelperPtr->write(std::stringstream() << "Calculated Pan-Angle was too small: " << panAngle*(180.0/M_PI), DebugHelper::ROBOT_MODEL);
226  }
227  panAngle = panMin;
228  }
229  if (panAngle > panMax)
230  {
231  if (panAngle > panMax + 10.0) {
232  ROS_WARN_STREAM("Calculated Pan-Angle was too high: " << panAngle*(180.0/M_PI));
233  } else {
234  mDebugHelperPtr->write(std::stringstream() << "Calculated Pan-Angle was too high: " << panAngle*(180.0/M_PI), DebugHelper::ROBOT_MODEL);
235  }
236  panAngle = panMax;
237  }
238 
239  //visualize current robot configuration and corrected view target
240  if (vis_pub.getNumSubscribers() > 0)
241  {
242  Eigen::Vector3d baseOrientation(basePoseEigen(0,0), basePoseEigen(1,0), basePoseEigen(2,0));
243  Eigen::Vector3d pan_base_point(panJointEigen(0,3), panJointEigen(1,3), panJointEigen(2,3));
244  Eigen::Vector3d pan_rotated_point(panJointRotatedEigen(0,3), panJointRotatedEigen(1,3), panJointRotatedEigen(2,3));
245  Eigen::Vector3d tilt_base_point(tiltJointEigen(0,3), tiltJointEigen(1,3), tiltJointEigen(2,3));
246  Eigen::Affine3d camFrame = tiltJointEigen * Eigen::AngleAxisd(-tiltAngle, Eigen::Vector3d::UnitY()) * tiltToCameraEigen;
247  Eigen::Vector3d cam_point(camFrame(0,3), camFrame(1,3), camFrame(2,3));
248  Eigen::Affine3d actualViewCenterEigen = camFrame * Eigen::Translation3d(Eigen::Vector3d(0.0, 0.0, viewTriangleZPlane_sideA));
249  Eigen::Vector3d actual_view_center_point(actualViewCenterEigen(0,3), actualViewCenterEigen(1,3), actualViewCenterEigen(2,3));
250  visualizeCameraPoseCorrection(basePosition, baseOrientation, pan_base_point, pan_rotated_point, tilt_base_point,cam_point, actual_view_center_point);
251  }
252 
253  mDebugHelperPtr->writeNoticeably("ENDING CALCULATE-CAMERA-POSE-CORRECTION METHOD", DebugHelper::ROBOT_MODEL);
254  return PTUConfig(panAngle,tiltAngle);
255  }
256 
257 
258  //Solves the inverse kinematical problem for an given robot state and a pose for the camera
260  {
261  mDebugHelperPtr->writeNoticeably("STARTING CALCULATE-ROBOT-STATE METHOD", DebugHelper::ROBOT_MODEL);
262  std::clock_t begin = std::clock();
263 
264  MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
265  MILDRobotStatePtr targetMILDRobotState(new MILDRobotState());
266  targetMILDRobotState->pan = 0;
267  targetMILDRobotState->tilt = 0;
268  targetMILDRobotState->rotation = 0;
269  targetMILDRobotState->x = 0;
270  targetMILDRobotState->y = 0;
271 
272  double tiltMin = mTiltLimits.get<0>();
273  double tiltMax = mTiltLimits.get<1>();
274 
276 
277  //Make sure the necessary geometry parameters are initialized
279  {
282  {
283  ROS_ERROR_STREAM("Could not extract parameters from tf.");
284  mDebugHelperPtr->writeNoticeably("ENDING CALCULATE-ROBOT-STATE METHOD", DebugHelper::ROBOT_MODEL);
285  return targetMILDRobotState;
286  }
287  }
288  Eigen::Quaterniond targetOrientation(orientation.w(), orientation.x(), orientation.y(), orientation.z());
289  Eigen::Vector3d targetViewVector = targetOrientation.toRotationMatrix() * Eigen::Vector3d::UnitX();
290 
291  //The plane normal is now defined as the negative cross product of the camera view vector and the z axis.
292  //Any rotation around the view axis will be ignored to ensure that the resulting target camera pose is valid
293  Eigen::Vector3d planeNormal = -targetViewVector.cross(Eigen::Vector3d::UnitZ());
294  planeNormal.normalize(); targetViewVector.normalize();
295 
296  mDebugHelperPtr->write(std::stringstream() << "Source state: (Pan: " << sourceMILDRobotState->pan
297  << ", Tilt: " << sourceMILDRobotState->tilt
298  << ", Rotation " << sourceMILDRobotState->rotation
299  << ", X:" << sourceMILDRobotState->x
300  << ", Y:" << sourceMILDRobotState->y << ")",
302  mDebugHelperPtr->write(std::stringstream() << "Target Position: " << position[0] << ", " << position[1] << ", " << position[2],
304  mDebugHelperPtr->write(std::stringstream() << "Target Orientation: " << targetOrientation.w() << ", " << targetOrientation.x() << ", " << targetOrientation.y()<< ", " << targetOrientation.z(),
306  //Visualize target camera pose & target viewcenter
307  Eigen::Vector3d target_view_center_point = Eigen::Vector3d(position[0], position[1], position[2]) + targetViewVector*mViewPointDistance;
308 
310  {
311  mDebugHelperPtr->write(std::stringstream() << "Publishing Camera Target from (" << position[0] << ", " << position[1] << ", " << position[2] << ") to (" << target_view_center_point[0] << ", " << target_view_center_point[1] << ", " << target_view_center_point[2] << ")", DebugHelper::ROBOT_MODEL);
312  Eigen::Vector3d target_cam_point(position[0], position[1], position[2]);
313  visualizeIKCameraTarget(target_view_center_point, target_cam_point);
314  }
315 
316  //Calculate TILT and position of Tilt joint
317  double tilt; Eigen::Vector3d tilt_base_point_projected;
318  if (!getTiltAngleAndTiltBasePointProjected(planeNormal, targetViewVector, target_view_center_point, tilt, tilt_base_point_projected))
319  {
320  ROS_ERROR_STREAM("No solution found for center point (" << position[0] << ", " << position[1] << ", " << position[2] << ")");
321  mDebugHelperPtr->writeNoticeably("ENDING CALCULATE-ROBOT-STATE METHOD", DebugHelper::ROBOT_MODEL);
322  return targetMILDRobotState;
323  }
324  mDebugHelperPtr->write(std::stringstream() << "tilt_base_point_projected: " << tilt_base_point_projected[0] << ", " << tilt_base_point_projected[1] << ", " << tilt_base_point_projected[2],
326  if (tilt < tiltMin)
327  {
328  if (tilt < tiltMin - 10.0) {
329  ROS_WARN_STREAM("Calculated Tilt-Angle was too small: " << tilt*(180.0/M_PI));
330  } else {
331  mDebugHelperPtr->write(std::stringstream() << "Calculated Tilt-Angle was too small: " << tilt*(180.0/M_PI), DebugHelper::ROBOT_MODEL);
332  }
333  tilt = tiltMin;
334  }
335  if (tilt > tiltMax)
336  {
337  if (tilt > tiltMax + 10.0) {
338  ROS_WARN_STREAM("Calculated Tilt-Angle was too high: " << tilt*(180.0/M_PI));
339  } else {
340  mDebugHelperPtr->write(std::stringstream() << "Calculated Tilt-Angle was too high: " << tilt*(180.0/M_PI), DebugHelper::ROBOT_MODEL);
341  }
342  tilt = tiltMax;
343  }
344  mDebugHelperPtr->write(std::stringstream() << "Tilt: " << tilt*(180.0/M_PI) << " deg",
346 
347  Eigen::Vector3d tilt_base_point = tilt_base_point_projected + x_product*planeNormal;
348  mDebugHelperPtr->write(std::stringstream() << "tilt_base_point: " << tilt_base_point[0] << ", " << tilt_base_point[1] << ", " << tilt_base_point[2],
350 
351  // Get pose of PAN joint
352  Eigen::Affine3d tiltFrame = getTiltJointFrame(planeNormal, targetViewVector, tilt_base_point);
353  Eigen::Affine3d tiltedFrame = tiltFrame * Eigen::AngleAxisd(-tilt, Eigen::Vector3d::UnitY());
354  Eigen::Affine3d camFrame = tiltedFrame * tiltToCameraEigen;
355  Eigen::Affine3d actualViewCenterEigen(Eigen::Translation3d(Eigen::Vector3d(0.0, 0.0, mViewPointDistance)));
356  actualViewCenterEigen = camFrame*actualViewCenterEigen;
357 
358  Eigen::Affine3d pan_rotated_Frame = tiltFrame * tiltToPanEigen;
359 
360  //Calculate PAN and base rotation
361  double pan = this->getPanAngleFromPanJointPose(pan_rotated_Frame, sourceMILDRobotState);
362  mDebugHelperPtr->write(std::stringstream() << "Pan: " << pan*(180.0/M_PI) << " deg", DebugHelper::ROBOT_MODEL);
363 
364  Eigen::Affine3d pan_Frame = pan_rotated_Frame * Eigen::AngleAxisd(pan, Eigen::Vector3d::UnitZ());
365  Eigen::Affine3d base_Frame = pan_Frame * panToBaseEigen;
366 
367  //Visualization
368  if (mVisualizeIK) // && vis_pub.getNumSubscribers() > 0)
369  {
370  Eigen::Vector3d base_point(base_Frame(0,3), base_Frame(1,3), base_Frame(2,3));
371  Eigen::Vector3d pan_base_point(pan_Frame(0,3), pan_Frame(1,3), pan_Frame(2,3));
372  Eigen::Vector3d pan_rotated_point(pan_rotated_Frame(0,3), pan_rotated_Frame(1,3), pan_rotated_Frame(2,3));
373  Eigen::Vector3d cam_point(camFrame(0,3), camFrame(1,3), camFrame(2,3));
374  Eigen::Vector3d actual_view_center_point(actualViewCenterEigen(0,3), actualViewCenterEigen(1,3), actualViewCenterEigen(2,3));
375  Eigen::Vector3d base_orientation(base_Frame(0,0), base_Frame(1,0), base_Frame(2,0));
376  visualizeIKcalculation(base_point, base_orientation, pan_base_point, pan_rotated_point, tilt_base_point,tilt_base_point_projected, cam_point, actual_view_center_point);
377  }
378 
379  // Set output values
380  // set pan
381  targetMILDRobotState->pan = pan;
382 
383  // set rotation
384  targetMILDRobotState->rotation = this->getBaseAngleFromBaseFrame(base_Frame);
385  while (targetMILDRobotState->rotation < 0) { targetMILDRobotState->rotation += 2 * M_PI; };
386  while (targetMILDRobotState->rotation > 2 * M_PI) { targetMILDRobotState->rotation -= 2 * M_PI; };
387 
388  // set tilt
389  targetMILDRobotState->tilt = tilt;
390 
391  // set x, y
392  targetMILDRobotState->x = base_Frame(0,3);
393  targetMILDRobotState->y = base_Frame(1,3);
394  mDebugHelperPtr->write(std::stringstream() << "Target state: (Pan: " << targetMILDRobotState->pan << " rad"
395  << ", Tilt: " << targetMILDRobotState->tilt << " rad"
396  << ", Rotation " << targetMILDRobotState->rotation << " rad"
397  << ", X: " << targetMILDRobotState->x << " m"
398  << ", Y: " << targetMILDRobotState->y << " m)",
400 
401 
402  std::clock_t end = std::clock();
403  double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
404  mNumberIKCalls++;
405  mnTotalIKTime += elapsed_secs;
406  mDebugHelperPtr->write(std::stringstream() << "IK Calculation took " << elapsed_secs << " seconds. Total calculation time: "
407  << mnTotalIKTime << " over " << mNumberIKCalls << " calculations.",
409 
410  mDebugHelperPtr->writeNoticeably("ENDING CALCULATE-ROBOT-STATE METHOD", DebugHelper::ROBOT_MODEL);
411  return targetMILDRobotState;
412  }
413 
414  Eigen::Affine3d MILDRobotModelWithExactIK::getTiltJointFrame(Eigen::Vector3d &planeNormal, Eigen::Vector3d &targetViewVector, Eigen::Vector3d &tilt_base_point)
415  {
416  Eigen::Vector3d viewDirection;
417  viewDirection = targetViewVector;
418  viewDirection[2] = 0.0;
419  viewDirection.normalize();
420  Eigen::Matrix4d tiltFrame_Rotation;
421  tiltFrame_Rotation.col(0) << viewDirection[0], viewDirection[1], 0.0 , 0.0;
422  tiltFrame_Rotation.col(1) << -planeNormal[0] , -planeNormal[1] , -planeNormal[2] ,0.0;
423  tiltFrame_Rotation.col(2) << 0.0, 0.0, 1.0, 0.0;
424  tiltFrame_Rotation.col(3) << tilt_base_point[0] , tilt_base_point[1] , tilt_base_point[2] , 1.0;
425 
426  Eigen::Affine3d tiltFrame(tiltFrame_Rotation);
427  return tiltFrame;
428  }
429 
430  bool MILDRobotModelWithExactIK::getTiltAngleAndTiltBasePointProjected(Eigen::Vector3d &planeNormal, Eigen::Vector3d &targetViewVector, Eigen::Vector3d &target_view_center_point, double &tilt, Eigen::Vector3d &tilt_base_point_projected)
431  {
432  //Calculate tilt base point (t1, t2, t3)
433  double t1, t2, t3;
434  //Calculate t3 using h
435  t3 = h_tilt - target_view_center_point[2];
436  //Calculate t2 using abc-formula
437  double a, b, c;
438  double planeNormalX = planeNormal.x();
439 
440  // in case planeNormalX is zero, calculation can be done in an easier way
441  if (fabs(planeNormalX) < 10e-7)
442  {
443  mDebugHelperPtr->write(std::stringstream() << "PlaneNormalX is zero", DebugHelper::ROBOT_MODEL);
444  //Note: I will assume here, that x and y cannot both be zero, since the plane normal has to lie in the XY-plane
445  t2 = -(t3*planeNormal[2])/planeNormal[1];
446  t1 = pow(viewTriangleZPlane_sideA, 2.0) - pow(t2, 2.0) - pow(t3, 2.0);
447  // if t1 < 0, so solution can be found
448  if (t1 < 0)
449  {
450  return false;
451  }
452  t1 = sqrt(t1);
453 
454  //Note: The equation solved above has a positive and negative solution. The correct one is whichever points in the same direction as the targetViewvector
455  if (targetViewVector[0]*t1+targetViewVector[1]*t2 > 0)
456  {
457  //-> Flip sign if needed
458  t1 *= -1.0;
459  }
460  }
461  else // in any other case, a quadratic equation needs to be solved for t2 and t1 will be derived from the result
462  {
463  mDebugHelperPtr->write(std::stringstream() << "planNormalX NOT equal 0", DebugHelper::ROBOT_MODEL);
464  a = 1 + pow(planeNormal(1)/planeNormalX, 2.0);
465  b = (2*t3*planeNormal(1)*planeNormal(2))/pow(planeNormalX, 2.0);
466  c = -pow(viewTriangleZPlane_sideA, 2.0) + pow(t3, 2.0)*(1+pow(planeNormal(2)/planeNormalX, 2.0));
467  if (pow(b, 2.0)<4*a*c)
468  {
469  return false;
470  }
471 
472  double t2_1, t2_2, t1_1, t1_2;
473  t2_1 = (-b + sqrt(pow(b, 2.0)-4*a*c))/(2*a);
474  t2_2 = (-b - sqrt(pow(b, 2.0)-4*a*c))/(2*a);
475  //Calculate feasible t1
476  t1_1 = -(t2_1*planeNormal(1)+t3*planeNormal(2))/planeNormalX;
477  t1_2 = -(t2_2*planeNormal(1)+t3*planeNormal(2))/planeNormalX;
478  //Choose t1, t2
479  if (targetViewVector[0]*t1_1+targetViewVector[1]*t2_1 < 0)
480  {
481  t1 = t1_1;
482  t2 = t2_1;
483  }
484  else
485  {
486  t1 = t1_2;
487  t2 = t2_2;
488  }
489  }
490 
491  //get projected tilt base point
492  tilt_base_point_projected = Eigen::Vector3d(t1+target_view_center_point[0], t2+target_view_center_point[1], t3+target_view_center_point[2]);
493  //get tilt angle
494  Eigen::Vector3d targetToBase(tilt_base_point_projected[0]-target_view_center_point[0], tilt_base_point_projected[1]-target_view_center_point[1], tilt_base_point_projected[2]-target_view_center_point[2]);
495  targetToBase.normalize();
496  double targetToBase_Angle = acos(targetToBase[2]);
497  mDebugHelperPtr->write(std::stringstream() << "targetToBase_Angle: " << targetToBase_Angle, DebugHelper::ROBOT_MODEL);
498  tilt = targetToBase_Angle+mTiltAngleOffset;
499  return true;
500  }
501 
502 
503 
504  double MILDRobotModelWithExactIK::getPanAngleFromPanJointPose(Eigen::Affine3d &panJointFrame, MILDRobotStatePtr &robotState)
505  {
506  unsigned int iterationCount = 1;
507  double phiMin = mPanLimits.get<0>();
508  double phiMax = mPanLimits.get<1>();
509  double currentBestAngle = (phiMax-phiMin)/2.0+phiMin;
510  double currentBestRating, newBestRating = 0.0;
511  double currentAngleRange = phiMax-phiMin;
512  geometry_msgs::Point actualRobotPosition, targetRobotPosition;
513  actualRobotPosition.x = robotState->x;
514  actualRobotPosition.y = robotState->y;
515  actualRobotPosition.z = targetRobotPosition.z = 0.0;
516  Eigen::Affine3d baseFrame;
517  mDebugHelperPtr->write(std::stringstream() << "phiMin: " << phiMin << " phiMax: " << phiMax, DebugHelper::ROBOT_MODEL);
518  mDebugHelperPtr->write(std::stringstream() << "currentAngleRange: " << currentAngleRange << " currentBestAngle: " << currentBestAngle,
520  mDebugHelperPtr->write(std::stringstream() << "mPanAngleSamplingStepsPerIteration: " << mPanAngleSamplingStepsPerIteration,
522  Eigen::Vector3d basePoint, basePoint2;
523  Eigen::Vector3d baseOrientation;
524  //do sampling
525  do
526  {
527  std::ostringstream converter;
528  converter << iterationCount;
529  std::string nsIterationVector = std::string("iterationVector") + converter.str();
530  double angleStepSize = currentAngleRange / mPanAngleSamplingStepsPerIteration;
531  double currentIterationAngle, currentRating, angleCenter;
532  currentBestRating = newBestRating;
533  angleCenter = currentBestAngle;
534  newBestRating = -1.0;
535  for (unsigned int i = 0; i < mPanAngleSamplingStepsPerIteration; i++)
536  {
537  currentIterationAngle = angleCenter - currentAngleRange/2.0 + i * angleStepSize;
538  if (phiMax>currentIterationAngle && phiMin<currentIterationAngle)
539  {
540  //Calculate the base frame with respect to the current angle
541  baseFrame = panJointFrame * Eigen::AngleAxisd(-currentIterationAngle, Eigen::Vector3d::UnitZ()) * panToBaseEigen;
542  basePoint = Eigen::Vector3d(baseFrame(0,3),baseFrame(1,3),baseFrame(2,3));
543  baseOrientation = Eigen::Vector3d(baseFrame(0,0),baseFrame(1,0),baseFrame(2,0));
544  baseOrientation.normalize();
545  basePoint2 = basePoint+baseOrientation*0.15;
546  targetRobotPosition.x = baseFrame(0,3);
547  targetRobotPosition.y = baseFrame(1,3);
548  float baseAngle = getBaseAngleFromBaseFrame(baseFrame);
549  currentRating = ikRatingModule->getPanAngleRating(actualRobotPosition, targetRobotPosition, robotState->rotation, baseAngle);
550  mDebugHelperPtr->write(std::stringstream() << "PTU-Angle: " << currentIterationAngle << " with base angle: " << baseAngle << " and rating: " << currentRating,
552  if (currentRating > newBestRating)
553  {
554  newBestRating = currentRating;
555  currentBestAngle = currentIterationAngle;
556  }
558  {
559  Eigen::Vector4d color_succeeded(1.0-currentRating,currentRating, 0.0, 1.0);
560  //visualizeIKPoint(basePoint, color_succeeded, nsIterationVector, 2*i);
561  visualizeIKArrowSmall(basePoint, basePoint2, color_succeeded, nsIterationVector, 2*i+1);
562  }
563  }
564  }
565  mDebugHelperPtr->write(std::stringstream() << "Best angle: " << currentBestAngle << " with rating: " << newBestRating
566  << " and angle range " << currentAngleRange,
568  currentAngleRange = currentAngleRange / 2.0;
569  iterationCount++;
570  //Loop while there is still significant change in the angle rating and while the maximum number of iterations has not yet been reached
571  } while(fabs(currentBestRating-newBestRating) > mInverseKinematicIterationAccuracy && iterationCount <= IKVisualizationMaximunIterationCount);
572 
573  mIKVisualizationLastIterationCount = iterationCount;
574  if (currentBestRating < 0.0) {ROS_ERROR_STREAM("No valid solution found for this pan frame.");}
575  return -currentBestAngle;
576  }
577 
578 
580  {
581  //Get Parameters from TF-Publishers
582  tf::StampedTransform panToTiltTF, baseToPanTF, tiltToCamLeftTF, tiltToCamRightTF;
583  Eigen::Affine3d tiltAxisPointEigen, tiltToCamLeftEigen, tiltToCamRightEigen, cameraLeftPointEigen, cameraRightPointEigen, cameraMidPointEigen;
584  ROS_INFO_STREAM("Looking up tf transforms (" << mFrameName_map << " to " << mFrameName_mild_ptu_tilt_link_rotated << ")");
585  ros::spinOnce();
586  try
587  {
588  //Wait for first transform to be published
590  {
591  //Assume that tf is alive and lookups will be successful
596  }
597  else
598  {
599  ROS_ERROR("TF lookup timed out. Is the transformation publisher running?");
600  return false;
601  }
602  }
603  catch (tf::TransformException ex)
604  {
605  ROS_ERROR("An error occured during tf-lookup: %s",ex.what());
606  return false;
607  }
608  tf::poseTFToEigen(panToTiltTF, panToTiltEigen);
609  tf::poseTFToEigen(baseToPanTF, baseToPanEigen);
610  tf::poseTFToEigen(tiltToCamLeftTF, tiltToCamLeftEigen);
611  tf::poseTFToEigen(tiltToCamRightTF, tiltToCamRightEigen);
612 
613  tiltAxisPointEigen = baseToPanEigen * panToTiltEigen;
614  cameraLeftPointEigen = tiltAxisPointEigen * tiltToCamLeftEigen;
615  cameraRightPointEigen = tiltAxisPointEigen * tiltToCamRightEigen;
616 
617  //Hacky-ish approach to get the center point between left and right camera
618  cameraMidPointEigen = cameraLeftPointEigen;
619  cameraMidPointEigen(0,3) = (cameraLeftPointEigen(0,3) + cameraRightPointEigen(0,3)) / 2.0;
620  cameraMidPointEigen(1,3) = (cameraLeftPointEigen(1,3) + cameraRightPointEigen(1,3)) / 2.0;
621  cameraMidPointEigen(2,3) = (cameraLeftPointEigen(2,3) + cameraRightPointEigen(2,3)) / 2.0;
622  tiltToCameraEigen = tiltAxisPointEigen.inverse() * cameraMidPointEigen;
623 
624  tiltToPanEigen = panToTiltEigen.inverse();
625  panToBaseEigen = baseToPanEigen.inverse();
626  h_tilt = tiltAxisPointEigen.matrix()(2,3);
627  mDebugHelperPtr->writeNoticeably(std::stringstream() << "Height above ground: " << h_tilt, DebugHelper::ROBOT_MODEL);
628 
629  Eigen::Vector3d cam_axis_x(cameraMidPointEigen(0,0), cameraMidPointEigen(1,0), cameraMidPointEigen(2,0));
630  Eigen::Vector3d cam_axis_y(cameraMidPointEigen(0,1), cameraMidPointEigen(1,1), cameraMidPointEigen(2,1));
631  Eigen::Vector3d cam_axis_z(cameraMidPointEigen(0,2), cameraMidPointEigen(1,2), cameraMidPointEigen(2,2));
632  cam_axis_x.normalize();
633  cam_axis_y.normalize();
634  cam_axis_z.normalize();
635  Eigen::Vector3d tilt_to_cam(tiltAxisPointEigen(0,3)-cameraMidPointEigen(0,3), tiltAxisPointEigen(1,3)-cameraMidPointEigen(1,3), tiltAxisPointEigen(2,3)-cameraMidPointEigen(2,3));
636  x_product = cam_axis_x.dot(tilt_to_cam);
637  tilt_to_cam -= x_product*cam_axis_x;
638  viewTriangleZPlane_sideB = tilt_to_cam.norm();
639  tilt_to_cam.normalize();
640  viewTriangleZPlane_angleAlpha = acos(cam_axis_z.dot(tilt_to_cam));
642  viewTriangleZPlane_angleGamma = pow(mViewPointDistance, 2.0) - pow(viewTriangleZPlane_sideA,2.0)-pow(viewTriangleZPlane_sideB,2.0);
646  //Calculate additional values for the camera pose correction
647  Eigen::Affine3d panToCameraEigen = panToTiltEigen * tiltToCameraEigen;
648  Eigen::Vector3d cam_axis_x_pan_coordinates(panToCameraEigen(0,2), panToCameraEigen(1,2), panToCameraEigen(2,2));
649  Eigen::Vector3d cam_axis_z_pan_coordinates(panToCameraEigen(0,1), panToCameraEigen(1,1), panToCameraEigen(2,1));
650  cam_axis_x_pan_coordinates.normalize();
651  cam_axis_z_pan_coordinates.normalize();
652  Eigen::Vector3d panToCameraNormal(panToCameraEigen(0,3), panToCameraEigen(1,3), panToCameraEigen(2,3));
653  panToCameraNormal = panToCameraNormal - cam_axis_x_pan_coordinates * panToCameraNormal.dot(cam_axis_x_pan_coordinates) - cam_axis_z_pan_coordinates * panToCameraNormal.dot(cam_axis_z_pan_coordinates);
654  viewTriangleXYPlane_sideC = panToCameraNormal.norm();
655  panToCameraNormal.normalize();
656  mPanAngleOffset = acos(panToCameraNormal.dot(Eigen::Vector3d::UnitX()));
657 
658  mDebugHelperPtr->writeNoticeably(std::stringstream() << "viewTriangleZPlane_angleAlpha: " << viewTriangleZPlane_angleAlpha, DebugHelper::ROBOT_MODEL);
659  mDebugHelperPtr->writeNoticeably(std::stringstream() << "viewTriangleZPlane_angleGamma: " << viewTriangleZPlane_angleGamma, DebugHelper::ROBOT_MODEL);
660  mDebugHelperPtr->writeNoticeably(std::stringstream() << "viewTriangleZPlane_sideA: " << viewTriangleZPlane_sideA, DebugHelper::ROBOT_MODEL);
661  mDebugHelperPtr->writeNoticeably(std::stringstream() << "viewTriangleZPlane_sideB: " << viewTriangleZPlane_sideB, DebugHelper::ROBOT_MODEL);
662  mDebugHelperPtr->writeNoticeably(std::stringstream() << "viewTriangleXYPlane_sideC: " << viewTriangleXYPlane_sideC, DebugHelper::ROBOT_MODEL);
663  mDebugHelperPtr->writeNoticeably(std::stringstream() << "mTiltAngleOffset: " << mTiltAngleOffset, DebugHelper::ROBOT_MODEL);
664  mDebugHelperPtr->writeNoticeably(std::stringstream() << "mPanAngleOffset: " << mPanAngleOffset, DebugHelper::ROBOT_MODEL);
665 
666  ROS_INFO_STREAM("TF lookup successful.");
667 
668  return true;
669  }
670 
672  {
673  //NOTE: This method should basically just delete all previously created markers.
674  //Since the DELETEALL option is not working under ROS indigo, I tried to delete each marker individually by using the DELETE method
675  //This should be changed to a clean solution once the required options in ROS are working again
676  visualization_msgs::Marker resetMarker = visualization_msgs::Marker();
677  resetMarker.id = 0;
678  resetMarker.header.frame_id = mFrameName_map;
679  resetMarker.action = visualization_msgs::Marker::DELETE;
680  resetMarker.lifetime = ros::Duration();
681  resetMarker.scale.x = 0.02;
682  resetMarker.scale.y = 0.02;
683  resetMarker.scale.z = 0.02;
684  resetMarker.color.a = 0.0;
685 
686  //Reset camToActualViewCenterVector
687  resetMarker.header.stamp = ros::Time::now();
688  resetMarker.type = visualization_msgs::Marker::ARROW;
689  resetMarker.ns = "camToActualViewCenterVector";
690  vis_pub.publish(resetMarker);
691  ros::spinOnce();
692  //Reset tiltToCamVector
693  resetMarker.header.stamp = ros::Time::now();
694  resetMarker.type = visualization_msgs::Marker::ARROW;
695  resetMarker.ns = "tiltToCamVector";
696  vis_pub.publish(resetMarker);
697  ros::spinOnce();
698  //Reset tiltBaseVectorProjected
699  resetMarker.header.stamp = ros::Time::now();
700  resetMarker.type = visualization_msgs::Marker::SPHERE;
701  resetMarker.ns = "tiltBaseVectorProjected";
702  vis_pub.publish(resetMarker);
703  ros::spinOnce();
704  //Reset tiltBaseVector
705  resetMarker.header.stamp = ros::Time::now();
706  resetMarker.type = visualization_msgs::Marker::SPHERE;
707  resetMarker.ns = "tiltBaseVector";
708  vis_pub.publish(resetMarker);
709  ros::spinOnce();
710  //Reset panToTiltVector
711  resetMarker.header.stamp = ros::Time::now();
712  resetMarker.type = visualization_msgs::Marker::ARROW;
713  resetMarker.ns = "panToTiltVector";
714  vis_pub.publish(resetMarker);
715  ros::spinOnce();
716  //Reset panBaseVector
717  resetMarker.header.stamp = ros::Time::now();
718  resetMarker.type = visualization_msgs::Marker::SPHERE;
719  resetMarker.ns = "panBaseVector";
720  vis_pub.publish(resetMarker);
721  ros::spinOnce();
722  //Reset baseToPanVector
723  resetMarker.header.stamp = ros::Time::now();
724  resetMarker.type = visualization_msgs::Marker::ARROW;
725  resetMarker.ns = "baseToPanVector";
726  vis_pub.publish(resetMarker);
727  ros::spinOnce();
728  //Reset targetCameraVector
729  resetMarker.header.stamp = ros::Time::now();
730  resetMarker.type = visualization_msgs::Marker::ARROW;
731  resetMarker.ns = "targetCameraVector";
732  vis_pub.publish(resetMarker);
733  ros::spinOnce();
734  //Reset basePose
735  resetMarker.header.stamp = ros::Time::now();
736  resetMarker.type = visualization_msgs::Marker::SPHERE;
737  resetMarker.ns = "basePose";
738  vis_pub.publish(resetMarker);
739  ros::spinOnce();
740  resetMarker.type = visualization_msgs::Marker::ARROW;
741  resetMarker.header.stamp = ros::Time::now();
742  resetMarker.id = 1;
743  vis_pub.publish(resetMarker);
744  ros::spinOnce();
745  mDebugHelperPtr->writeNoticeably(std::stringstream() << "Deleting markers for " << mIKVisualizationLastIterationCount << " iterations", DebugHelper::ROBOT_MODEL);
746 
747  for (unsigned int i = 1; i < mIKVisualizationLastIterationCount + 1; i++)
748  {
749  std::ostringstream converter;
750  converter << i;
751  std::string nsIterationVector = std::string("iterationVector") + converter.str();
752  for (unsigned int j = 0; j < 3*(mPanAngleSamplingStepsPerIteration+1); j++)
753  {
754  resetMarker.ns = nsIterationVector;
755  resetMarker.id = j;
756  resetMarker.header.stamp = ros::Time::now();
757  vis_pub.publish(resetMarker);
758  ros::spinOnce();
759  }
760  }
761  ros::spinOnce();
762  mIKVisualizationLastIterationCount = 0;
763  }
764 
765  void MILDRobotModelWithExactIK::visualizeIKCameraTarget(Eigen::Vector3d &target_view_center_point, Eigen::Vector3d &target_camera_point)
766  {
767  Eigen::Vector4d color_green(0.0,1.0,0.0,1.0);
768  visualizeIKArrowLarge(target_camera_point, target_view_center_point, color_green, "targetCameraVector", 0);
769  }
770 
771  void MILDRobotModelWithExactIK::visualizeIKcalculation(Eigen::Vector3d &base_point, Eigen::Vector3d &base_orientation, Eigen::Vector3d &pan_joint_point, Eigen::Vector3d & pan_rotated_point, Eigen::Vector3d &tilt_base_point, Eigen::Vector3d &tilt_base_point_projected, Eigen::Vector3d &cam_point, Eigen::Vector3d &actual_view_center_point)
772  {
773  Eigen::Vector4d color_red(1.0,0.0,0.0,1.0);
774  Eigen::Vector4d color_blue(0.0,0.0,1.0,1.0);
775  base_orientation.normalize();
776  Eigen::Vector3d base_point2 = base_point + base_orientation * 0.3;
777  visualizeIKArrowLarge(cam_point, actual_view_center_point, color_blue, "camToActualViewCenterVector", 0);
778  visualizeIKArrowSmall(tilt_base_point,cam_point, color_blue, "tiltToCamVector", 0);
779  visualizeIKPoint(tilt_base_point_projected, color_red, "tiltBaseVectorProjected", 0);
780  visualizeIKPoint(tilt_base_point, color_blue, "tiltBaseVector", 0);
781  visualizeIKArrowSmall(pan_rotated_point,tilt_base_point, color_blue, "panToTiltVector", 0);
782  visualizeIKPoint(pan_rotated_point, color_blue, "panBaseVector", 0);
783  visualizeIKArrowSmall(base_point,pan_joint_point, color_blue, "baseToPanVector", 0);
784  visualizeIKPoint(base_point, color_blue, "basePose", 0);
785  visualizeIKArrowLarge(base_point, base_point2, color_blue, "basePose", 1);
786  }
787 
788  void MILDRobotModelWithExactIK::visualizeCameraPoseCorrection(Eigen::Vector3d &base_point, Eigen::Vector3d &base_orientation, Eigen::Vector3d &pan_joint_point, Eigen::Vector3d & pan_rotated_point, Eigen::Vector3d &tilt_base_point, Eigen::Vector3d &cam_point, Eigen::Vector3d &actual_view_center_point)
789  {
790  Eigen::Vector4d color_red(1.0,0.0,0.0,1.0);
791  base_orientation.normalize();
792  Eigen::Vector3d base_point2 = base_point + base_orientation * 0.3;
793  visualizeIKArrowLarge(cam_point, actual_view_center_point, color_red, "camToActualViewCenterVector_poseCorrection", 0);
794  visualizeIKArrowSmall(tilt_base_point,cam_point, color_red, "tiltToCamVector_poseCorrection", 0);
795  visualizeIKPoint(tilt_base_point, color_red, "tiltBaseVector_poseCorrection", 0);
796  visualizeIKArrowSmall(pan_rotated_point,tilt_base_point, color_red, "panToTiltVector_poseCorrection", 0);
797  visualizeIKPoint(pan_rotated_point, color_red, "panBaseVector_poseCorrection", 0);
798  visualizeIKArrowSmall(base_point,pan_joint_point, color_red, "baseToPanVector_poseCorrection", 0);
799  visualizeIKPoint(base_point, color_red, "basePose_poseCorrection", 0);
800  visualizeIKArrowLarge(base_point, base_point2, color_red, "basePose_poseCorrection", 1);
801  }
802 
803  void MILDRobotModelWithExactIK::visualizeIKPoint(Eigen::Vector3d &point, Eigen::Vector4d &colorRGBA, std::string ns, int id)
804  {
805  visualization_msgs::Marker pointMarker = visualization_msgs::Marker();
806  pointMarker.header.stamp = ros::Time();
807  pointMarker.header.frame_id = mFrameName_map;
808  pointMarker.type = pointMarker.SPHERE;
809  pointMarker.action = pointMarker.ADD;
810  pointMarker.id = id;
811  pointMarker.lifetime = ros::Duration();
812  pointMarker.ns = ns;
813  pointMarker.scale.x = 0.02;
814  pointMarker.scale.y = 0.02;
815  pointMarker.scale.z = 0.02;
816  pointMarker.color.r = colorRGBA[0];
817  pointMarker.color.g = colorRGBA[1];
818  pointMarker.color.b = colorRGBA[2];
819  pointMarker.color.a = colorRGBA[3];
820  pointMarker.pose.position.x = point[0];
821  pointMarker.pose.position.y = point[1];
822  pointMarker.pose.position.z = point[2];
823  vis_pub.publish(pointMarker);
824  ros::spinOnce();
825  }
826 
827  void MILDRobotModelWithExactIK::visualizeIKArrowSmall(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, int id)
828  {
829  Eigen::Vector3d scaleParameters(0.005, 0.01, 0.01);
830  visualizeIKArrow(pointStart, pointEnd, colorRGBA, ns, scaleParameters, id);
831  }
832 
833  void MILDRobotModelWithExactIK::visualizeIKArrowLarge(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, int id)
834  {
835  Eigen::Vector3d scaleParameters(0.02, 0.05, 0.1);
836  visualizeIKArrow(pointStart, pointEnd, colorRGBA, ns, scaleParameters, id);
837  }
838 
839  void MILDRobotModelWithExactIK::visualizeIKArrow(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, Eigen::Vector3d &scaleParameters, int id)
840  {
841  geometry_msgs::Point point1, point2;
842  visualization_msgs::Marker arrowMarker = visualization_msgs::Marker();
843  arrowMarker.header.stamp = ros::Time();
844  arrowMarker.header.frame_id = mFrameName_map;
845  arrowMarker.type = arrowMarker.ARROW;
846  arrowMarker.action = arrowMarker.ADD;
847  arrowMarker.id = id;
848  arrowMarker.lifetime = ros::Duration();
849  arrowMarker.ns = ns;
850  arrowMarker.scale.x = scaleParameters[0]; //d Shaft
851  arrowMarker.scale.y = scaleParameters[1]; //d Head
852  arrowMarker.scale.z = scaleParameters[2]; //l Head
853  arrowMarker.color.r = colorRGBA[0];
854  arrowMarker.color.g = colorRGBA[1];
855  arrowMarker.color.b = colorRGBA[2];
856  arrowMarker.color.a = colorRGBA[3];
857  point1.x = pointStart[0];
858  point1.y = pointStart[1];
859  point1.z = pointStart[2];
860  point2.x = pointEnd[0];
861  point2.y = pointEnd[1];
862  point2.z = pointEnd[2];
863  arrowMarker.points.push_back(point1);
864  arrowMarker.points.push_back(point2);
865  vis_pub.publish(arrowMarker);
866  ros::spinOnce();
867  }
868 
869  double MILDRobotModelWithExactIK::getBaseAngleFromBaseFrame(Eigen::Affine3d &baseFrame)
870  {
871  Eigen::Vector3d xAxis(baseFrame(0,0), baseFrame(1,0), 0.0);
872  Eigen::Vector3d yAxis(baseFrame(0,1), baseFrame(1,1), 0.0);
873  xAxis.normalize();
874  yAxis.normalize();
875 
876  if (yAxis[0] >= 0)
877  {
878  return acos(xAxis[0]);
879  }
880  else
881  {
882  return 2.0*M_PI - acos(xAxis[0]);
883  }
884  }
885 }
886 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void publish(const boost::shared_ptr< M > &message) const
NavigationPathIKRatingModule implements the functionlities offered by IKRatingModule.
std::tuple< double, double > PTUConfig
MILDRobotModelWithExactIK implements a model of pan tilt unit robot where the inverse kinematic is ca...
MILDRobotModel implements a model of pan tilt unit robot.
static boost::shared_ptr< DebugHelper > getInstance()
Definition: DebugHelper.cpp:29
SimpleIKRatingModule uses the difference between the start and target angle for the rating...
virtual ~MILDRobotModelWithExactIK()
destructor of the MILDRobotModelWithExactIK
void visualizeIKPoint(Eigen::Vector3d &point, Eigen::Vector4d &colorRGBA, std::string ns, int id)
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:50
MILDRobotModelWithExactIK()
constructor of the MILDRobotModelWithExactIK
void setViewPointDistance(float viewPointDistance)
Sets the distance between the desired view center point and the camera.
bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
boost::shared_ptr< RobotModel > RobotModelPtr
Definition for the shared pointer type of the class.
Definition: RobotModel.hpp:132
void visualizeIKArrow(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, Eigen::Vector3d &scaleParameters, int id)
double getBaseAngleFromBaseFrame(Eigen::Affine3d &baseFrame)
boost::tuple< float, float > mPanLimits
this namespace contains all generally usable classes.
Definition: DebugHelper.hpp:27
void visualizeCameraPoseCorrection(Eigen::Vector3d &base_point, Eigen::Vector3d &base_orientation, Eigen::Vector3d &pan_joint_point, Eigen::Vector3d &pan_rotated_point, Eigen::Vector3d &tilt_base_point, Eigen::Vector3d &cam_point, Eigen::Vector3d &actual_view_center_point)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void visualizeIKcalculation(Eigen::Vector3d &base_point, Eigen::Vector3d &base_orientation, Eigen::Vector3d &pan_joint_point, Eigen::Vector3d &pan_rotated_point, Eigen::Vector3d &tilt_base_point, Eigen::Vector3d &tilt_base_point_projected, Eigen::Vector3d &cam_point, Eigen::Vector3d &actual_view_center_point)
#define ROS_WARN_STREAM(args)
void visualizeIKArrowSmall(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, int id)
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const
bool getTiltAngleAndTiltBasePointProjected(Eigen::Vector3d &planeNormal, Eigen::Vector3d &targetViewVector, Eigen::Vector3d &target_view_center_point, double &tilt, Eigen::Vector3d &tilt_base_point_projected)
Eigen::Affine3d getTiltJointFrame(Eigen::Vector3d &planeNormal, Eigen::Vector3d &targetViewVector, Eigen::Vector3d &tilt_base_point)
boost::tuple< float, float > mTiltLimits
void visualizeIKCameraTarget(Eigen::Vector3d &target_view_center_point, Eigen::Vector3d &target_camera_point)
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
boost::shared_ptr< NavigationPathIKRatingModule > NavigationPathIKRatingModulePtr
Definition for the shared pointer type of the class.
bool getParam(const std::string &key, std::string &s) const
PTUConfig calculateCameraPoseCorrection(const RobotStatePtr &sourceRobotState, const SimpleVector3 &position, const SimpleQuaternion &orientation)
Calculates the best approximation for the given camera pose from the current base position...
static Time now()
#define ROS_ERROR_STREAM(args)
boost::shared_ptr< AngleApproximationIKRatingModule > AngleApproximationIKRatingModulePtr
Definition for the shared pointer type of the class.
RobotStatePtr calculateRobotState(const RobotStatePtr &sourceRobotState, const SimpleVector3 &position, const SimpleQuaternion &orientation)
Calculates the inverse kinematics for the given camera pose.
boost::shared_ptr< SimpleIKRatingModule > SimpleIKRatingModulePtr
Definition for the shared pointer type of the class.
void visualizeIKArrowLarge(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, int id)
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:64
AngleApproximationIKRatingModule uses an approximation of the total angle delta during the mild movem...
double getPanAngleFromPanJointPose(Eigen::Affine3d &panJointFrame, MILDRobotStatePtr &robotState)


asr_robot_model_services
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:49:59