Guest User

Untitled

a guest
Oct 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. int limit_ = 5000;
  2. int i = 0;
  3. int found_ = 0;
  4.  
  5. // get the volume of the explored space
  6. Eigen::Vector3d volumeMin, volumeMax;
  7.  
  8. // OCTOMAP will provide bounding box in the MAP frame
  9. getMapBounds(&volumeMin, &volumeMax);
  10.  
  11. std::cout << "VOL MIN " << volumeMin[0] << " , " << volumeMin[1] << " , " << volumeMin[2] << std::endl;
  12.  
  13. std::cout << "VOL Max " << volumeMax[0] << " , " << volumeMax[1] << " , " << volumeMax[2] << std::endl;
  14.  
  15. unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  16. std::default_random_engine generator (seed);
  17. std::uniform_real_distribution<float> dis0 (volumeMin[0], volumeMax[0]);
  18. std::uniform_real_distribution<float> dis1(volumeMin[1], volumeMax[1]);
  19. std::uniform_real_distribution<float> dis2(volumeMin[2], volumeMax[2]);
  20.  
  21.  
  22. // iterate untilgoal reached or thershold reached
  23. while ((found_ == 0) && (i < limit_)){
  24.  
  25. float x = dis0(generator);
  26. float y = dis1(generator);
  27. float z = dis2(generator);
  28.  
  29. std::cout << "random point : " << x << " ," << y << " , " << z << std::endl;
  30.  
  31. found_ = tree_->iterate(x, y, z);
  32. i++;
  33. }
  34.  
  35. if (i >= limit_)
  36. ROS_INFO("NO SOLUTION FOUND");
  37. else
  38. tree_->smoothPath();
  39.  
  40. ROS_INFO("ITERATE CALL 1");
  41.  
  42. // In this function a new configuration is sampled and added to the tree.
  43. StateVec newState;
  44.  
  45. newState[0] = x;
  46. newState[1] = y;
  47. newState[2] = z;
  48.  
  49. // Find nearest neighbour
  50. kdres * nearest = kd_nearest3(kdTree_, newState.x(), newState.y(), newState.z());
  51.  
  52. if (kd_res_size(nearest) <= 0) {
  53. kd_res_free(nearest);
  54. return 0;
  55. }
  56.  
  57. // create a new node and fill x,y,z value
  58. Node<StateVec> * newParent = (volumetric_mapping::Node<StateVec> *) kd_res_item_data(nearest);
  59.  
  60. // Check for collision of new connection plus some overshoot distance.
  61. Eigen::Vector3d origin(newParent->state_[0], newParent->state_[1], newParent->state_[2]);
  62.  
  63. std::cout << "Origin (Parent) : " << origin[0] << " , " << origin[1] << " , " << origin[2] << std::endl;
  64.  
  65. Eigen::Vector3d direction(newState[0] - origin[0], newState[1] - origin[1], newState[2] - origin[2]);
  66.  
  67. //stepping
  68. if (direction.norm() > params_.extensionRange_) {
  69. direction = params_.extensionRange_ * direction.normalized();
  70. }
  71.  
  72. newState[0] = origin[0] + direction[0];
  73. newState[1] = origin[1] + direction[1];
  74. newState[2] = origin[2] + direction[2];
  75.  
  76. // add the random point to the marker - reference frame map
  77. geometry_msgs::Point p;
  78. p.x = newState[0];
  79. p.y = newState[1];
  80. p.z = newState[2];
  81. marker.points.push_back(p);
  82. nh_.publish(marker);
  83.  
  84. // check collision
  85. // bounding box represents the box in which the drone is contained - parameter to set! information available into resource/area_exploration.yaml
  86. // see how to combine them with octomapManager and so on
  87. if (volumetric_mapping::OctomapManager::CellStatus::kFree
  88. == manager_->getLineStatusBoundingBox(origin,
  89. direction + origin /*+ direction.normalized() * params_.dOvershoot*/,
  90. params_.boundingBox_)) {
  91.  
  92. std::cout << " NO COLLISION" << std::endl;
  93.  
  94. // Sample the new orientation
  95. newState[3] = 2.0 * M_PI * (((double) rand()) / ((double) RAND_MAX) - 0.5);
  96.  
  97. // Create new node and insert into tree
  98. Node<StateVec> * newNode = new volumetric_mapping::Node<StateVec>;
  99. newNode->state_ = newState;
  100. newNode->parent_ = newParent;
  101. newNode->distance_ = newParent->distance_ + direction.norm();
  102. newParent->children_.push_back(newNode);
  103.  
  104. // insert the new node
  105. kd_insert3(kdTree_, newState.x(), newState.y(), newState.z(), newNode);
  106.  
  107. std::cout << "Insert new node : " << newState.x() << " , " << newState.y() << " , " << newState.z() << std::endl;
  108.  
  109. // Display new node
  110. publishNode(newNode);
  111.  
  112. ROS_INFO("NEW NODE!");
  113.  
  114. counter_++;
  115.  
  116. Eigen::Vector3d origin2_(newState[0], newState[1], newState[2]);
  117. Eigen::Vector3d goal_(goalNode_->state_[0], goalNode_->state_[1], goalNode_->state_[2]);
  118.  
  119. // at this stage, we check if there is a straight line between this node and the goal which is free of obstacle
  120. if (volumetric_mapping::OctomapManager::CellStatus::kFree
  121. == manager_->getLineStatus(origin2_, goal_)) {
  122. // insert goal node in the tree
  123. newNode->children_.push_back(goalNode_);
  124. goalNode_->parent_ = newNode;
  125.  
  126. // if so setup goalIsReached
  127. goalReached_ = 1;
  128. // Display new node (not sure here it is really useful)
  129. publishNode(goalNode_);
  130.  
  131. ROS_INFO("-----------------------GOAL REACHED!--------------------------");
  132. }
  133.  
  134. }
  135.  
  136. if (goalReached_)
  137. showPath(goalNode_);
  138.  
  139. return goalReached_;
Add Comment
Please, Sign In to add comment