| 97 | } |
| 98 | |
| 99 | list<GraphNode::Ptr> TopologyPRM::createGraph(Eigen::Vector3d start, Eigen::Vector3d end) { |
| 100 | // std::cout << "[Topo]: searching----------------------" << std::endl; |
| 101 | |
| 102 | /* init the start, end and sample region */ |
| 103 | graph_.clear(); |
| 104 | // collis_.clear(); |
| 105 | |
| 106 | GraphNode::Ptr start_node = GraphNode::Ptr(new GraphNode(start, GraphNode::Guard, 0)); |
| 107 | GraphNode::Ptr end_node = GraphNode::Ptr(new GraphNode(end, GraphNode::Guard, 1)); |
| 108 | |
| 109 | graph_.push_back(start_node); |
| 110 | graph_.push_back(end_node); |
| 111 | |
| 112 | // sample region |
| 113 | sample_r_(0) = 0.5 * (end - start).norm() + sample_inflate_(0); |
| 114 | sample_r_(1) = sample_inflate_(1); |
| 115 | sample_r_(2) = sample_inflate_(2); |
| 116 | |
| 117 | // transformation |
| 118 | translation_ = 0.5 * (start + end); |
| 119 | |
| 120 | Eigen::Vector3d xtf, ytf, ztf, downward(0, 0, -1); |
| 121 | xtf = (end - translation_).normalized(); |
| 122 | ytf = xtf.cross(downward).normalized(); |
| 123 | ztf = xtf.cross(ytf); |
| 124 | |
| 125 | rotation_.col(0) = xtf; |
| 126 | rotation_.col(1) = ytf; |
| 127 | rotation_.col(2) = ztf; |
| 128 | |
| 129 | int node_id = 1; |
| 130 | |
| 131 | /* ---------- main loop ---------- */ |
| 132 | int sample_num = 0; |
| 133 | double sample_time = 0.0; |
| 134 | Eigen::Vector3d pt; |
| 135 | ros::Time t1, t2; |
| 136 | while (sample_time < max_sample_time_ && sample_num < max_sample_num_) { |
| 137 | t1 = ros::Time::now(); |
| 138 | |
| 139 | pt = getSample(); |
| 140 | ++sample_num; |
| 141 | double dist; |
| 142 | Eigen::Vector3d grad; |
| 143 | // edt_environment_->evaluateEDTWithGrad(pt, -1.0, dist, grad); |
| 144 | dist = edt_environment_->evaluateCoarseEDT(pt, -1.0); |
| 145 | if (dist <= clearance_) { |
| 146 | sample_time += (ros::Time::now() - t1).toSec(); |
| 147 | continue; |
| 148 | } |
| 149 | |
| 150 | /* find visible guard */ |
| 151 | vector<GraphNode::Ptr> visib_guards = findVisibGuard(pt); |
| 152 | if (visib_guards.size() == 0) { |
| 153 | GraphNode::Ptr guard = GraphNode::Ptr(new GraphNode(pt, GraphNode::Guard, ++node_id)); |
| 154 | graph_.push_back(guard); |
| 155 | } else if (visib_guards.size() == 2) { |
| 156 | /* try adding new connection between two guard */ |
nothing calls this directly
no test coverage detected