NavigationPathIKRatingModule.cpp
Go to the documentation of this file.
00001 
00020 #include "robot_model_services/rating/impl/NavigationPathIKRatingModule.h"
00021 #include <ros/ros.h>
00022 
00023 namespace robot_model_services {
00024     NavigationPathIKRatingModule::NavigationPathIKRatingModule(RobotModelPtr robotModel) : IKRatingModule()
00025     {
00026         mRobotModel = robotModel;
00027         mDebugHelperPtr = DebugHelper::getInstance();
00028     }
00029     NavigationPathIKRatingModule::~NavigationPathIKRatingModule() { }
00030 
00031     double NavigationPathIKRatingModule::getPanAngleRating(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition, double sourceRotationBase, double targetRotationBase)
00032     {
00033         targetRotationBase = fmod(targetRotationBase + M_PI, 2.0 * M_PI);
00034         nav_msgs::Path navigationPath = this->mRobotModel->getNavigationPath(sourcePosition, targetPosition, sourceRotationBase, targetRotationBase);
00035 
00036         if (navigationPath.poses.size() > 2)
00037         {
00038             //Get length and angle change of the path
00039             double length = 0;
00040             double currentDotProduct;
00041             double absolutAngleChange = 0;
00042             std::vector<geometry_msgs::PoseStamped>::iterator poseIterator = navigationPath.poses.end();
00043             geometry_msgs::Pose previousPose_2 = poseIterator->pose;
00044             poseIterator--;
00045             geometry_msgs::Pose previousPose_1 = poseIterator->pose;
00046             poseIterator--;
00047             do
00048             {
00049                 length += sqrt(pow(previousPose_1.position.x-(*poseIterator).pose.position.x, 2.0)+pow(previousPose_1.position.y-(*poseIterator).pose.position.y, 2.0));
00050                 Eigen::Vector2d v1(previousPose_1.position.x - previousPose_2.position.x, previousPose_1.position.y - previousPose_2.position.y);
00051                 Eigen::Vector2d v2(-previousPose_2.position.x + (*poseIterator).pose.position.x, -previousPose_2.position.y + (*poseIterator).pose.position.y);
00052                 v1.normalize();
00053                 v2.normalize();
00054                 currentDotProduct = v1.dot(v2);
00055                 if (currentDotProduct < -1.0) currentDotProduct = -1.0;
00056                 if (currentDotProduct > 1.0) currentDotProduct = 1.0;
00057                 absolutAngleChange += fabs(acos(currentDotProduct));
00058                 previousPose_2 = previousPose_1;
00059                 previousPose_1 = poseIterator->pose;
00060                 poseIterator--;
00061 
00062             } while(poseIterator > navigationPath.poses.begin() && length < 1.0);  //consider only the last 1 meter of the path
00063             double rating = pow(0.6, absolutAngleChange);
00064             mDebugHelperPtr->write(std::stringstream() << "Rating: " << rating
00065                                     << " (absolutAngleChange: " << absolutAngleChange
00066                                     << ", length: " << length << ")",
00067                         DebugHelper::IK_RATING);
00068             return rating;
00069         }
00070         else
00071         {
00072             return 0.0;
00073         }
00074     }
00075 }
00076 


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 Sat Jun 8 2019 18:24:52