AngleApproximationIKRatingModule.cpp
Go to the documentation of this file.
00001 
00020 #include "robot_model_services/rating/impl/AngleApproximationIKRatingModule.h"
00021 #include <ros/ros.h>
00022 
00023 namespace robot_model_services {
00024     AngleApproximationIKRatingModule::AngleApproximationIKRatingModule() : IKRatingModule() {}
00025     AngleApproximationIKRatingModule::~AngleApproximationIKRatingModule() { }
00026 
00027     double AngleApproximationIKRatingModule::getPanAngleRating(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition, double sourceRotationBase, double targetRotationBase)
00028     {
00029         double angleBetweenPoints = 0.0;
00030         if (fabs(targetPosition.y - sourcePosition.y) > 0.000001f && fabs(targetPosition.x - sourcePosition.x) > 0.000001f)  //Prevent undefined behavior when distance if close to zero
00031         {
00032             //ROS_INFO_STREAM("Rating for (" << sourcePosition.x << ", " << sourcePosition.y << ") to (" << targetPosition.x << ", " << targetPosition.y << ")");
00033             angleBetweenPoints = std::atan2(targetPosition.y - sourcePosition.y, targetPosition.x - sourcePosition.x);
00034         }
00035         //Make sure, input is between 0 and 2 PI
00036         if (sourceRotationBase <= 0) {sourceRotationBase += 2.0*M_PI;}
00037         if (targetRotationBase <= 0) {targetRotationBase += 2.0*M_PI;}
00038         double sourceRotDiff = fmod(sourceRotationBase - angleBetweenPoints, 2.0*M_PI);
00039         double targetRotDiff = fmod(targetRotationBase - angleBetweenPoints, 2.0*M_PI);
00040         //Make sure, rotation difference is between 0 and 2 PI
00041         if (sourceRotDiff <= 0) {sourceRotDiff += 2.0*M_PI;}
00042         if (targetRotDiff <= 0) {targetRotDiff += 2.0*M_PI;}
00043 
00044         //Calculate costs, take costs for turning left oder right, depending on which ones better
00045         double rotationCosts = std::min(fabs(targetRotDiff), (2.0f*M_PI-fabs(targetRotDiff))) + std::min(fabs(sourceRotDiff), (2.0f*M_PI-fabs(sourceRotDiff)));
00046 
00047         double rating = pow(0.6, rotationCosts);
00048         return rating;
00049     }
00050 }
00051 
00052 


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