Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <obs_providers/ExternalObsPoint.hpp>
00009
00010 #include <telekyb_base/ROS.hpp>
00011
00012
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
00040 for (unsigned int i = 0; i < subscribers.size(); ++i) {
00041 delete subscribers[i];
00042 }
00043 }
00044
00045
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
00066
00067 }
00068
00069
00070 void ExternalObsPoint::destroy()
00071 {
00072
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
00082 obsPoint = options.tObsTranformConvMatrix->getValue() * obsPoint;
00083
00084 if (obstacleRadii[i] > 0.0) {
00085
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);
00091 } else {
00092
00093 obstaclePoints.push_back(obsPoint + obsVector.normalized() * obstacleRadii[i]);
00094 }
00095 } else {
00096 obstaclePoints.push_back(obsPoint);
00097 }
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 }