32 #include "nav_msgs/GetPlan.h" 33 #include "geometry_msgs/PoseStamped.h" 34 #include "geometry_msgs/Point.h" 36 #include "urdf/model.h" 37 #include "urdf_model/joint.h" 39 #include <tf_conversions/tf_eigen.h> 41 #include <tf_conversions/tf_eigen.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> 51 #include <visualization_msgs/Marker.h> 60 double inverseKinematicIterationAccuracy_, ncp_, fcp_;
61 int panAngleSamplingStepsPerIteration_;
63 std::string IKAngleRating_;
64 n.
getParam(
"panAngleSamplingStepsPerIteration", panAngleSamplingStepsPerIteration_);
65 n.
getParam(
"inverseKinematicIterationAccuracy", inverseKinematicIterationAccuracy_);
85 std::string IKVisualization;
86 n.
getParam(
"IKVisualization", IKVisualization);
89 n.
getParam(
"IKAngleRating", IKAngleRating_);
91 if (IKAngleRating_ ==
"ANGLE_APPROXIMATION")
96 else if (IKAngleRating_ ==
"NAVIGATION_PATH")
101 else if (IKAngleRating_ ==
"SIMPLE")
109 ROS_WARN_STREAM(
"'" << IKAngleRating_ <<
"' is not a valid IK rating algorithm! Using the SimpleIKRating algorithm instead.");
140 Eigen::Vector3d basePosition(sourceMILDRobotState->x, sourceMILDRobotState->y, 0.0);
142 Eigen::Affine3d basePoseEigen = Eigen::Translation3d(basePosition) * Eigen::AngleAxisd((
double)(sourceMILDRobotState->rotation), Eigen::Vector3d::UnitZ());
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;
151 Eigen::Vector3d target_cam_point(position[0], position[1], position[2]);
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();
158 double viewTriangleXYPlane_AngleBeta = pow(viewTriangleXYPlane_sideA, 2.0) + pow(
viewTriangleXYPlane_sideC, 2.0) - pow(viewTriangleXYPlane_sideB, 2.0);
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;
172 mDebugHelperPtr->write(std::stringstream() <<
"asin(panJointToCenterPointProjected.dot(panJointYAxis)): " << asin(panJointToCenterPointProjected.dot(panJointYAxis)),
175 mDebugHelperPtr->write(std::stringstream() <<
"panJointToCenterPointProjected.dot(panJointXAxis): " << panJointToCenterPointProjected.dot(panJointXAxis),
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;
186 double viewTriangleZPlane_sideC = - bTimesCos/2.0 + sqrt(pow(bTimesCos,2.0)/4.0-pow(
viewTriangleZPlane_sideB,2.0)+pow(viewTriangleZPlane_sideA,2.0));
193 viewTriangleZPlane_angleGamma = acos(viewTriangleZPlane_angleGamma / (2.0*
viewTriangleZPlane_sideB*viewTriangleZPlane_sideA));
194 double tiltAngle = viewTriangleZPlane_angleGamma - acos(tiltJointToViewCenter[2]/tiltJointToViewCenter.norm());
199 if (tiltAngle < tiltMin)
201 if (tiltAngle < tiltMin - 10.0) {
202 ROS_WARN_STREAM(
"Calculated Tilt-Angle was too small: " << tiltAngle*(180.0/M_PI));
208 if (tiltAngle > tiltMax)
210 if (tiltAngle > tiltMax + 10.0) {
211 ROS_WARN_STREAM(
"Calculated Tilt-Angle was too high: " << tiltAngle*(180.0/M_PI));
220 if (panAngle < panMin)
222 if (panAngle < panMin - 10.0) {
223 ROS_WARN_STREAM(
"Calculated Pan-Angle was too small: " << panAngle*(180.0/M_PI));
229 if (panAngle > panMax)
231 if (panAngle > panMax + 10.0) {
232 ROS_WARN_STREAM(
"Calculated Pan-Angle was too high: " << panAngle*(180.0/M_PI));
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);
262 std::clock_t begin = std::clock();
266 targetMILDRobotState->pan = 0;
267 targetMILDRobotState->tilt = 0;
268 targetMILDRobotState->rotation = 0;
269 targetMILDRobotState->x = 0;
270 targetMILDRobotState->y = 0;
285 return targetMILDRobotState;
288 Eigen::Quaterniond targetOrientation(orientation.w(), orientation.x(), orientation.y(), orientation.z());
289 Eigen::Vector3d targetViewVector = targetOrientation.toRotationMatrix() * Eigen::Vector3d::UnitX();
293 Eigen::Vector3d planeNormal = -targetViewVector.cross(Eigen::Vector3d::UnitZ());
294 planeNormal.normalize(); targetViewVector.normalize();
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(),
307 Eigen::Vector3d target_view_center_point = Eigen::Vector3d(position[0], position[1], position[2]) + targetViewVector*
mViewPointDistance;
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]);
317 double tilt; Eigen::Vector3d tilt_base_point_projected;
320 ROS_ERROR_STREAM(
"No solution found for center point (" << position[0] <<
", " << position[1] <<
", " << position[2] <<
")");
322 return targetMILDRobotState;
324 mDebugHelperPtr->write(std::stringstream() <<
"tilt_base_point_projected: " << tilt_base_point_projected[0] <<
", " << tilt_base_point_projected[1] <<
", " << tilt_base_point_projected[2],
328 if (tilt < tiltMin - 10.0) {
329 ROS_WARN_STREAM(
"Calculated Tilt-Angle was too small: " << tilt*(180.0/M_PI));
337 if (tilt > tiltMax + 10.0) {
338 ROS_WARN_STREAM(
"Calculated Tilt-Angle was too high: " << tilt*(180.0/M_PI));
344 mDebugHelperPtr->write(std::stringstream() <<
"Tilt: " << tilt*(180.0/M_PI) <<
" deg",
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],
352 Eigen::Affine3d tiltFrame =
getTiltJointFrame(planeNormal, targetViewVector, tilt_base_point);
353 Eigen::Affine3d tiltedFrame = tiltFrame * Eigen::AngleAxisd(-tilt, Eigen::Vector3d::UnitY());
355 Eigen::Affine3d actualViewCenterEigen(Eigen::Translation3d(Eigen::Vector3d(0.0, 0.0, mViewPointDistance)));
356 actualViewCenterEigen = camFrame*actualViewCenterEigen;
364 Eigen::Affine3d pan_Frame = pan_rotated_Frame * Eigen::AngleAxisd(pan, Eigen::Vector3d::UnitZ());
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);
381 targetMILDRobotState->pan = pan;
385 while (targetMILDRobotState->rotation < 0) { targetMILDRobotState->rotation += 2 * M_PI; };
386 while (targetMILDRobotState->rotation > 2 * M_PI) { targetMILDRobotState->rotation -= 2 * M_PI; };
389 targetMILDRobotState->tilt = tilt;
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)",
402 std::clock_t end = std::clock();
403 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
406 mDebugHelperPtr->write(std::stringstream() <<
"IK Calculation took " << elapsed_secs <<
" seconds. Total calculation time: " 411 return targetMILDRobotState;
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;
426 Eigen::Affine3d tiltFrame(tiltFrame_Rotation);
435 t3 =
h_tilt - target_view_center_point[2];
438 double planeNormalX = planeNormal.x();
441 if (fabs(planeNormalX) < 10e-7)
445 t2 = -(t3*planeNormal[2])/planeNormal[1];
455 if (targetViewVector[0]*t1+targetViewVector[1]*t2 > 0)
464 a = 1 + pow(planeNormal(1)/planeNormalX, 2.0);
465 b = (2*t3*planeNormal(1)*planeNormal(2))/pow(planeNormalX, 2.0);
467 if (pow(b, 2.0)<4*a*c)
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);
476 t1_1 = -(t2_1*planeNormal(1)+t3*planeNormal(2))/planeNormalX;
477 t1_2 = -(t2_2*planeNormal(1)+t3*planeNormal(2))/planeNormalX;
479 if (targetViewVector[0]*t1_1+targetViewVector[1]*t2_1 < 0)
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]);
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]);
506 unsigned int iterationCount = 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;
518 mDebugHelperPtr->write(std::stringstream() <<
"currentAngleRange: " << currentAngleRange <<
" currentBestAngle: " << currentBestAngle,
522 Eigen::Vector3d basePoint, basePoint2;
523 Eigen::Vector3d baseOrientation;
527 std::ostringstream converter;
528 converter << iterationCount;
529 std::string nsIterationVector = std::string(
"iterationVector") + converter.str();
531 double currentIterationAngle, currentRating, angleCenter;
532 currentBestRating = newBestRating;
533 angleCenter = currentBestAngle;
534 newBestRating = -1.0;
537 currentIterationAngle = angleCenter - currentAngleRange/2.0 + i * angleStepSize;
538 if (phiMax>currentIterationAngle && phiMin<currentIterationAngle)
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);
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)
554 newBestRating = currentRating;
555 currentBestAngle = currentIterationAngle;
559 Eigen::Vector4d color_succeeded(1.0-currentRating,currentRating, 0.0, 1.0);
565 mDebugHelperPtr->write(std::stringstream() <<
"Best angle: " << currentBestAngle <<
" with rating: " << newBestRating
566 <<
" and angle range " << currentAngleRange,
568 currentAngleRange = currentAngleRange / 2.0;
574 if (currentBestRating < 0.0) {
ROS_ERROR_STREAM(
"No valid solution found for this pan frame.");}
575 return -currentBestAngle;
583 Eigen::Affine3d tiltAxisPointEigen, tiltToCamLeftEigen, tiltToCamRightEigen, cameraLeftPointEigen, cameraRightPointEigen, cameraMidPointEigen;
599 ROS_ERROR(
"TF lookup timed out. Is the transformation publisher running?");
605 ROS_ERROR(
"An error occured during tf-lookup: %s",ex.what());
610 tf::poseTFToEigen(tiltToCamLeftTF, tiltToCamLeftEigen);
611 tf::poseTFToEigen(tiltToCamRightTF, tiltToCamRightEigen);
614 cameraLeftPointEigen = tiltAxisPointEigen * tiltToCamLeftEigen;
615 cameraRightPointEigen = tiltAxisPointEigen * tiltToCamRightEigen;
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;
626 h_tilt = tiltAxisPointEigen.matrix()(2,3);
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));
639 tilt_to_cam.normalize();
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);
655 panToCameraNormal.normalize();
656 mPanAngleOffset = acos(panToCameraNormal.dot(Eigen::Vector3d::UnitX()));
676 visualization_msgs::Marker resetMarker = visualization_msgs::Marker();
679 resetMarker.action = visualization_msgs::Marker::DELETE;
681 resetMarker.scale.x = 0.02;
682 resetMarker.scale.y = 0.02;
683 resetMarker.scale.z = 0.02;
684 resetMarker.color.a = 0.0;
688 resetMarker.type = visualization_msgs::Marker::ARROW;
689 resetMarker.ns =
"camToActualViewCenterVector";
694 resetMarker.type = visualization_msgs::Marker::ARROW;
695 resetMarker.ns =
"tiltToCamVector";
700 resetMarker.type = visualization_msgs::Marker::SPHERE;
701 resetMarker.ns =
"tiltBaseVectorProjected";
706 resetMarker.type = visualization_msgs::Marker::SPHERE;
707 resetMarker.ns =
"tiltBaseVector";
712 resetMarker.type = visualization_msgs::Marker::ARROW;
713 resetMarker.ns =
"panToTiltVector";
718 resetMarker.type = visualization_msgs::Marker::SPHERE;
719 resetMarker.ns =
"panBaseVector";
724 resetMarker.type = visualization_msgs::Marker::ARROW;
725 resetMarker.ns =
"baseToPanVector";
730 resetMarker.type = visualization_msgs::Marker::ARROW;
731 resetMarker.ns =
"targetCameraVector";
736 resetMarker.type = visualization_msgs::Marker::SPHERE;
737 resetMarker.ns =
"basePose";
740 resetMarker.type = visualization_msgs::Marker::ARROW;
749 std::ostringstream converter;
751 std::string nsIterationVector = std::string(
"iterationVector") + converter.str();
754 resetMarker.ns = nsIterationVector;
762 mIKVisualizationLastIterationCount = 0;
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);
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)
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);
779 visualizeIKPoint(tilt_base_point_projected, color_red,
"tiltBaseVectorProjected", 0);
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)
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);
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);
805 visualization_msgs::Marker pointMarker = visualization_msgs::Marker();
808 pointMarker.type = pointMarker.SPHERE;
809 pointMarker.action = pointMarker.ADD;
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];
829 Eigen::Vector3d scaleParameters(0.005, 0.01, 0.01);
835 Eigen::Vector3d scaleParameters(0.02, 0.05, 0.1);
841 geometry_msgs::Point point1, point2;
842 visualization_msgs::Marker arrowMarker = visualization_msgs::Marker();
845 arrowMarker.type = arrowMarker.ARROW;
846 arrowMarker.action = arrowMarker.ADD;
850 arrowMarker.scale.x = scaleParameters[0];
851 arrowMarker.scale.y = scaleParameters[1];
852 arrowMarker.scale.z = scaleParameters[2];
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);
871 Eigen::Vector3d xAxis(baseFrame(0,0), baseFrame(1,0), 0.0);
872 Eigen::Vector3d yAxis(baseFrame(0,1), baseFrame(1,1), 0.0);
878 return acos(xAxis[0]);
882 return 2.0*M_PI - acos(xAxis[0]);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
double mViewPointDistance
std::string mFrameName_mild_ptu_tilt_link_rotated
std::string mFrameName_map
unsigned int mIKVisualizationLastIterationCount
void publish(const boost::shared_ptr< M > &message) const
NavigationPathIKRatingModule implements the functionlities offered by IKRatingModule.
ros::ServiceClient navigationCostClient
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.
Eigen::Affine3d tiltToPanEigen
std::string mFrameName_mild_base
double viewTriangleZPlane_sideB
static boost::shared_ptr< DebugHelper > getInstance()
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
Eigen::Affine3d panToBaseEigen
bool tfParametersInitialized
DebugHelperPtr mDebugHelperPtr
MILDRobotModelWithExactIK()
constructor of the MILDRobotModelWithExactIK
const unsigned int IKVisualizationMaximunIterationCount
IKRatingModulePtr ikRatingModule
void setViewPointDistance(float viewPointDistance)
Sets the distance between the desired view center point and the camera.
double viewTriangleXYPlane_sideC
double viewTriangleZPlane_angleGamma
boost::shared_ptr< RobotModel > RobotModelPtr
Definition for the shared pointer type of the class.
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.
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)
std::string mFrameName_mild_ptu_pan_link_rotated
void resetIKVisualization()
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)
tf::TransformListener listener
#define ROS_WARN_STREAM(args)
void visualizeIKArrowSmall(Eigen::Vector3d &pointStart, Eigen::Vector3d &pointEnd, Eigen::Vector4d &colorRGBA, std::string ns, int id)
unsigned int mPanAngleSamplingStepsPerIteration
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)
std::string mFrameName_mild_ptu_pan_link
Eigen::Affine3d tiltToCameraEigen
boost::tuple< float, float > mTiltLimits
void visualizeIKCameraTarget(Eigen::Vector3d &target_view_center_point, Eigen::Vector3d &target_camera_point)
Eigen::Affine3d baseToPanEigen
uint32_t getNumSubscribers() const
std::string mFrameName_mild_camera_left
#define ROS_INFO_STREAM(args)
std::string mFrameName_mild_ptu_tilt_link
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...
double viewTriangleZPlane_sideA
double viewTriangleZPlane_angleAlpha
Eigen::Affine3d panToTiltEigen
#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)
std::string mFrameName_mild_camera_right
ROSCPP_DECL void spinOnce()
Eigen::Quaternion< Precision > SimpleQuaternion
float mInverseKinematicIterationAccuracy
AngleApproximationIKRatingModule uses an approximation of the total angle delta during the mild movem...
double getPanAngleFromPanJointPose(Eigen::Affine3d &panJointFrame, MILDRobotStatePtr &robotState)