Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <obs_providers/ExternalFace.hpp>
00009
00010
00011 PLUGINLIB_DECLARE_CLASS(tk_obstacle, ExternalFace, telekyb_obs::ExternalFace, TELEKYB_NAMESPACE::ObstacleProvider);
00012
00013 namespace telekyb_obs {
00014
00015 ExternalFaceOptions::ExternalFaceOptions()
00016 : OptionContainer("ExternalFace")
00017 {
00018 tInputFaces = addOption< std::vector<Eigen::Vector3d> >("tInputFaces",
00019 "Input Faces here",
00020 std::vector<Eigen::Vector3d>(),false,false);
00021 }
00022
00023 ExternalFace::ExternalFace()
00024 : ObstacleProvider("tk_obstacle/ExternalFace")
00025 {
00026 std::vector<Eigen::Vector3d> optionInput = options.tInputFaces->getValue();
00027
00028 for (unsigned int i = 0; i < optionInput.size() / 3; i++) {
00029 Face f;
00030 f.origin = optionInput[i*3 + 0];
00031 f.dir1 = optionInput[i*3 + 1];
00032 f.dir2 = optionInput[i*3 + 2];
00033 faces.push_back(f);
00034 }
00035 }
00036
00037 ExternalFace::~ExternalFace()
00038 {
00039
00040 }
00041
00042
00043 void ExternalFace::initialize()
00044 {
00045
00046 }
00047
00048
00049 void ExternalFace::destroy()
00050 {
00051
00052 }
00053
00054
00055 void ExternalFace::getObstaclePoints(const TKState& lastState, std::vector<Position3D>& obstaclePoints) const
00056 {
00057
00058 if (faces.empty()) {
00059 ROS_ERROR("Warning, no faces defined!");
00060 return;
00061 }
00062
00063 Eigen::Vector3d point = lastState.position;
00064
00065 for (unsigned int i = 0; i < faces.size(); ++i) {
00066
00067
00068 Eigen::Vector3d faceNormal = faces[i].dir1.cross(faces[i].dir2);
00069 faceNormal.normalize();
00070
00071
00072
00073 Eigen::Vector3d projectedPoint = point - ((point - faces[i].origin).dot(faceNormal) * faceNormal );
00074
00075
00076
00077 double relativePosDir1 = (faces[i].dir1.dot(projectedPoint - faces[i].origin)) / faces[i].dir1.squaredNorm();
00078 double relativePosDir2 = (faces[i].dir2.dot(projectedPoint - faces[i].origin)) / faces[i].dir2.squaredNorm();
00079
00080
00081
00082
00083 if (relativePosDir1 < 0) {
00084 projectedPoint -= relativePosDir1 * faces[i].dir1;
00085
00086 } else if (relativePosDir1 > 1.0) {
00087 projectedPoint -= (relativePosDir1 - 1.0) * faces[i].dir1;
00088 }
00089
00090
00091 if (relativePosDir2 < 0) {
00092 projectedPoint -= relativePosDir2 * faces[i].dir2;
00093
00094 } else if (relativePosDir2 > 1.0) {
00095 projectedPoint -= (relativePosDir2 - 1.0) * faces[i].dir2;
00096 }
00097
00098
00099
00100
00101 obstaclePoints.push_back(projectedPoint);
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 }
00126
00127 }