MILDRobotModel.cpp
Go to the documentation of this file.
00001 
00020 #include <glpk.h>
00021 #include <limits>
00022 #include <ros/ros.h>
00023 #include <ros/node_handle.h>
00024 
00025 #include "robot_model_services/robot_model/impl/MILDRobotModel.hpp"
00026 #include "robot_model_services/robot_model/impl/MILDRobotState.hpp"
00027 #include "robot_model_services/helper/MathHelper.hpp"
00028 
00029 #include "nav_msgs/GetPlan.h"
00030 #include "geometry_msgs/PoseStamped.h"
00031 #include "geometry_msgs/Point.h"
00032 
00033 #include "urdf/model.h"
00034 #include "urdf_model/joint.h"
00035 #include "tf/tf.h"
00036 #include "tf/transform_datatypes.h"
00037 //#include <robot_state_publisher/robot_state_publisher.h>
00038 #include <kdl_parser/kdl_parser.hpp>
00039 #include <kdl/chain.hpp>
00040 #include <kdl/chainfksolver.hpp>
00041 #include <kdl/chainfksolverpos_recursive.hpp>
00042 
00043 namespace robot_model_services {
00044     MILDRobotModel::MILDRobotModel() : RobotModel(), listener() {
00045         mDebugHelperPtr = DebugHelper::getInstance();
00046         mDebugHelperPtr->write(std::stringstream() << "STARTING MILD ROBOT MODEL", DebugHelper::ROBOT_MODEL);
00047         n = ros::NodeHandle(ros::this_node::getName());
00048         navigationCostClient = n.serviceClient<nav_msgs::GetPlan>("/move_base/make_plan");
00049         double mOmegaPan_, mOmegaTilt_, mOmegaRot_, tolerance_, speedFactorPTU_,speedFactorBaseMove_,speedFactorBaseRot_, mSigma_;
00050         bool useGlobalPlanner_;
00051         n.getParam("mOmegaPan", mOmegaPan_);
00052         n.getParam("mOmegaTilt", mOmegaTilt_);
00053         n.getParam("mOmegaRot", mOmegaRot_);
00054         n.getParam("speedFactorPTU", speedFactorPTU_);
00055         n.getParam("speedFactorBaseMove", speedFactorBaseMove_);
00056         n.getParam("speedFactorBaseRot", speedFactorBaseRot_);
00057         n.getParam("tolerance", tolerance_);
00058         n.getParam("useGlobalPlanner", useGlobalPlanner_);
00059         n.getParam("mSigma", mSigma_);
00060 
00061         useGlobalPlanner = useGlobalPlanner_;
00062         if (useGlobalPlanner_)
00063         {
00064             mDebugHelperPtr->write("Use of global planner ENABLED", DebugHelper::PARAMETERS);
00065         }
00066         else
00067         {
00068             mDebugHelperPtr->write("Use of global planner DISABLED. Using simplified calculation instead", DebugHelper::PARAMETERS);
00069         }
00070 
00071         mDebugHelperPtr->write(std::stringstream() << "speedFactorPTU: " << speedFactorPTU_, DebugHelper::PARAMETERS);
00072         mDebugHelperPtr->write(std::stringstream() << "speedFactorBaseMove: " << speedFactorBaseMove_, DebugHelper::PARAMETERS);
00073         mDebugHelperPtr->write(std::stringstream() << "speedFactorBaseRot: " << speedFactorBaseRot_, DebugHelper::PARAMETERS);
00074         mDebugHelperPtr->write(std::stringstream() << "tolerance: " << tolerance_, DebugHelper::PARAMETERS);
00075         mDebugHelperPtr->write(std::stringstream() << "mOmegaPan: " << mOmegaPan_, DebugHelper::PARAMETERS);
00076         mDebugHelperPtr->write(std::stringstream() << "mOmegaTilt: " << mOmegaTilt_, DebugHelper::PARAMETERS);
00077         mDebugHelperPtr->write(std::stringstream() << "mOmegaRot: " << mOmegaRot_, DebugHelper::PARAMETERS);
00078         mDebugHelperPtr->write(std::stringstream() << "mSigma: " << mSigma_, DebugHelper::PARAMETERS);
00079         mOmegaPan = mOmegaPan_;
00080         mOmegaTilt = mOmegaTilt_;
00081         mOmegaRot = mOmegaRot_;
00082         speedFactorPTU = speedFactorPTU_;
00083         speedFactorBaseMove = speedFactorBaseMove_;
00084         speedFactorBaseRot = speedFactorBaseRot_;
00085         tolerance = tolerance_;
00086         mSigma = mSigma_;
00087         //Read robot model frames
00088         std::string strMap_, strMild_base_, strMild_ptu_base_link_, strMild_ptu_pan_link_, strMild_ptu_pan_link_rotated_, strMild_ptu_tilt_link_,
00089         strMild_ptu_tilt_link_rotated_, strMild_camera_mount_link_, strMild_camera_left_, strMild_camera_right;
00090         n.getParam("map_frame", strMap_);
00091         n.getParam("base_frame", strMild_base_);
00092         n.getParam("ptu_base_frame", strMild_ptu_base_link_);
00093         n.getParam("ptu_pan_frame", strMild_ptu_pan_link_);
00094         n.getParam("ptu_pan_frame_rotated", strMild_ptu_pan_link_rotated_);
00095         n.getParam("ptu_tilt_frame", strMild_ptu_tilt_link_);
00096         n.getParam("ptu_tilt_frame_rotated", strMild_ptu_tilt_link_rotated_);
00097         n.getParam("camera_mount_frame", strMild_camera_mount_link_);
00098         n.getParam("camera_left_frame", strMild_camera_left_);
00099         n.getParam("camera_right_frame", strMild_camera_right);
00100 
00101         mDebugHelperPtr->write(std::stringstream() << "strMap_: " << strMap_, DebugHelper::PARAMETERS);
00102         mDebugHelperPtr->write(std::stringstream() << "strMild_base_: " << strMild_base_, DebugHelper::PARAMETERS);
00103         mDebugHelperPtr->write(std::stringstream() << "strMild_ptu_base_link_: " << strMild_ptu_base_link_, DebugHelper::PARAMETERS);
00104         mDebugHelperPtr->write(std::stringstream() << "strMild_ptu_pan_link_: " << strMild_ptu_pan_link_, DebugHelper::PARAMETERS);
00105         mDebugHelperPtr->write(std::stringstream() << "strMild_ptu_pan_link_rotated_: " << strMild_ptu_pan_link_rotated_, DebugHelper::PARAMETERS);
00106         mDebugHelperPtr->write(std::stringstream() << "strMild_ptu_tilt_link_: " << strMild_ptu_tilt_link_, DebugHelper::PARAMETERS);
00107         mDebugHelperPtr->write(std::stringstream() << "strMild_ptu_tilt_link_rotated_: " << strMild_ptu_tilt_link_rotated_, DebugHelper::PARAMETERS);
00108         mDebugHelperPtr->write(std::stringstream() << "strMild_camera_mount_link_: " << strMild_camera_mount_link_, DebugHelper::PARAMETERS);
00109         mDebugHelperPtr->write(std::stringstream() << "strMild_camera_left_: " << strMild_camera_left_, DebugHelper::PARAMETERS);
00110         mDebugHelperPtr->write(std::stringstream() << "strMild_camera_right: " << strMild_camera_right, DebugHelper::PARAMETERS);
00111 
00112         mFrameName_map = strMap_;
00113         mFrameName_mild_base = strMild_base_;
00114         mFrameName_mild_ptu_base_link = strMild_ptu_base_link_;
00115         mFrameName_mild_ptu_pan_link = strMild_ptu_pan_link_;
00116         mFrameName_mild_ptu_pan_link_rotated = strMild_ptu_pan_link_rotated_;
00117         mFrameName_mild_ptu_tilt_link = strMild_ptu_tilt_link_;
00118         mFrameName_mild_ptu_tilt_link_rotated = strMild_ptu_tilt_link_rotated_;
00119         mFrameName_mild_camera_mount_link = strMild_camera_mount_link_;
00120         mFrameName_mild_camera_left = strMild_camera_left_;
00121         mFrameName_mild_camera_right = strMild_camera_right;
00122         this->setPanAngleLimits(0, 0);
00123         this->setTiltAngleLimits(0, 0);
00124         this->setRotationAngleLimits(0, 0);
00125         }
00126 
00127         MILDRobotModel::~MILDRobotModel() {}
00128 
00129     geometry_msgs::Pose MILDRobotModel::getRobotPose()
00130     {
00131         geometry_msgs::Pose robotPose;
00132         tf::StampedTransform transform;
00133         listener.lookupTransform(mFrameName_map, mFrameName_mild_base, ros::Time(0), transform);
00134         robotPose.position.x = transform.getOrigin()[0];
00135         robotPose.position.y = transform.getOrigin()[1];
00136         robotPose.position.z = transform.getOrigin()[2];
00137         tf::quaternionTFToMsg(transform.getRotation(), robotPose.orientation);
00138         return robotPose;
00139     }
00140 
00141     geometry_msgs::Pose MILDRobotModel::getCameraPose()
00142     {
00143         geometry_msgs::Pose cameraPose;
00144         tf::StampedTransform transform;
00145         listener.lookupTransform(mFrameName_map, mFrameName_mild_camera_mount_link, ros::Time(0), transform);
00146         cameraPose.position.x = transform.getOrigin()[0];
00147         cameraPose.position.y = transform.getOrigin()[1];
00148         cameraPose.position.z = transform.getOrigin()[2];
00149         tf::quaternionTFToMsg(transform.getRotation(), cameraPose.orientation);
00150         return cameraPose;
00151     }
00152 
00153         void MILDRobotModel::setPanAngleLimits(float minAngleDegrees, float maxAngleDegrees) {
00154         mDebugHelperPtr->write(std::stringstream() << "Setting PAN angle limits to (" << minAngleDegrees << ", " << maxAngleDegrees << ")", DebugHelper::PARAMETERS);
00155                 mPanLimits.get<0>() = MathHelper::degToRad(minAngleDegrees);
00156                 mPanLimits.get<1>() = MathHelper::degToRad(maxAngleDegrees);
00157         }
00158 
00159         void MILDRobotModel::setTiltAngleLimits(float minAngleDegrees, float maxAngleDegrees) {
00160         mDebugHelperPtr->write(std::stringstream() << "Setting TILT angle limits to (" << minAngleDegrees << ", " << maxAngleDegrees << ")", DebugHelper::PARAMETERS);
00161                 mTiltLimits.get<0>() = MathHelper::degToRad(minAngleDegrees);
00162                 mTiltLimits.get<1>() = MathHelper::degToRad(maxAngleDegrees);
00163         }
00164 
00165         void MILDRobotModel::setRotationAngleLimits(float minAngleDegrees, float maxAngleDegrees) {
00166         mDebugHelperPtr->write(std::stringstream() << "Setting rotation angle limits to (" << minAngleDegrees << ", " << maxAngleDegrees << ")", DebugHelper::PARAMETERS);
00167         mRotationLimits.get<0>() = MathHelper::degToRad(minAngleDegrees);
00168                 mRotationLimits.get<1>() = MathHelper::degToRad(maxAngleDegrees);
00169         }
00170 
00171     bool MILDRobotModel::isPositionAllowed(const geometry_msgs::Point &position)
00172     {
00173         mDebugHelperPtr->writeNoticeably("STARTING IS-POSITION-ALLOWED METHOD", DebugHelper::ROBOT_MODEL);
00174         MILDRobotModel::initMapHelper();
00175         SimpleVector3 pos(position.x, position.y, position.z);
00176         int8_t occupancyValue = mMapHelperPtr->getRaytracingMapOccupancyValue(pos);
00177         mDebugHelperPtr->writeNoticeably("ENDING IS-POSITION-ALLOWED METHOD", DebugHelper::ROBOT_MODEL);
00178         return mMapHelperPtr->isOccupancyValueAcceptable(occupancyValue);
00179     }
00180 
00181     void MILDRobotModel::initMapHelper() {
00182         if (mMapHelperPtr == nullptr)
00183         {
00184             mDebugHelperPtr->writeNoticeably("INIT MAP_HELPER IN MILDRobotModel", DebugHelper::ROBOT_MODEL);
00185             mMapHelperPtr = MapHelperPtr(new MapHelper());
00186             ros::NodeHandle n(ros::this_node::getName());
00187             double colThresh;
00188             n.param("colThresh", colThresh, 40.0);
00189             mDebugHelperPtr->write(std::stringstream() << "colThresh: " << colThresh, DebugHelper::PARAMETERS);
00190             mMapHelperPtr->setCollisionThreshold(colThresh);
00191             mDebugHelperPtr->writeNoticeably("INIT MAP_HELPER IN MILDRobotModel DONE", DebugHelper::ROBOT_MODEL);
00192         }
00193     }
00194 
00195     bool MILDRobotModel::isPoseReachable(const SimpleVector3 &position, const SimpleQuaternion &orientation)
00196     {
00197         SimpleVector3 visualAxis = MathHelper::getVisualAxis(orientation);
00198                 SimpleSphereCoordinates sphereCoords = MathHelper::convertC2S(visualAxis);
00199 
00200                 return (mTiltLimits.get<0>() <= sphereCoords[1] && sphereCoords[1] <= mTiltLimits.get<1>());
00201         }
00202 
00203     bool MILDRobotModel::isPositionReachable(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition)
00204     {
00205         mDebugHelperPtr->writeNoticeably("STARTING IS-POSITION-REACHABLE METHOD", DebugHelper::ROBOT_MODEL);
00206 
00207         nav_msgs::Path path = getNavigationPath(sourcePosition, targetPosition);
00208 
00209         if (path.poses.empty())
00210         {
00211             mDebugHelperPtr->writeNoticeably("ENDING IS-POSITION-REACHABLE METHOD", DebugHelper::ROBOT_MODEL);
00212             return false;
00213         }
00214 
00215         int lastPose = path.poses.size()-1;
00216         float distanceToLastPoint = sqrt(pow(targetPosition.x - path.poses[lastPose].pose.position.x, 2) + pow(targetPosition.y  - path.poses[lastPose].pose.position.y, 2));
00217         mDebugHelperPtr->write(std::stringstream() << "Target: " << targetPosition.x << ", " << targetPosition.y, DebugHelper::ROBOT_MODEL);
00218         mDebugHelperPtr->write(std::stringstream() << "Actual position: " << path.poses[lastPose].pose.position.x << ", " << path.poses[lastPose].pose.position.y,
00219                     DebugHelper::ROBOT_MODEL);
00220         mDebugHelperPtr->writeNoticeably("ENDING IS-POSITION-REACHABLE METHOD", DebugHelper::ROBOT_MODEL);
00221         return distanceToLastPoint < 0.01f;
00222     }
00223 
00224     float MILDRobotModel::getBase_TranslationalMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
00225     {
00226         MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
00227         MILDRobotStatePtr targetMILDRobotState = boost::static_pointer_cast<MILDRobotState>(targetRobotState);
00228 
00229         float distance ;
00230         geometry_msgs::Point sourcePoint, targetPoint;
00231         sourcePoint.x = sourceMILDRobotState->x;
00232         sourcePoint.y = sourceMILDRobotState->y;
00233         sourcePoint.z = 0;
00234         targetPoint.x = targetMILDRobotState->x;
00235         targetPoint.y = targetMILDRobotState->y;
00236         targetPoint.z = 0;
00237 
00238         distance = getDistance(sourcePoint, targetPoint);
00239 
00240         float movementCosts = std::exp(-pow((distance-0.0), 2.0)/(2.0*pow(mSigma, 2.0))); // [0, 1]
00241         return movementCosts;
00242     }
00243 
00244     float MILDRobotModel::getPTU_PanMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
00245     {
00246         MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
00247         MILDRobotStatePtr targetMILDRobotState = boost::static_pointer_cast<MILDRobotState>(targetRobotState);
00248 
00249         float panDiff = targetMILDRobotState->pan - sourceMILDRobotState->pan;
00250 
00251         float panSpan = mPanLimits.get<1>() - mPanLimits.get<0>();
00252 
00253         if (panSpan == 0)
00254             return 1.0;
00255 
00256         float ptuPanCosts = fabs(panDiff)/ panSpan;
00257 
00258         return 1.0 - ptuPanCosts;
00259     }
00260 
00261     float MILDRobotModel::getPTU_TiltMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
00262     {
00263         MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
00264         MILDRobotStatePtr targetMILDRobotState = boost::static_pointer_cast<MILDRobotState>(targetRobotState);
00265         float tiltDiff = targetMILDRobotState->tilt - sourceMILDRobotState->tilt;
00266 
00267         float tiltSpan = mTiltLimits.get<1>() - mTiltLimits.get<0>();
00268 
00269         if (tiltSpan == 0)
00270             return 1.0;
00271 
00272         float ptuTiltCosts = fabs(tiltDiff)/ tiltSpan;
00273 
00274         return 1.0 - ptuTiltCosts;
00275     }
00276 
00277     float MILDRobotModel::getBase_RotationalMovementCosts(const RobotStatePtr &sourceRobotState, const RobotStatePtr &targetRobotState)
00278     {
00279         MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
00280         MILDRobotStatePtr targetMILDRobotState = boost::static_pointer_cast<MILDRobotState>(targetRobotState);
00281 
00282         float rotationCosts;
00283 
00284         if (fabs(targetMILDRobotState->y - sourceMILDRobotState->y) < 0.00001 && fabs(targetMILDRobotState->x - sourceMILDRobotState->x) < 0.00001) {
00285             float rotDiff = targetMILDRobotState->rotation - sourceMILDRobotState->rotation;
00286 
00287             rotationCosts = std::min((float)fabs(rotDiff), (float)(2.0f*M_PI-fabs(rotDiff)))/ (2.0 * M_PI);
00288 
00289         }
00290         else {
00291             float angleBetweenPoints = std::atan2(targetMILDRobotState->y - sourceMILDRobotState->y, targetMILDRobotState->x - sourceMILDRobotState->x);
00292             if(angleBetweenPoints < 0.0) angleBetweenPoints += 2.0 * M_PI;
00293 
00294             float sourceRotDiff = sourceMILDRobotState->rotation - angleBetweenPoints;
00295             float targetRotDiff = targetMILDRobotState->rotation - angleBetweenPoints;
00296 
00297             rotationCosts = std::min((float)fabs(sourceRotDiff), (float)(2.0f*M_PI-fabs(sourceRotDiff)))
00298                                     + std::min((float)fabs(targetRotDiff), (float)(2.0f*M_PI-fabs(targetRotDiff)));
00299             rotationCosts /= 2.0 * M_PI;
00300 
00301         }
00302         return 1.0 - rotationCosts;
00303     }
00304 
00305     float MILDRobotModel::getDistance(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition)
00306     {
00307         mDebugHelperPtr->writeNoticeably("STARTING GET-DISTANCE METHOD", DebugHelper::ROBOT_MODEL);
00308         double distance;
00309         if (useGlobalPlanner) //Use global planner to calculate distance
00310         {
00311             nav_msgs::Path path;
00312             mDebugHelperPtr->write(std::stringstream() << "Calculate path from (" << sourcePosition.x << ", "
00313                                     << sourcePosition.y << ") to (" << targetPosition.x << ", "<< targetPosition.y << ")",
00314                         DebugHelper::ROBOT_MODEL);
00315 
00316             path = getNavigationPath(sourcePosition, targetPosition);
00317 
00318             if (!path.poses.empty())
00319             {
00320                 unsigned int size = path.poses.size();
00321                 distance = 0;
00322                 for (unsigned int i = 0; i < size ; i++)
00323                 {
00324                     mDebugHelperPtr->write(std::stringstream() << "Path (" << path.poses[i].pose.position.x << ", " << path.poses[i].pose.position.y << ")",
00325                                 DebugHelper::ROBOT_MODEL);
00326                 }
00327                 //Calculate distance from source point to first point in path
00328                 distance += sqrt(pow(sourcePosition.x - path.poses[0].pose.position.x, 2) + pow(sourcePosition.y - path.poses[0].pose.position.y, 2));
00329                 //Calculate path length
00330                 for (unsigned int i = 0; i < size - 1 ; i++)
00331                 {
00332                     distance += sqrt(pow(path.poses[i].pose.position.x - path.poses[i+1].pose.position.x, 2) + pow(path.poses[i].pose.position.y - path.poses[i+1].pose.position.y, 2));
00333                 }
00334             }
00335             else
00336             {
00337                 distance = -1;
00338                 ROS_ERROR("Could not get navigation path..");
00339             }
00340         }
00341         else //Use euclidean distance
00342         {
00343             distance = sqrt(pow(sourcePosition.x -targetPosition.x, 2) + pow(sourcePosition.y - targetPosition.y, 2));
00344         }
00345         mDebugHelperPtr->write(std::stringstream() << "Calculated distance: " << distance, DebugHelper::ROBOT_MODEL);
00346         mDebugHelperPtr->write(std::stringstream() << "Euclidian distance: "
00347                                 << sqrt(pow(sourcePosition.x -targetPosition.x, 2) + pow(sourcePosition.y - targetPosition.y, 2)),
00348                     DebugHelper::ROBOT_MODEL);
00349         mDebugHelperPtr->writeNoticeably("ENDING GET-DISTANCE METHOD", DebugHelper::ROBOT_MODEL);
00350         return distance;
00351     }
00352 
00353     nav_msgs::Path MILDRobotModel::getNavigationPath(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition)
00354     {
00355         return getNavigationPath(sourcePosition, targetPosition, 0, 0);
00356     }
00357 
00358     nav_msgs::Path MILDRobotModel::getNavigationPath(const geometry_msgs::Point &sourcePosition, const geometry_msgs::Point &targetPosition, double sourceRotationBase, double targetRotationBase)
00359     {
00360         mDebugHelperPtr->writeNoticeably("STARTING GET-NAVIGATION-PATH METHOD", DebugHelper::ROBOT_MODEL);
00361 
00362         nav_msgs::GetPlan srv;
00363         srv.request.start.header.frame_id = mFrameName_map;
00364         srv.request.goal.header.frame_id = mFrameName_map;
00365         srv.request.start.pose.position = sourcePosition;
00366         srv.request.goal.pose.position = targetPosition;
00367         Eigen::Quaterniond sourceRotationEigen(Eigen::AngleAxisd(sourceRotationBase,Eigen::Vector3d::UnitZ()));
00368         Eigen::Quaterniond targetRotationEigen(Eigen::AngleAxisd(targetRotationBase,Eigen::Vector3d::UnitZ()));
00369         geometry_msgs::Quaternion sourceRotation;
00370         sourceRotation.w = sourceRotationEigen.w();
00371         sourceRotation.x = sourceRotationEigen.x();
00372         sourceRotation.y = sourceRotationEigen.y();
00373         sourceRotation.z = sourceRotationEigen.z();
00374         geometry_msgs::Quaternion targetRotation;
00375         targetRotation.w = targetRotationEigen.w();
00376         targetRotation.x = targetRotationEigen.x();
00377         targetRotation.y = targetRotationEigen.y();
00378         targetRotation.z = targetRotationEigen.z();
00379         srv.request.start.pose.orientation = sourceRotation;
00380         srv.request.goal.pose.orientation = targetRotation;
00381         srv.request.tolerance = tolerance;
00382 
00383         nav_msgs::Path path;
00384         if (navigationCostClient.call(srv))
00385         {
00386             path = srv.response.plan;
00387             mDebugHelperPtr->write(std::stringstream() << "Path size:" << path.poses.size(), DebugHelper::ROBOT_MODEL);
00388         }
00389         else
00390         {
00391             ROS_ERROR("Failed to call the global planner.");
00392         }
00393 
00394         mDebugHelperPtr->writeNoticeably("ENDING GET-NAVIGATION-PATH METHOD", DebugHelper::ROBOT_MODEL);
00395         return path;
00396     }
00397 
00398     // Not fully implemented
00399     // Guideline: http://www.orocos.org/kdl/examples
00400     geometry_msgs::Pose MILDRobotModel::calculateCameraPose(const RobotStatePtr &sourceRobotState)
00401     {
00402         /*MILDRobotStatePtr sourceMILDRobotState = boost::static_pointer_cast<MILDRobotState>(sourceRobotState);
00403 
00404         urdf::Model * myModel;
00405         geometry_msgs::Pose cameraPose;
00406 
00407         tf::Transform pan(tf::Quaternion(tf::Vector3(0,0,1), sourceMILDRobotState->pan));
00408         tf::Transform tilt(tf::Quaternion(tf::Vector3(0,-1,0), sourceMILDRobotState->tilt));
00409 
00410         urdf::Model myModel;
00411         ros::Rate loop_rate(30);
00412         //geometry_msgs::Pose cameraPose;
00413 
00414         if(!myModel.initParam("/robot_description"))
00415         {
00416             ROS_ERROR("Could not get robot description.");
00417         }
00418         else
00419         {
00420             KDL::Tree my_tree;
00421             if (!kdl_parser::treeFromUrdfModel(myModel, my_tree))
00422             {
00423                    ROS_ERROR("Failed to construct kdl tree");
00424             }
00425             else
00426             {
00427                  KDL::Chain chain;
00428                  my_tree.getChain(myModel.getRoot()->name, "mount_to_camera_left", chain);
00429                  ChainFkSolverPos_recursive fksolver = ChainFkSolverPos_recursive(chain);
00430 
00431 
00432                  //robot_state_publisher::RobotStatePublisher* publisher = new robot_state_publisher::RobotStatePublisher(my_tree);
00433                  //my_tree.getSegment()
00434 
00435                  typedef std::map<std::string, boost::shared_ptr<urdf::Joint> > joint_map;
00436 
00437                  std::map<std::string, double> positions;
00438                  joint_map joints = myModel.joints_;
00439 
00440                  for(joint_map::const_iterator it =  joints.begin(); it !=  joints.end(); ++it)
00441                  {
00442                     std::string name = it->first;
00443                     urdf::Joint* joint = it->second.get();
00444                     //joint->dynamics.
00445                     mDebugHelperPtr->write(name, DebugHelper::ROBOT_MODEL);
00446                     if(joint->type==urdf::Joint::REVOLUTE || joint->type==urdf::Joint::CONTINUOUS || joint->type==urdf::Joint::PRISMATIC) positions[name] = 0;
00447                  }
00448                  while (ros::ok())
00449                  {
00450                      //publisher->publishTransforms(positions, ros::Time::now());
00451 
00452                      // Process a round of subscription messages
00453                      ros::spinOnce();
00454 
00455                      // This will adjust as needed per iteration
00456                      loop_rate.sleep();
00457                  }
00458              }
00459         } */
00460         geometry_msgs::Pose myPose;
00461         return myPose;
00462     }
00463 }
00464 


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