ExternalObsPoint.cpp
Go to the documentation of this file.
00001 /*
00002  * ExternalObsPoint.cpp
00003  *
00004  *  Created on: Dec 16, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <obs_providers/ExternalObsPoint.hpp>
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 
00012 // Declare
00013 PLUGINLIB_DECLARE_CLASS(tk_obstacle, ExternalObsPoint, telekyb_obs::ExternalObsPoint, TELEKYB_NAMESPACE::ObstacleProvider);
00014 
00015 namespace telekyb_obs {
00016 
00017 ExternalObsPointOptions::ExternalObsPointOptions()
00018         : OptionContainer("ExternalObsPoint")
00019 {
00020         tObsTransformTopicNames = addOption< std::vector<std::string> >("tObsTransformTopicNames",
00021                         "TopicName of Obstacle Transform Topic",std::vector<std::string>(),true,true);
00022         tObsRadius = addOption< std::vector<double> >("tObsRadius",
00023                         "TopicName of Obstacle Transform Topic",std::vector<double>(),false,true);
00024 
00025         Eigen::Matrix3d m = Eigen::Matrix3d::Zero();
00026         m.diagonal() << 1.0,-1.0,-1.0;
00027         tObsTranformConvMatrix = addOption<Eigen::Matrix3d>("tObsTranformConvMatrix",
00028                         "Conversion Matrix applied to TransformPoint. (Def: Vicon to NED)", m,false,true);
00029 }
00030 
00031 ExternalObsPoint::ExternalObsPoint()
00032         : ObstacleProvider("tk_obstacle/ExternalObsPoint")
00033 {
00034 
00035 }
00036 
00037 ExternalObsPoint::~ExternalObsPoint()
00038 {
00039         // free
00040         for (unsigned int i = 0; i < subscribers.size(); ++i) {
00041                 delete subscribers[i];
00042         }
00043 }
00044 
00045 // called directly after Creation
00046 void ExternalObsPoint::initialize()
00047 {
00048         ros::NodeHandle nodeHandle(ROSModule::Instance().getMainNodeHandle());
00049         transformTopicNames = options.tObsTransformTopicNames->getValue();
00050 
00051         obstacleRadii = options.tObsRadius->getValue();
00052         if (obstacleRadii.size() != transformTopicNames.size()) {
00053                 ROS_WARN_STREAM(options.tObsRadius->getNSName() << " length not equal to "
00054                                 << options.tObsTransformTopicNames->getNSName() << "! Adjusting!");
00055                 obstacleRadii.resize(transformTopicNames.size(), 0.0);
00056         }
00057 
00058         subscribers.resize(transformTopicNames.size());
00059 
00060         for (unsigned int i = 0; i < transformTopicNames.size(); ++i) {
00061                 ROS_WARN_STREAM("Subscribing to " << transformTopicNames[i]);
00062                 subscribers[i] = new GenericSubscriber<geometry_msgs::PoseStamped>(nodeHandle, transformTopicNames[i],1);
00063         }
00064 
00065 //      obsTranformSub = nodeHandle.subscribe<geometry_msgs::TransformStamped>(
00066 //                      options.tObsTransformTopicName->getValue(),1, &ExternalObsPoint::obsPointCB, this);
00067 }
00068 
00069 // called right before destruction
00070 void ExternalObsPoint::destroy()
00071 {
00072 //      obsTranformSub.shutdown();
00073 }
00074 
00075 
00076 void ExternalObsPoint::getObstaclePoints(const TKState& lastState, std::vector<Position3D>& obstaclePoints) const
00077 {
00078         for (unsigned int i = 0; i < subscribers.size(); ++i) {
00079                 geometry_msgs::PoseStamped msg = subscribers[i]->getLastMsg();
00080                 Eigen::Vector3d obsPoint(msg.pose.position.x, msg.pose.position.y, msg.pose.position.z);
00081                 // Convert.
00082                 obsPoint = options.tObsTranformConvMatrix->getValue() * obsPoint;
00083 
00084                 if (obstacleRadii[i] > 0.0) {
00085                         // Adjust point
00086                         Eigen::Vector3d obsVector = lastState.position - obsPoint;
00087 
00088                         if (obsVector.norm() < obstacleRadii[i]) {
00089                                 ROS_WARN("Object inside Obstaclesphere!!!");
00090                                 obstaclePoints.push_back(obsPoint + obsVector * 0.9); // go 10% deeper.
00091                         } else {
00092                                 // Point on Sphere
00093                                 obstaclePoints.push_back(obsPoint + obsVector.normalized() * obstacleRadii[i]);
00094                         }
00095                 } else {
00096                         obstaclePoints.push_back(obsPoint);
00097                 }
00098         }
00099 }
00100 
00101 //void ExternalObsPoint::obsPointCB(const geometry_msgs::TransformStamped::ConstPtr& msg)
00102 //{
00103 //      Position3D rawPosition;
00104 //      rawPosition(0) = msg->transform.translation.x;
00105 //      rawPosition(1) = msg->transform.translation.y;
00106 //      rawPosition(2) = msg->transform.translation.z;
00107 //
00108 //      boost::mutex::scoped_lock obsPointLock(obsPointMutex);
00109 //      obsPoint = options.tObsTranformConvMatrix->getValue() * rawPosition;
00110 //}
00111 
00112 } /* namespace telekyb_obs */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


tk_obstacle
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:22