From 14c33e92bd6de9d9abf623efe7cec875b4833e0b Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Thu, 2 Jul 2020 01:36:41 +0530
Subject: [PATCH 01/81] Add lazy_theta_star
---
lazy_theta_star_b/CMakeLists.txt | 89 ++++
lazy_theta_star_b/global_planner_plugin.xml | 5 +
.../lazy_theta_star_b/lazy_theta_star_b.h | 141 +++++
lazy_theta_star_b/package.xml | 31 ++
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 483 ++++++++++++++++++
5 files changed, 749 insertions(+)
create mode 100644 lazy_theta_star_b/CMakeLists.txt
create mode 100644 lazy_theta_star_b/global_planner_plugin.xml
create mode 100644 lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
create mode 100644 lazy_theta_star_b/package.xml
create mode 100644 lazy_theta_star_b/src/lazy_theta_star_b.cpp
diff --git a/lazy_theta_star_b/CMakeLists.txt b/lazy_theta_star_b/CMakeLists.txt
new file mode 100644
index 0000000000..98875908c0
--- /dev/null
+++ b/lazy_theta_star_b/CMakeLists.txt
@@ -0,0 +1,89 @@
+cmake_minimum_required(VERSION 3.5)
+project(lazy_theta_star_b)
+
+set(CMAKE_C_STANDARD 99)
+set(CMAKE_CXX_STANDARD 14)
+
+
+if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ add_compile_options(-Wall -Wextra -Wpedantic -O3)
+endif()
+
+# find dependencies
+find_package(ament_cmake REQUIRED)
+find_package(rclcpp REQUIRED)
+find_package(rclcpp_action REQUIRED)
+find_package(rclcpp_lifecycle REQUIRED)
+find_package(visualization_msgs REQUIRED)
+find_package(nav2_util REQUIRED)
+find_package(nav2_msgs REQUIRED)
+find_package(builtin_interfaces REQUIRED)
+find_package(tf2_ros REQUIRED)
+find_package(nav2_costmap_2d REQUIRED)
+find_package(pluginlib REQUIRED)
+find_package(nav2_core REQUIRED)
+
+include_directories(
+ include
+)
+
+set(library_name ${PROJECT_NAME}_plugin)
+
+set(dependencies
+ rclcpp
+ rclcpp_action
+ rclcpp_lifecycle
+ std_msgs
+ visualization_msgs
+ nav2_util
+ nav2_msgs
+ builtin_interfaces
+ tf2_ros
+ nav2_costmap_2d
+ nav2_core
+ pluginlib
+ )
+
+add_library(${library_name} SHARED
+ src/lazy_theta_star_b.cpp
+ )
+
+set_target_properties(lazy_theta_star_b_plugin PROPERTIES COMPILE_FLAGS "-O3")
+ament_target_dependencies(${library_name}
+ ${dependencies}
+ )
+
+target_compile_definitions(${library_name} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
+
+pluginlib_export_plugin_description_file(nav2_core global_planner_plugin.xml)
+
+install(TARGETS ${library_name}
+ ARCHIVE DESTINATION lib
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION lib/${PROJECT_NAME}
+ )
+
+install(DIRECTORY include/
+ DESTINATION include/
+ )
+
+install(FILES global_planner_plugin.xml
+ DESTINATION share/${PROJECT_NAME}
+ )
+
+if(BUILD_TESTING)
+ find_package(ament_lint_auto REQUIRED)
+ # the following line skips the linter which checks for copyrights
+ # uncomment the line when a copyright and license is not present in all source files
+ #set(ament_cmake_copyright_FOUND TRUE)
+ # the following line skips cpplint (only works in a git repo)
+ # uncomment the line when this package is not in a git repo
+ #set(ament_cmake_cpplint_FOUND TRUE)
+ ament_lint_auto_find_test_dependencies()
+endif()
+
+
+ament_export_include_directories(include)
+ament_export_libraries(${library_name})
+ament_export_dependencies(${dependencies})
+ament_package()
diff --git a/lazy_theta_star_b/global_planner_plugin.xml b/lazy_theta_star_b/global_planner_plugin.xml
new file mode 100644
index 0000000000..39eae7f80c
--- /dev/null
+++ b/lazy_theta_star_b/global_planner_plugin.xml
@@ -0,0 +1,5 @@
+
+
+ The implementation of lazy theta_star
+
+
\ No newline at end of file
diff --git a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
new file mode 100644
index 0000000000..39a649b87f
--- /dev/null
+++ b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
@@ -0,0 +1,141 @@
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "rclcpp/rclcpp.hpp"
+
+#include "nav2_core/global_planner.hpp"
+#include "nav_msgs/msg/path.hpp"
+#include "nav2_util/robot_utils.hpp"
+#include "nav2_util/lifecycle_node.hpp"
+#include "nav2_costmap_2d/costmap_2d_ros.hpp"
+#include "nav2_costmap_2d/cost_values.hpp"
+
+namespace lazy_theta_star_b {
+ typedef int id;
+ using namespace std;
+
+#define SMALL 0.001
+#define INF_COST 10000000.0
+#define LETHAL_COST 100
+
+ template
+ struct pts {
+ ptsT x, y;
+ };
+
+ struct pos {
+ id pos_id;
+ double *g;
+ double *f;
+ };
+
+ struct tree_node {
+ int x, y;
+ double g = INF_COST;
+ double h = INF_COST;
+ id parentId;
+ int closed = 0; //0 - unexplored, 1 - closed, -1 - open
+ double f = INF_COST;
+ int counter = 0;
+ int got_here = 0;
+ };
+
+
+ class LazyThetaStarB : public nav2_core::GlobalPlanner {
+
+ public:
+
+ int lethal_cost = LETHAL_COST;
+
+ std::shared_ptr tf_;
+ nav2_util::LifecycleNode::SharedPtr node_;
+ nav2_costmap_2d::Costmap2D *costmap_;
+ std::string global_frame_, name_;
+
+ double interpolation_dist;
+ int how_many_corners_;
+ pts src_{}, dst_{};
+
+ //stores the cell data
+ vector data;
+
+ //stores the raw path given by the planner on the basis of their index in the vector data
+ vector path;
+ nav_msgs::msg::Path global_path;
+
+ // is the priority queue
+ vector pq;
+ int sizeX = 0;
+ int sizeY = 0;
+ int how_many_corners;
+ pts src{}, dst{};
+
+
+ void configure(
+ rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
+ std::string name, std::shared_ptr tf,
+ std::shared_ptr costmap_ros) override;
+
+ void cleanup() override;
+
+ void activate() override;
+
+ void deactivate() override;
+
+ nav_msgs::msg::Path createPlan(
+ const geometry_msgs::msg::PoseStamped &start,
+ const geometry_msgs::msg::PoseStamped &goal) override;
+
+
+ //The Line of Sight checking algorithm, takes in the points, and follows the line joining points
+ bool los_check(int x0, int y0, int x1, int y1);
+
+ //Gives out the Euclidean Distance
+ double dist(double ax, double ay, double bx, double by) {
+ return sqrt(pow(ax - bx, 2) + pow(ay - by, 2));
+ }
+
+ //to pop the minimum value of the queue, it is ever so slightly faster than the stl one,
+ //based on the implementation by Peter Sanders (2000)
+ void binary_heap_del_min();
+
+ //to compare between values in thet priority queue
+ static bool comp(pos p1, pos p2) {
+ return (*(p1.f) != *(p2.f)) ? (*(p1.f) > *(p2.f)) : (*(p1.g) > *(p2.g));
+ }
+
+ nav_msgs::msg::Path linearInterpolation(vector lp, double dist_bw_points);
+
+ pts tf_map_to_world(int x, int y) ;
+
+ bool withinLimits(int x, int y);
+
+ bool isSafe(int cx, int cy);
+
+ void push_to_pq(id id_this);
+
+ void clearRobotCell(int mx, int my);
+
+ void backtrace(vector *waypt, id curr_id);
+
+ //stores the index at which the node data is stored for a particular co-ordinate
+ vector posn;
+
+ //it sets/resets all the values within posn to 0
+ void initializePosn();
+
+ //functions used to maintain indices
+ void addIndex(int cx, int cy, id index);
+ id getIndex(int cx, int cy);
+
+ //nav_msgs::msg::Path AutoLinearInterpolation(vector lp);
+ };
+
+}
+
diff --git a/lazy_theta_star_b/package.xml b/lazy_theta_star_b/package.xml
new file mode 100644
index 0000000000..7e06686661
--- /dev/null
+++ b/lazy_theta_star_b/package.xml
@@ -0,0 +1,31 @@
+
+
+
+ lazy_theta_star_b
+ 0.0.1
+ TODO: Package description
+ anshu-man
+ Apache-2.0
+
+ ament_cmake
+ rclcpp
+ nav2_core
+ rclcpp_action
+ rclcpp_lifecycle
+ std_msgs
+ visualization_msgs
+ nav2_util
+ nav2_msgs
+ builtin_interfaces
+ tf2_ros
+ nav2_costmap_2d
+ pluginlib
+
+ ament_lint_auto
+ ament_lint_common
+
+
+ ament_cmake
+
+
+
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
new file mode 100644
index 0000000000..0f58aa2c81
--- /dev/null
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -0,0 +1,483 @@
+#include "lazy_theta_star_b/lazy_theta_star_b.h"
+#include "nav2_util/node_utils.hpp"
+#include "chrono"
+
+namespace lazy_theta_star_b {
+ void LazyThetaStarB::configure(rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
+ std::string name, std::shared_ptr tf,
+ std::shared_ptr costmap_ros) {
+ node_ = parent;
+ name_ = name;
+ tf_ = tf;
+ costmap_ = costmap_ros->getCostmap();
+ global_frame_ = costmap_ros->getGlobalFrameID();
+
+ nav2_util::declare_parameter_if_not_declared(
+ node_, name_ + ".how_many_corners", rclcpp::ParameterValue(
+ 8));
+
+ node_->get_parameter(name_ + ".how_many_corners", how_many_corners_);
+
+ if (how_many_corners_ != 8)
+ how_many_corners_ = 4;
+
+ nav2_util::declare_parameter_if_not_declared(
+ node_, name_ + ".interpolation_dist", rclcpp::ParameterValue(
+ 0.1));
+
+ node_->get_parameter(name_ + ".interpolation_dist", interpolation_dist);
+
+ }
+
+ void LazyThetaStarB::cleanup() {
+ RCLCPP_INFO(
+ node_->get_logger(), "CleaningUp plugin %s of type LazyThetaStarB",
+ name_.c_str());
+ }
+
+ void LazyThetaStarB::activate() {
+ RCLCPP_INFO(
+ node_->get_logger(), "Activating plugin %s of type LazyThetaStarB",
+ name_.c_str());
+ }
+
+ void LazyThetaStarB::deactivate() {
+ RCLCPP_INFO(
+ node_->get_logger(), "Deactivating plugin %s of type LazyThetaStarB",
+ name_.c_str());
+ }
+
+ nav_msgs::msg::Path LazyThetaStarB::createPlan(
+ const geometry_msgs::msg::PoseStamped &start,
+ const geometry_msgs::msg::PoseStamped &goal) {
+
+
+ RCLCPP_INFO(
+ node_->get_logger(), "Path Search Begins");
+
+ costmap_->worldToMap(start.pose.position.x, start.pose.position.y, reinterpret_cast(src.x),
+ reinterpret_cast(src.y));
+
+
+ costmap_->worldToMap(goal.pose.position.x, goal.pose.position.y, reinterpret_cast(dst.x),
+ reinterpret_cast(dst.y));
+ src.x = int(src.x);
+ src.y = int(src.y);
+
+ dst.x = int(dst.x);
+ dst.y = int(dst.y);
+
+ data.clear();
+ pq.clear();
+ path.clear();
+ posn.clear();
+ lethal_cost = LETHAL_COST;
+
+ sizeX = costmap_->getSizeInCellsX();
+ sizeY = costmap_->getSizeInCellsY();
+
+ //has been added so that if the robot is stuck at a place with costmap cost higher than 127, then only for that run, the planner be able to give a path
+ if (costmap_->getCost(src.x, src.y) >= lethal_cost && costmap_->getCost(src.x, src.y) <= 253) {
+ lethal_cost = costmap_->getCost(src.x, src.y);
+ }
+
+ initializePosn();
+ data.reserve(int((sizeX) * (sizeY) * 0.01));
+
+ clearRobotCell(src.x, src.y);
+
+ RCLCPP_INFO(
+ node_->get_logger(), "GOT THE SOURCE AND DESTINATION ------ %i, %i && %i, %i",
+ src.x, src.y, dst.x, dst.y);
+
+
+ if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
+ !withinLimits(dst.x, dst.y)) {
+ RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE!!!!!!");
+ global_path.poses.clear();
+ return global_path;
+
+ }
+
+ data.push_back({(src.x), (src.y), 0, dist(src.x, src.y, dst.x, dst.y), 0, -1,
+ dist(src.x, src.y, dst.x, dst.y)});
+
+ addIndex(src.x, src.y, 0);
+
+ pq.push_back({0, &(data[0].g), &(data[0].f)});
+ //added as a buffer, since my binary_heap_del_min starts from the index 1 instead of 0
+ pq.push_back({0, &(data[0].g), &(data[0].f)});
+
+
+ //The algorithm begins here
+ id curr_id = 0;
+ id id_gen = 1;
+ id last_id = 0;
+ int cy;
+ int cx;
+ cx = (data[curr_id].x);
+ cy = (data[curr_id].y);
+
+ if (!los_check(src.x, src.y, dst.x, dst.y)) {
+
+ while (pq.size() > 1) {
+
+ data[curr_id].counter++;
+
+ // The condition if current point is the destination
+ if (cx == dst.x && cy == dst.y) {
+ if (los_check(cx, cy, data[data[last_id].parentId].x, data[data[last_id].parentId].y)) {
+ data[curr_id].parentId = data[last_id].parentId;
+ data[curr_id].g = data[data[last_id].parentId].g;
+ data[curr_id].f = data[data[last_id].parentId].f;
+ break;
+ } else {
+ data[curr_id].parentId = last_id;
+ data[curr_id].g = data[last_id].g;
+ data[curr_id].f = data[last_id].f;
+ break;
+ }
+ }
+
+ //generates the child nodes location
+ int moves[8][2] = {{cx, cy + 1},
+ {cx + 1, cy},
+ {cx, cy - 1},
+ {cx - 1, cy},
+ {cx + 1, cy + 1},
+ {cx + 1, cy - 1},
+ {cx - 1, cy - 1},
+ {cx - 1, cy + 1}};
+
+ if (how_many_corners != 8) {
+ how_many_corners = 4;
+ }
+
+ int mx, my;
+ id m_id;
+ id curr_par = (data[curr_id].parentId);
+
+ //lazy checking for the parent
+ if (!(los_check(cx, cy, data[curr_par].x, data[curr_par].y)) && isSafe(cx, cy) &&
+ isSafe(data[curr_par].x, data[curr_par].y)) {
+
+ double min_dist = INF_COST;
+ int min_dist_id = curr_par;
+
+ for (int i = 0; i < how_many_corners; i++) {
+ mx = moves[i][0];
+ my = moves[i][1];
+ if (withinLimits(mx, my)) {
+ m_id = getIndex(mx, my);
+ if (m_id != 0) {
+ if (data[m_id].f < min_dist) {
+ min_dist = data[m_id].f;
+ min_dist_id = m_id;
+ }
+ }
+ }
+ data[curr_id].parentId = min_dist_id;
+ data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
+ data[curr_id].f = data[curr_id].g + data[curr_id].h;
+ }
+ }
+ curr_par = data[curr_id].parentId;
+
+ for (int i = 0; i < how_many_corners; i++) {
+ mx = moves[i][0];
+ my = moves[i][1];
+
+ if (mx == data[curr_par].x && my == data[curr_par].y)
+ continue;
+
+ if (withinLimits(mx, my)) {
+ double g_cost = data[curr_par].g + dist(mx, my, data[curr_par].x, data[curr_par].y);
+ double h_cost, cal_cost;
+ m_id = getIndex(mx, my);
+ if (m_id == 0 && isSafe(mx, my)) {
+ h_cost = dist(mx, my, dst.x, dst.y);
+ cal_cost = g_cost + h_cost;
+ data.push_back({int(mx), int(my), g_cost, h_cost, curr_par, -1, cal_cost});
+ addIndex(mx, my, id_gen);
+ push_to_pq(id_gen);
+ id_gen++;
+ continue;
+ } else if (m_id != 0) {
+ h_cost = data[m_id].h;
+ cal_cost = g_cost + h_cost;
+ if (data[m_id].f > cal_cost) {
+ data[m_id].g = g_cost;
+ data[m_id].f = cal_cost;
+ data[m_id].parentId = curr_par;
+ if (data[m_id].closed == 1) {
+ data[m_id].closed = -1;
+ push_to_pq(m_id);
+ }
+ }
+ continue;
+ }
+ }
+ }
+
+ last_id = curr_id;
+ do {
+ curr_id = pq[1].pos_id;
+ cx = data[curr_id].x;
+ cy = data[curr_id].y;
+ } while (!isSafe(cx, cy));
+ binary_heap_del_min();
+ data[curr_id].closed = -1;
+
+ }
+
+ } else {
+ RCLCPP_INFO(node_->get_logger(), "Straight Path");
+ data.push_back({(dst.x), (dst.y), dist(cx, cy, src.x, src.y), 0, 0});
+ curr_id = 1;
+ }
+
+ RCLCPP_INFO(node_->get_logger(), "REACHED DEST %i, %i", dst.x, dst.y);
+
+ backtrace(&path, curr_id);
+
+ cout << data.size() << '\n';
+
+ cout << "Publishing the Path" << '\n';
+
+ //reset all the values
+ global_path = linearInterpolation(path, interpolation_dist);
+
+ geometry_msgs::msg::PoseStamped p_end;
+ p_end.pose.position.x = goal.pose.position.x;
+ p_end.pose.position.y = goal.pose.position.y;
+ p_end.header.stamp = node_->now();
+ p_end.header.frame_id = global_frame_;
+ global_path.poses.push_back(p_end);
+
+ return global_path;
+ }
+
+ void LazyThetaStarB::initializePosn() {
+ if (pq.size() != abs(sizeX * sizeY)) {
+ for (int i = 0; i < sizeY * sizeX; i++) {
+ posn.push_back(0);
+ }
+ } else {
+ for (int i = 0; i < sizeY * sizeX; i++) {
+ posn[i] = 0;
+ }
+ }
+ }
+
+ void LazyThetaStarB::addIndex(int cx, int cy, id index) {
+ posn[sizeX * cy + cx] = index;
+ }
+
+ id LazyThetaStarB::getIndex(int cx, int cy) {
+ return posn[sizeX * cy + cx];
+ }
+
+ void LazyThetaStarB::backtrace(vector *waypt, id curr_id) {
+ vector waypt_rev;
+ do {
+ waypt_rev.push_back(curr_id);
+ curr_id = data[curr_id].parentId;
+ } while (curr_id != 0);
+ waypt_rev.push_back(0);
+
+ for (int i = waypt_rev.size() - 1; i >= 0; i--) {
+ waypt->push_back(waypt_rev[i]);
+ }
+
+ }
+
+ void LazyThetaStarB::binary_heap_del_min() {
+ int hole = 1;
+ int succ = 2, size = pq.size() - 1, sz = size;
+ //the main bottom up part where it compares and assigns the smallest value to the hole
+ //remember that for this part the heap starts at index 1
+ while (succ < sz) {
+ double k1 = *(pq[succ].f);
+ double k2 = *(pq[succ + 1].f);
+ if (k1 > k2) {
+ succ++;
+ pq[hole] = pq[succ];
+ } else {
+ pq[hole] = pq[succ];
+ }
+ hole = succ;
+ succ <<= 1;
+ }
+ //this part checks if the value to be used to fill the last row's hole is small or not
+ //if not small then it slides the small value up till it reaches the apt position
+ double bubble = *(pq[sz].f);
+ int pred = hole >> 1;
+ while (*(pq[pred].f) > bubble) {
+ pq[hole] = pq[pred];
+ hole = pred;
+ pred >>= 1;
+ }
+ //this part simply assigns the last value in the heap to the hole after checking it
+ //for maintaining the heap data structure
+ pq[hole] = pq[sz];
+ pq.pop_back();
+ }
+
+ bool LazyThetaStarB::los_check(int x0, int y0, int x1, int y1) {
+
+ int dy = y1 - y0, dx = x1 - x0, f = 0;
+ int sx, sy;
+
+ if (dy < 0) {
+ dy = -dy;
+ sy = -1;
+ } else {
+ sy = 1;
+ }
+
+ if (dx < 0) {
+ dx = -dx;
+ sx = -1;
+ } else {
+ sx = 1;
+ }
+
+ if (dx >= dy) {
+ while (x0 != x1) {
+ f += dy;
+ if (f >= dx) {
+ if (!isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
+ return false;
+ y0 += sy;
+ f -= dx;
+ }
+ if (f != 0 && !isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
+ return false;
+ if (dy == 0 && !isSafe(x0 + (sx - 1) / 2, y0) && !isSafe(x0 + (sx - 1) / 2, y0 - 1))
+ return false;
+ x0 += sx;
+ }
+ } else {
+ while (y0 != y1) {
+ f = f + dx;
+ if (f >= dy) {
+ if (!isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
+ return false;
+ x0 += sx;
+ f -= dy;
+ }
+ if (f != 0 && !isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
+ return false;
+ if (dx == 0 && !isSafe(x0, y0 + (sy - 1) / 2) && !isSafe(x0 - 1, y0 + (sy - 1) / 2))
+ return false;
+ y0 += sy;
+ }
+ }
+
+ return true;
+
+ }
+
+ void LazyThetaStarB::push_to_pq(id id_this) {
+ pq.push_back({id_this, &(data[id_this].g), &(data[id_this].f)});
+ push_heap(pq.begin() + 1, pq.end(), comp);
+ }
+
+ bool LazyThetaStarB::isSafe(int cx, int cy) {
+ return (costmap_->getCost(cx, cy) < lethal_cost);
+ }
+
+ bool LazyThetaStarB::withinLimits(int x, int y) {
+ return (x > 0 && x <= sizeX && y > 0 && y <= sizeY);
+ }
+
+ pts LazyThetaStarB::tf_map_to_world(int x, int y) {
+ pts pt{};
+ pt.x = double(
+ costmap_->getOriginX() + (x + 0.5) * costmap_->getResolution());
+ pt.y = double(
+ costmap_->getOriginY() + (y + 0.5) * costmap_->getResolution());
+ // 0.5 added to display the points at the centre of the grid cell
+ return pt;
+ }
+
+ nav_msgs::msg::Path LazyThetaStarB::linearInterpolation(vector lp, double dist_bw_points) {
+
+ nav_msgs::msg::Path pa;
+ pa.header.frame_id = "map";
+ for (int i = 0; i < int(lp.size() - 1); i++) {
+ geometry_msgs::msg::PoseStamped p;
+ pts pt_copy = tf_map_to_world(data[lp[i]].x, data[lp[i]].y);
+
+
+ p.pose.position.x = pt_copy.x;
+ p.pose.position.y = pt_copy.y;
+ p.header.stamp = node_->now();
+ p.header.frame_id = global_frame_;
+ pa.poses.push_back(p);
+
+ pts pt2_copy = tf_map_to_world(data[lp[i + 1]].x, data[lp[i + 1]].y);
+
+ double distance = double(dist(pt2_copy.x, pt2_copy.y, pt_copy.x, pt_copy.y));
+ int loops = int(distance / dist_bw_points);
+ double sin_alpha = (pt2_copy.y - pt_copy.y) / distance;
+ double cos_alpha = (pt2_copy.x - pt_copy.x) / distance;
+ for (int j = 1; j < loops; j++) {
+ geometry_msgs::msg::PoseStamped p1;
+ p1.pose.position.x = pt_copy.x + j * dist_bw_points * cos_alpha;
+ p1.pose.position.y = pt_copy.y + j * dist_bw_points * sin_alpha;
+ p1.header.stamp = node_->now();
+ p1.header.frame_id = global_frame_;
+ pa.poses.push_back(p1);
+ }
+ geometry_msgs::msg::PoseStamped p2;
+ p2.pose.position.x = pt2_copy.x;
+ p2.pose.position.y = pt2_copy.y;
+ p2.header.stamp = node_->now();
+ p2.header.frame_id = global_frame_;
+ pa.poses.push_back(p2);
+
+ }
+
+
+ return pa;
+
+ }
+
+
+ void LazyThetaStarB::clearRobotCell(int mx, int my) {
+ costmap_->setCost(mx, my, nav2_costmap_2d::FREE_SPACE);
+ }
+
+
+ //Code to preferably not to look at
+
+ //this finds the shortest distance between the points of the raw path given by the planner
+// nav_msgs::msg::Path LazyThetaStarB::AutoLinearInterpolation(vector lp) {
+//
+// nav_msgs::msg::Path the_path;
+// if (lp.size() > 2) {
+// double min_dist = INF_COST;
+//
+// for (int i = 0; i < int(lp.size() - 1); i++) {
+// pts pt_copy = tf_map_to_world(data[lp[i]].x, data[lp[i]].y);
+// pts pt2_copy = tf_map_to_world(data[lp[i + 1]].x, data[lp[i + 1]].y)
+// double dist_curr = dist(pt_copy.x, pt_copy.y, pt2_copy.x, pt2_copy.y);
+//
+// if (dist_curr < min_dist)
+// min_dist = dist_curr;
+// }
+//
+// the_path = linearInterpolation(lp, min_dist);
+//
+// } else {
+// the_path = linearInterpolation(lp, 0.01);
+// }
+// RCLCPP_INFO(node_->get_logger(), "SENT BACK THE PATH!!!!!!");
+// return the_path;
+// }
+}
+
+#include "pluginlib/class_list_macros.hpp"
+
+PLUGINLIB_EXPORT_CLASS(lazy_theta_star_b::LazyThetaStarB, nav2_core::GlobalPlanner)
From cc9505832461b9d308cece3c94863506c7a62909 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Thu, 2 Jul 2020 02:44:18 +0530
Subject: [PATCH 02/81] Added license
---
.../lazy_theta_star_b/lazy_theta_star_b.h | 37 ++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
index 39a649b87f..6fda92ebb8 100644
--- a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
+++ b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
@@ -1,4 +1,39 @@
-
+/*********************************************************************
+ *
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2020 Anshumaan Singh
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Willow Garage, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Anshumaan Singh
+ *********************************************************************/
#include
#include
#include
From 74946f297581f5a8dbe17e91d56325846420406c Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Thu, 2 Jul 2020 02:45:23 +0530
Subject: [PATCH 03/81] Added license
---
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 36 +++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
index 0f58aa2c81..1816333d5a 100644
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -1,3 +1,39 @@
+/*********************************************************************
+ *
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2020 Anshumaan Singh
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Willow Garage, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Anshumaan Singh
+ *********************************************************************/
#include "lazy_theta_star_b/lazy_theta_star_b.h"
#include "nav2_util/node_utils.hpp"
#include "chrono"
From ae6ecc44968398eafd06b1cfa50d8985b3729bdf Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Thu, 2 Jul 2020 23:32:22 +0530
Subject: [PATCH 04/81] Update lazy_theta_star_b.cpp
---
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 64 ++++++++++++---------
1 file changed, 37 insertions(+), 27 deletions(-)
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
index 1816333d5a..8c5985399f 100644
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -88,8 +88,9 @@ namespace lazy_theta_star_b {
const geometry_msgs::msg::PoseStamped &goal) {
- RCLCPP_INFO(
- node_->get_logger(), "Path Search Begins");
+ RCLCPP_INFO(
+ node_->get_logger(), "GOT THE SOURCE AND DESTINATION ------ (%f, %f) && (%f, %f)",
+ start.pose.position.x, start.pose.position.y, goal.pose.position.x, goal.pose.position.y);
costmap_->worldToMap(start.pose.position.x, start.pose.position.y, reinterpret_cast(src.x),
reinterpret_cast(src.y));
@@ -122,14 +123,9 @@ namespace lazy_theta_star_b {
clearRobotCell(src.x, src.y);
- RCLCPP_INFO(
- node_->get_logger(), "GOT THE SOURCE AND DESTINATION ------ %i, %i && %i, %i",
- src.x, src.y, dst.x, dst.y);
-
-
- if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
+ if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
!withinLimits(dst.x, dst.y)) {
- RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE!!!!!!");
+ RCLCPP_INFO(node_->get_logger(), "THE SOURCE OR DESTINATION IS EITHER NOT WITHIN THE SIZE MAP OR IS OBSTRUCTED");
global_path.poses.clear();
return global_path;
@@ -160,23 +156,7 @@ namespace lazy_theta_star_b {
data[curr_id].counter++;
- // The condition if current point is the destination
- if (cx == dst.x && cy == dst.y) {
- if (los_check(cx, cy, data[data[last_id].parentId].x, data[data[last_id].parentId].y)) {
- data[curr_id].parentId = data[last_id].parentId;
- data[curr_id].g = data[data[last_id].parentId].g;
- data[curr_id].f = data[data[last_id].parentId].f;
- break;
- } else {
- data[curr_id].parentId = last_id;
- data[curr_id].g = data[last_id].g;
- data[curr_id].f = data[last_id].f;
- break;
- }
- }
-
- //generates the child nodes location
- int moves[8][2] = {{cx, cy + 1},
+ int moves[8][2] = {{cx, cy + 1},
{cx + 1, cy},
{cx, cy - 1},
{cx - 1, cy},
@@ -192,6 +172,32 @@ namespace lazy_theta_star_b {
int mx, my;
id m_id;
id curr_par = (data[curr_id].parentId);
+
+ // The condition if current point is the destination
+ if (cx == dst.x && cy == dst.y) {
+ if (!(los_check(cx, cy, data[curr_par].x, data[curr_par].y))) {
+ float min_dist = INF_COST;
+ int min_dist_id = curr_par;
+
+ for (int i = 0; i < how_many_corners; i++) {
+ mx = moves[i][0];
+ my = moves[i][1];
+ if (withinLimits(mx, my)) {
+ m_id = getIndex(mx, my);
+ if (m_id != 0) {
+ if (data[m_id].f < min_dist) {
+ min_dist = data[m_id].f;
+ min_dist_id = m_id;
+ }
+ }
+ }
+ data[curr_id].parentId = min_dist_id;
+ data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
+ data[curr_id].f = data[curr_id].g + data[curr_id].h;
+ }
+ }
+ break;
+ }
//lazy checking for the parent
if (!(los_check(cx, cy, data[curr_par].x, data[curr_par].y)) && isSafe(cx, cy) &&
@@ -265,9 +271,13 @@ namespace lazy_theta_star_b {
data[curr_id].closed = -1;
}
+
+ if(pq.size() == 1){
+ RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE");
+ }
} else {
- RCLCPP_INFO(node_->get_logger(), "Straight Path");
+ RCLCPP_INFO(node_->get_logger(), "STRAIGHT LINE PATH");
data.push_back({(dst.x), (dst.y), dist(cx, cy, src.x, src.y), 0, 0});
curr_id = 1;
}
From 24ab8232e63516e0fa516e95da141245324e412d Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Sat, 4 Jul 2020 09:29:56 +0530
Subject: [PATCH 05/81] restructured files
- separated planner part and the algorithm
- implemented all the changes as suggested
---
lazy_theta_star_b/CMakeLists.txt | 7 +-
lazy_theta_star_b/global_planner_plugin.xml | 2 +-
.../lazy_theta_star_b/lazy_theta_star_b.h | 286 +++---
.../include/lazy_theta_star_b/planner.h | 75 ++
lazy_theta_star_b/package.xml | 3 +-
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 843 ++++++++----------
lazy_theta_star_b/src/planner.cpp | 145 +++
7 files changed, 694 insertions(+), 667 deletions(-)
create mode 100644 lazy_theta_star_b/include/lazy_theta_star_b/planner.h
create mode 100644 lazy_theta_star_b/src/planner.cpp
diff --git a/lazy_theta_star_b/CMakeLists.txt b/lazy_theta_star_b/CMakeLists.txt
index 98875908c0..dc04e6d324 100644
--- a/lazy_theta_star_b/CMakeLists.txt
+++ b/lazy_theta_star_b/CMakeLists.txt
@@ -45,10 +45,9 @@ set(dependencies
)
add_library(${library_name} SHARED
+ src/planner.cpp
src/lazy_theta_star_b.cpp
)
-
-set_target_properties(lazy_theta_star_b_plugin PROPERTIES COMPILE_FLAGS "-O3")
ament_target_dependencies(${library_name}
${dependencies}
)
@@ -75,10 +74,10 @@ if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
- #set(ament_cmake_copyright_FOUND TRUE)
+ # set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
- #set(ament_cmake_cpplint_FOUND TRUE)
+ # set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
diff --git a/lazy_theta_star_b/global_planner_plugin.xml b/lazy_theta_star_b/global_planner_plugin.xml
index 39eae7f80c..5eb448e56b 100644
--- a/lazy_theta_star_b/global_planner_plugin.xml
+++ b/lazy_theta_star_b/global_planner_plugin.xml
@@ -1,5 +1,5 @@
-
+
The implementation of lazy theta_star
\ No newline at end of file
diff --git a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
index 6fda92ebb8..9a2641f4d1 100644
--- a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
+++ b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
@@ -1,176 +1,122 @@
-/*********************************************************************
- *
- * Software License Agreement (BSD License)
- *
- * Copyright (c) 2020 Anshumaan Singh
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of Willow Garage, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * Author: Anshumaan Singh
- *********************************************************************/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef LAZY_THETA_STAR_B__LAZY_THETA_STAR_B_H_
+#define LAZY_THETA_STAR_B__LAZY_THETA_STAR_B_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
#include "rclcpp/rclcpp.hpp"
-
-#include "nav2_core/global_planner.hpp"
-#include "nav_msgs/msg/path.hpp"
-#include "nav2_util/robot_utils.hpp"
-#include "nav2_util/lifecycle_node.hpp"
#include "nav2_costmap_2d/costmap_2d_ros.hpp"
#include "nav2_costmap_2d/cost_values.hpp"
-namespace lazy_theta_star_b {
- typedef int id;
- using namespace std;
+typedef int id;
-#define SMALL 0.001
#define INF_COST 10000000.0
-#define LETHAL_COST 100
-
- template
- struct pts {
- ptsT x, y;
- };
-
- struct pos {
- id pos_id;
- double *g;
- double *f;
- };
-
- struct tree_node {
- int x, y;
- double g = INF_COST;
- double h = INF_COST;
- id parentId;
- int closed = 0; //0 - unexplored, 1 - closed, -1 - open
- double f = INF_COST;
- int counter = 0;
- int got_here = 0;
- };
-
-
- class LazyThetaStarB : public nav2_core::GlobalPlanner {
-
- public:
-
- int lethal_cost = LETHAL_COST;
-
- std::shared_ptr tf_;
- nav2_util::LifecycleNode::SharedPtr node_;
- nav2_costmap_2d::Costmap2D *costmap_;
- std::string global_frame_, name_;
-
- double interpolation_dist;
- int how_many_corners_;
- pts src_{}, dst_{};
-
- //stores the cell data
- vector data;
-
- //stores the raw path given by the planner on the basis of their index in the vector data
- vector path;
- nav_msgs::msg::Path global_path;
-
- // is the priority queue
- vector pq;
- int sizeX = 0;
- int sizeY = 0;
- int how_many_corners;
- pts src{}, dst{};
-
-
- void configure(
- rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
- std::string name, std::shared_ptr tf,
- std::shared_ptr costmap_ros) override;
-
- void cleanup() override;
-
- void activate() override;
-
- void deactivate() override;
-
- nav_msgs::msg::Path createPlan(
- const geometry_msgs::msg::PoseStamped &start,
- const geometry_msgs::msg::PoseStamped &goal) override;
-
-
- //The Line of Sight checking algorithm, takes in the points, and follows the line joining points
- bool los_check(int x0, int y0, int x1, int y1);
-
- //Gives out the Euclidean Distance
- double dist(double ax, double ay, double bx, double by) {
- return sqrt(pow(ax - bx, 2) + pow(ay - by, 2));
- }
-
- //to pop the minimum value of the queue, it is ever so slightly faster than the stl one,
- //based on the implementation by Peter Sanders (2000)
- void binary_heap_del_min();
-
- //to compare between values in thet priority queue
- static bool comp(pos p1, pos p2) {
- return (*(p1.f) != *(p2.f)) ? (*(p1.f) > *(p2.f)) : (*(p1.g) > *(p2.g));
- }
-
- nav_msgs::msg::Path linearInterpolation(vector lp, double dist_bw_points);
-
- pts tf_map_to_world(int x, int y) ;
-
- bool withinLimits(int x, int y);
-
- bool isSafe(int cx, int cy);
-
- void push_to_pq(id id_this);
-
- void clearRobotCell(int mx, int my);
-
- void backtrace(vector *waypt, id curr_id);
-
- //stores the index at which the node data is stored for a particular co-ordinate
- vector posn;
-
- //it sets/resets all the values within posn to 0
- void initializePosn();
-
- //functions used to maintain indices
- void addIndex(int cx, int cy, id index);
- id getIndex(int cx, int cy);
-
- //nav_msgs::msg::Path AutoLinearInterpolation(vector lp);
- };
-
-}
-
+#define LETHAL_COST 127
+
+template
+struct pts
+{
+ ptsT x, y;
+};
+
+struct pos
+{
+ id pos_id;
+ double * g;
+ double * f;
+};
+
+struct tree_node
+{
+ int x, y;
+ double g = INF_COST;
+ double h = INF_COST;
+ id parentId;
+ int closed = 0; // 0 - unexplored, 1 - closed, -1 - open
+ double f = INF_COST;
+ int got_here = 0;
+};
+
+namespace lazyThetaStarB
+{
+
+class LazyThetaStarB
+{
+public:
+ int lethal_cost = LETHAL_COST;
+
+ nav2_util::LifecycleNode::SharedPtr node_;
+ nav2_costmap_2d::Costmap2D * costmap_;
+
+ // stores the cell data
+ std::vector data;
+
+ // stores the raw path given by the planner on the basis of their index in the std::vector data
+ std::vector path;
+
+ // is the priority queue
+ std::vector pq;
+ int sizeX = 0;
+ int sizeY = 0;
+ int how_many_corners;
+ pts src{}, dst{};
+
+ // The part containing the algorithm
+ void makePlan(std::vector & x_path, std::vector & y_path);
+
+ // The Line of Sight checking algorithm, takes in the points, and follows the line joining points
+ bool losCheck(int x0, int y0, int x1, int y1);
+
+ // to pop the minimum value of the queue, it is ever so slightly faster than the stl one,
+ // based on the implementation by Peter Sanders (2000)
+ void binaryHeapDelMin();
+
+ // to compare between values in the priority queue
+ static bool comp(pos p1, pos p2)
+ {
+ return (*(p1.f) != *(p2.f)) ? (*(p1.f) > *(p2.f)) : (*(p1.g) > *(p2.g));
+ }
+
+ double dist(int & ax, int & ay, int & bx, int & by)
+ {
+ return sqrt(pow(ax - bx, 2) + pow(ay - by, 2));
+ }
+
+ bool withinLimits(const int & x, const int & y);
+ bool isSafe(const int & cx, const int & cy);
+ void pushToPq(id & idThis);
+ void clearRobotCell(int mx, int my);
+ void backtrace(std::vector * waypt, id curr_id);
+
+ // stores the index at which the node data is stored for a particular co-ordinate
+ std::vector posn;
+
+ // it sets/resets all the values within posn to 0
+ void initializePosn();
+
+ // functions used to maintain indices
+ void addIndex(const int & cx, const int & cy, const id & index);
+ id getIndex(const int & cx, const int & cy);
+
+ bool isSafe2(int cx, int cy);
+};
+
+} // namespace lazyThetaStarB
+#endif // LAZY_THETA_STAR_B__LAZY_THETA_STAR_B_H_
diff --git a/lazy_theta_star_b/include/lazy_theta_star_b/planner.h b/lazy_theta_star_b/include/lazy_theta_star_b/planner.h
new file mode 100644
index 0000000000..118c8dbbfa
--- /dev/null
+++ b/lazy_theta_star_b/include/lazy_theta_star_b/planner.h
@@ -0,0 +1,75 @@
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef LAZY_THETA_STAR_B__PLANNER_H_
+#define LAZY_THETA_STAR_B__PLANNER_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "rclcpp/rclcpp.hpp"
+#include "nav2_core/global_planner.hpp"
+#include "nav_msgs/msg/path.hpp"
+#include "nav2_util/robot_utils.hpp"
+#include "nav2_util/lifecycle_node.hpp"
+#include "nav2_costmap_2d/costmap_2d_ros.hpp"
+#include "nav2_costmap_2d/cost_values.hpp"
+#include "nav2_util/node_utils.hpp"
+#include "lazy_theta_star_b/lazy_theta_star_b.h"
+
+namespace planner
+{
+
+template
+struct pts
+{
+ ptsT x, y;
+};
+
+class planner : public nav2_core::GlobalPlanner
+{
+public:
+ std::shared_ptr tf_;
+ nav2_util::LifecycleNode::SharedPtr node_;
+ nav2_costmap_2d::Costmap2D * costmap_;
+
+ std::string globalFrame_, name_;
+ int how_many_corners_;
+ double interpolation_dist_;
+ std::vector x, y;
+ std::unique_ptr planner_;
+
+ void configure(
+ rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
+ std::string name, std::shared_ptr tf,
+ std::shared_ptr costmapRos) override;
+
+ void cleanup() override;
+ void activate() override;
+ void deactivate() override;
+
+ nav_msgs::msg::Path createPlan(
+ const geometry_msgs::msg::PoseStamped & start,
+ const geometry_msgs::msg::PoseStamped & goal) override;
+
+ nav_msgs::msg::Path linearInterpolation(double distBwPoints);
+};
+
+} // namespace planner
+#endif // LAZY_THETA_STAR_B__PLANNER_H_
diff --git a/lazy_theta_star_b/package.xml b/lazy_theta_star_b/package.xml
index 7e06686661..fa361b2860 100644
--- a/lazy_theta_star_b/package.xml
+++ b/lazy_theta_star_b/package.xml
@@ -2,7 +2,7 @@
lazy_theta_star_b
- 0.0.1
+ 0.4.0
TODO: Package description
anshu-man
Apache-2.0
@@ -23,6 +23,7 @@
ament_lint_auto
ament_lint_common
+ ament_cmake_gtest
ament_cmake
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
index 8c5985399f..7e5aafdb4f 100644
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -1,529 +1,390 @@
-/*********************************************************************
- *
- * Software License Agreement (BSD License)
- *
- * Copyright (c) 2020 Anshumaan Singh
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of Willow Garage, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * Author: Anshumaan Singh
- *********************************************************************/
-#include "lazy_theta_star_b/lazy_theta_star_b.h"
-#include "nav2_util/node_utils.hpp"
-#include "chrono"
-
-namespace lazy_theta_star_b {
- void LazyThetaStarB::configure(rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
- std::string name, std::shared_ptr tf,
- std::shared_ptr costmap_ros) {
- node_ = parent;
- name_ = name;
- tf_ = tf;
- costmap_ = costmap_ros->getCostmap();
- global_frame_ = costmap_ros->getGlobalFrameID();
-
- nav2_util::declare_parameter_if_not_declared(
- node_, name_ + ".how_many_corners", rclcpp::ParameterValue(
- 8));
-
- node_->get_parameter(name_ + ".how_many_corners", how_many_corners_);
-
- if (how_many_corners_ != 8)
- how_many_corners_ = 4;
-
- nav2_util::declare_parameter_if_not_declared(
- node_, name_ + ".interpolation_dist", rclcpp::ParameterValue(
- 0.1));
-
- node_->get_parameter(name_ + ".interpolation_dist", interpolation_dist);
-
- }
-
- void LazyThetaStarB::cleanup() {
- RCLCPP_INFO(
- node_->get_logger(), "CleaningUp plugin %s of type LazyThetaStarB",
- name_.c_str());
- }
-
- void LazyThetaStarB::activate() {
- RCLCPP_INFO(
- node_->get_logger(), "Activating plugin %s of type LazyThetaStarB",
- name_.c_str());
- }
-
- void LazyThetaStarB::deactivate() {
- RCLCPP_INFO(
- node_->get_logger(), "Deactivating plugin %s of type LazyThetaStarB",
- name_.c_str());
- }
-
- nav_msgs::msg::Path LazyThetaStarB::createPlan(
- const geometry_msgs::msg::PoseStamped &start,
- const geometry_msgs::msg::PoseStamped &goal) {
-
-
- RCLCPP_INFO(
- node_->get_logger(), "GOT THE SOURCE AND DESTINATION ------ (%f, %f) && (%f, %f)",
- start.pose.position.x, start.pose.position.y, goal.pose.position.x, goal.pose.position.y);
-
- costmap_->worldToMap(start.pose.position.x, start.pose.position.y, reinterpret_cast(src.x),
- reinterpret_cast(src.y));
-
-
- costmap_->worldToMap(goal.pose.position.x, goal.pose.position.y, reinterpret_cast(dst.x),
- reinterpret_cast(dst.y));
- src.x = int(src.x);
- src.y = int(src.y);
-
- dst.x = int(dst.x);
- dst.y = int(dst.y);
-
- data.clear();
- pq.clear();
- path.clear();
- posn.clear();
- lethal_cost = LETHAL_COST;
-
- sizeX = costmap_->getSizeInCellsX();
- sizeY = costmap_->getSizeInCellsY();
-
- //has been added so that if the robot is stuck at a place with costmap cost higher than 127, then only for that run, the planner be able to give a path
- if (costmap_->getCost(src.x, src.y) >= lethal_cost && costmap_->getCost(src.x, src.y) <= 253) {
- lethal_cost = costmap_->getCost(src.x, src.y);
- }
-
- initializePosn();
- data.reserve(int((sizeX) * (sizeY) * 0.01));
-
- clearRobotCell(src.x, src.y);
-
- if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
- !withinLimits(dst.x, dst.y)) {
- RCLCPP_INFO(node_->get_logger(), "THE SOURCE OR DESTINATION IS EITHER NOT WITHIN THE SIZE MAP OR IS OBSTRUCTED");
- global_path.poses.clear();
- return global_path;
-
- }
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
- data.push_back({(src.x), (src.y), 0, dist(src.x, src.y, dst.x, dst.y), 0, -1,
- dist(src.x, src.y, dst.x, dst.y)});
-
- addIndex(src.x, src.y, 0);
-
- pq.push_back({0, &(data[0].g), &(data[0].f)});
- //added as a buffer, since my binary_heap_del_min starts from the index 1 instead of 0
- pq.push_back({0, &(data[0].g), &(data[0].f)});
-
-
- //The algorithm begins here
- id curr_id = 0;
- id id_gen = 1;
- id last_id = 0;
- int cy;
- int cx;
- cx = (data[curr_id].x);
- cy = (data[curr_id].y);
-
- if (!los_check(src.x, src.y, dst.x, dst.y)) {
-
- while (pq.size() > 1) {
-
- data[curr_id].counter++;
-
- int moves[8][2] = {{cx, cy + 1},
- {cx + 1, cy},
- {cx, cy - 1},
- {cx - 1, cy},
- {cx + 1, cy + 1},
- {cx + 1, cy - 1},
- {cx - 1, cy - 1},
- {cx - 1, cy + 1}};
-
- if (how_many_corners != 8) {
- how_many_corners = 4;
- }
+#include
+#include "lazy_theta_star_b/lazy_theta_star_b.h"
- int mx, my;
- id m_id;
- id curr_par = (data[curr_id].parentId);
-
- // The condition if current point is the destination
- if (cx == dst.x && cy == dst.y) {
- if (!(los_check(cx, cy, data[curr_par].x, data[curr_par].y))) {
- float min_dist = INF_COST;
- int min_dist_id = curr_par;
-
- for (int i = 0; i < how_many_corners; i++) {
- mx = moves[i][0];
- my = moves[i][1];
- if (withinLimits(mx, my)) {
- m_id = getIndex(mx, my);
- if (m_id != 0) {
- if (data[m_id].f < min_dist) {
- min_dist = data[m_id].f;
- min_dist_id = m_id;
- }
- }
- }
- data[curr_id].parentId = min_dist_id;
- data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
- data[curr_id].f = data[curr_id].g + data[curr_id].h;
- }
- }
- break;
- }
-
- //lazy checking for the parent
- if (!(los_check(cx, cy, data[curr_par].x, data[curr_par].y)) && isSafe(cx, cy) &&
- isSafe(data[curr_par].x, data[curr_par].y)) {
-
- double min_dist = INF_COST;
- int min_dist_id = curr_par;
-
- for (int i = 0; i < how_many_corners; i++) {
- mx = moves[i][0];
- my = moves[i][1];
- if (withinLimits(mx, my)) {
- m_id = getIndex(mx, my);
- if (m_id != 0) {
- if (data[m_id].f < min_dist) {
- min_dist = data[m_id].f;
- min_dist_id = m_id;
- }
- }
- }
- data[curr_id].parentId = min_dist_id;
- data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
- data[curr_id].f = data[curr_id].g + data[curr_id].h;
- }
+namespace lazyThetaStarB
+{
+
+void LazyThetaStarB::makePlan(std::vector & x_path, std::vector & y_path)
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "Path Search Begins");
+
+ x_path.clear();
+ y_path.clear();
+ id id_gen = 0;
+ sizeX = costmap_->getSizeInCellsX();
+ sizeY = costmap_->getSizeInCellsY();
+ posn.clear();
+ initializePosn();
+
+ std::cout << posn[0] << '\n';
+ // has been added so that if the robot is stuck at a place with costmap cost higher than 127
+ // then only for that run, the planner be able to give a path
+ if (costmap_->getCost(src.x, src.y) >= lethal_cost && costmap_->getCost(src.x, src.y) <= 253) {
+ lethal_cost = costmap_->getCost(src.x, src.y);
+ }
+
+ data.reserve(static_cast( (sizeX) * (sizeY) * 0.01 ) );
+ clearRobotCell(src.x, src.y);
+
+ RCLCPP_INFO(
+ node_->get_logger(), "GOT THE SOURCE AND DESTINATION ------ %i, %i && %i, %i",
+ src.x, src.y, dst.x, dst.y);
+
+ if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
+ !withinLimits(dst.x, dst.y))
+ {
+// std::cout << !isSafe(src.x, src.y) << '\t' << !isSafe(dst.x, dst.y) << '\t' << !withinLimits(
+// src.x, src.y) << '\t' <<
+// !withinLimits(dst.x, dst.y) << '\n';
+ RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE!!!!!!");
+ }
+
+ data.push_back({(src.x), (src.y), 0, dist(src.x, src.y, dst.x, dst.y), 0, -1,
+ dist(src.x, src.y, dst.x, dst.y)});
+
+ addIndex(src.x, src.y, id_gen);
+
+ pq.push_back({0, &(data[0].g), &(data[0].f)});
+ pq.push_back({0, &(data[0].g), &(data[0].f)});
+ // added as a buffer, since my binaryHeapDelMin requires for the start index to 1 instead of 0
+
+ // The algorithm begins here
+ id curr_id = 0;
+ id_gen++;
+
+ const int moves[8][2] = {
+ {0, +1},
+ {0, -1},
+ {-1, 0},
+ {+1, 0},
+ {+1, -1},
+ {-1, -1},
+ {-1, +1},
+ {+1, +1},
+ };
+
+ int cy;
+ int cx;
+ cx = (data[curr_id].x);
+ cy = (data[curr_id].y);
+
+ if (!losCheck(src.x, src.y, dst.x, dst.y)) {
+
+ while (pq.size() > 1) {
+
+
+// int moves[8][2] = {{cx, cy + 1},
+// {cx + 1, cy},
+// {cx, cy - 1},
+// {cx - 1, cy},
+// {cx + 1, cy + 1},
+// {cx + 1, cy - 1},
+// {cx - 1, cy - 1},
+// {cx - 1, cy + 1}};
+ int mx, my;
+ id m_id;
+ id curr_par = (data[curr_id].parentId);
+ std::cout << "THE CURRENT POINT IS : " << cx << '\t' << cy << '\n';
+
+ // The condition if current point is the destination
+ if (cx == dst.x && cy == dst.y) {
+ std::cout<<"Got IT!!!!!!!!!"<<'\n';
+ if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
+ float min_dist = INF_COST;
+ int min_dist_id = curr_par;
+ std::cout<<"NEED IT!!!!!!!!!"<<'\n';
+
+ for (int i = 0; i < how_many_corners; i++) {
+ std::cout<<"IT!!!!!!!!!"<<'\n';
+ mx = cx + moves[i][0];
+ my = cy + moves[i][1];
+ if (withinLimits(mx, my)) {
+ m_id = getIndex(mx, my);
+ if (m_id != 0) {
+ if (data[m_id].f < min_dist) {
+ min_dist = data[m_id].f;
+ min_dist_id = m_id;
}
- curr_par = data[curr_id].parentId;
-
- for (int i = 0; i < how_many_corners; i++) {
- mx = moves[i][0];
- my = moves[i][1];
-
- if (mx == data[curr_par].x && my == data[curr_par].y)
- continue;
-
- if (withinLimits(mx, my)) {
- double g_cost = data[curr_par].g + dist(mx, my, data[curr_par].x, data[curr_par].y);
- double h_cost, cal_cost;
- m_id = getIndex(mx, my);
- if (m_id == 0 && isSafe(mx, my)) {
- h_cost = dist(mx, my, dst.x, dst.y);
- cal_cost = g_cost + h_cost;
- data.push_back({int(mx), int(my), g_cost, h_cost, curr_par, -1, cal_cost});
- addIndex(mx, my, id_gen);
- push_to_pq(id_gen);
- id_gen++;
- continue;
- } else if (m_id != 0) {
- h_cost = data[m_id].h;
- cal_cost = g_cost + h_cost;
- if (data[m_id].f > cal_cost) {
- data[m_id].g = g_cost;
- data[m_id].f = cal_cost;
- data[m_id].parentId = curr_par;
- if (data[m_id].closed == 1) {
- data[m_id].closed = -1;
- push_to_pq(m_id);
- }
- }
- continue;
- }
- }
- }
-
- last_id = curr_id;
- do {
- curr_id = pq[1].pos_id;
- cx = data[curr_id].x;
- cy = data[curr_id].y;
- } while (!isSafe(cx, cy));
- binary_heap_del_min();
- data[curr_id].closed = -1;
-
+ }
}
-
- if(pq.size() == 1){
- RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE");
- }
-
- } else {
- RCLCPP_INFO(node_->get_logger(), "STRAIGHT LINE PATH");
- data.push_back({(dst.x), (dst.y), dist(cx, cy, src.x, src.y), 0, 0});
- curr_id = 1;
+ data[curr_id].parentId = min_dist_id;
+ data[curr_id].g = data[min_dist_id].g +
+ dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
+ data[curr_id].f = data[curr_id].g + data[curr_id].h;
+ }
}
-
- RCLCPP_INFO(node_->get_logger(), "REACHED DEST %i, %i", dst.x, dst.y);
-
- backtrace(&path, curr_id);
-
- cout << data.size() << '\n';
-
- cout << "Publishing the Path" << '\n';
-
- //reset all the values
- global_path = linearInterpolation(path, interpolation_dist);
-
- geometry_msgs::msg::PoseStamped p_end;
- p_end.pose.position.x = goal.pose.position.x;
- p_end.pose.position.y = goal.pose.position.y;
- p_end.header.stamp = node_->now();
- p_end.header.frame_id = global_frame_;
- global_path.poses.push_back(p_end);
-
- return global_path;
- }
-
- void LazyThetaStarB::initializePosn() {
- if (pq.size() != abs(sizeX * sizeY)) {
- for (int i = 0; i < sizeY * sizeX; i++) {
- posn.push_back(0);
- }
- } else {
- for (int i = 0; i < sizeY * sizeX; i++) {
- posn[i] = 0;
+ break;
+ }
+
+ if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
+ float min_dist = INF_COST;
+ int min_dist_id = curr_par;
+
+ for (int i = 0; i < how_many_corners; i++) {
+ mx = cx + moves[i][0];
+ my = cy + moves[i][1];
+ if (withinLimits(mx, my)) {
+ m_id = getIndex(mx, my);
+ if (m_id != 0) {
+ if (data[m_id].f < min_dist) {
+ min_dist = data[m_id].f;
+ min_dist_id = m_id;
+ }
}
+ }
+ data[curr_id].parentId = min_dist_id;
+ data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x,
+ data[min_dist_id].y);
+ data[curr_id].f = data[curr_id].g + data[curr_id].h;
}
- }
-
- void LazyThetaStarB::addIndex(int cx, int cy, id index) {
- posn[sizeX * cy + cx] = index;
- }
-
- id LazyThetaStarB::getIndex(int cx, int cy) {
- return posn[sizeX * cy + cx];
- }
+ }
+ curr_par = data[curr_id].parentId;
- void LazyThetaStarB::backtrace(vector *waypt, id curr_id) {
- vector waypt_rev;
- do {
- waypt_rev.push_back(curr_id);
- curr_id = data[curr_id].parentId;
- } while (curr_id != 0);
- waypt_rev.push_back(0);
+ for (int i = 0; i < how_many_corners; i++) {
+ mx = cx + moves[i][0];
+ my = cy + moves[i][1];
- for (int i = waypt_rev.size() - 1; i >= 0; i--) {
- waypt->push_back(waypt_rev[i]);
+ if (mx == data[curr_par].x && my == data[curr_par].y) {
+ continue;
}
- }
-
- void LazyThetaStarB::binary_heap_del_min() {
- int hole = 1;
- int succ = 2, size = pq.size() - 1, sz = size;
- //the main bottom up part where it compares and assigns the smallest value to the hole
- //remember that for this part the heap starts at index 1
- while (succ < sz) {
- double k1 = *(pq[succ].f);
- double k2 = *(pq[succ + 1].f);
- if (k1 > k2) {
- succ++;
- pq[hole] = pq[succ];
- } else {
- pq[hole] = pq[succ];
+ if (withinLimits(mx, my)) {
+ float g_cost = data[curr_par].g + dist(mx, my, data[curr_par].x, data[curr_par].y);
+ float h_cost, cal_cost;
+ m_id = getIndex(mx, my);
+ if (m_id == 0 && isSafe(mx, my)) {
+ h_cost = dist(mx, my, dst.x, dst.y);
+ cal_cost = g_cost + h_cost;
+ data.push_back({mx, my, g_cost, h_cost, curr_par, -1, cal_cost});
+ addIndex(mx, my, id_gen);
+ pushToPq(id_gen);
+ id_gen++;
+ continue;
+ } else if (m_id != 0) {
+ h_cost = data[m_id].h;
+ cal_cost = g_cost + h_cost;
+ if (data[m_id].f > cal_cost) {
+ data[m_id].g = g_cost;
+ data[m_id].f = cal_cost;
+ data[m_id].parentId = curr_par;
+ if (data[m_id].closed == 1) {
+ data[m_id].closed = -1;
+ pushToPq(m_id);
+ }
}
- hole = succ;
- succ <<= 1;
- }
- //this part checks if the value to be used to fill the last row's hole is small or not
- //if not small then it slides the small value up till it reaches the apt position
- double bubble = *(pq[sz].f);
- int pred = hole >> 1;
- while (*(pq[pred].f) > bubble) {
- pq[hole] = pq[pred];
- hole = pred;
- pred >>= 1;
+ continue;
+ }
}
- //this part simply assigns the last value in the heap to the hole after checking it
- //for maintaining the heap data structure
- pq[hole] = pq[sz];
- pq.pop_back();
+ }
+
+ do {
+ curr_id = pq[1].pos_id;
+ cx = data[curr_id].x;
+ cy = data[curr_id].y;
+ } while (!isSafe(cx, cy));
+ binaryHeapDelMin();
+ data[curr_id].closed = -1;
}
- bool LazyThetaStarB::los_check(int x0, int y0, int x1, int y1) {
+ } else {
+ RCLCPP_INFO(node_->get_logger(), "Straight Path");
+ data.push_back({(dst.x), (dst.y), dist(cx, cy, src.x, src.y), 0, 0});
+ curr_id = 1;
+ }
- int dy = y1 - y0, dx = x1 - x0, f = 0;
- int sx, sy;
+ RCLCPP_INFO(node_->get_logger(), "REACHED DEST %i, %i", dst.x, dst.y);
- if (dy < 0) {
- dy = -dy;
- sy = -1;
- } else {
- sy = 1;
- }
+ backtrace(&path, curr_id);
- if (dx < 0) {
- dx = -dx;
- sx = -1;
- } else {
- sx = 1;
- }
+ for (auto & p : path) {
+ pts map_coords;
+ costmap_->mapToWorld(data[p].x, data[p].y, map_coords.x, map_coords.y);
+ RCLCPP_INFO(node_->get_logger(), "%f, %f", map_coords.x, map_coords.y);
+ x_path.push_back(map_coords.x);
+ y_path.push_back(map_coords.y);
+ }
+ std::cout << data.size() << '\n';
- if (dx >= dy) {
- while (x0 != x1) {
- f += dy;
- if (f >= dx) {
- if (!isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
- return false;
- y0 += sy;
- f -= dx;
- }
- if (f != 0 && !isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
- return false;
- if (dy == 0 && !isSafe(x0 + (sx - 1) / 2, y0) && !isSafe(x0 + (sx - 1) / 2, y0 - 1))
- return false;
- x0 += sx;
- }
- } else {
- while (y0 != y1) {
- f = f + dx;
- if (f >= dy) {
- if (!isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
- return false;
- x0 += sx;
- f -= dy;
- }
- if (f != 0 && !isSafe(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2))
- return false;
- if (dx == 0 && !isSafe(x0, y0 + (sy - 1) / 2) && !isSafe(x0 - 1, y0 + (sy - 1) / 2))
- return false;
- y0 += sy;
- }
- }
-
- return true;
+ path.clear();
+ data.clear();
- }
-
- void LazyThetaStarB::push_to_pq(id id_this) {
- pq.push_back({id_this, &(data[id_this].g), &(data[id_this].f)});
- push_heap(pq.begin() + 1, pq.end(), comp);
- }
+ pq.clear();
+ lethal_cost = LETHAL_COST;
+ std::cout << "Publishing the Path" << '\n';
+}
- bool LazyThetaStarB::isSafe(int cx, int cy) {
- return (costmap_->getCost(cx, cy) < lethal_cost);
+void LazyThetaStarB::binaryHeapDelMin()
+{
+ int succ = 2;
+ int size = pq.size() - 1;
+ int sz = size;
+ int hole = 1;
+ // the main bottom up part where it compares and assigns the smallest value to the hole
+ // remember that for this part the heap starts at index 1
+ while (succ < sz) {
+ double k1 = *(pq[succ].f);
+ double k2 = *(pq[succ + 1].f);
+ if (k1 > k2) {
+ succ++;
+ pq[hole] = pq[succ];
+ } else {
+ pq[hole] = pq[succ];
}
+ hole = succ;
+ succ <<= 1;
+ }
+ // this part checks if the value to be used to fill the last row's hole is small or not
+ // if not small then it slides the small value up till it reaches the apt position
+ double bubble = *(pq[sz].f);
+ int pred = hole >> 1;
+ while (*(pq[pred].f) > bubble) {
+ pq[hole] = pq[pred];
+ hole = pred;
+ pred >>= 1;
+ }
+ // this part simply assigns the last value in the heap to the hole after checking it
+ // for maintaining the heap data structure
+ pq[hole] = pq[sz];
+ pq.pop_back();
+}
- bool LazyThetaStarB::withinLimits(int x, int y) {
- return (x > 0 && x <= sizeX && y > 0 && y <= sizeY);
+// TODO(Anshhu-man567): FIND A WAY TO PASS THE VALUES BY REFERENCE WHEN CHECKING
+bool LazyThetaStarB::losCheck(int x0, int y0, int x1, int y1)
+{
+ int dy = y1 - y0, dx = x1 - x0, f = 0;
+ int sx, sy;
+
+ if (dy < 0) {
+ dy = -dy;
+ sy = -1;
+ } else {
+ sy = 1;
+ }
+
+ if (dx < 0) {
+ dx = -dx;
+ sx = -1;
+ } else {
+ sx = 1;
+ }
+
+ if (dx >= dy) {
+ while (x0 != x1) {
+ f += dy;
+ if (f >= dx) {
+ if (!isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
+ return false;
+ }
+ y0 += sy;
+ f -= dx;
+ }
+ if (f != 0 && !isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
+ return false;
+ }
+ if (dy == 0 && !isSafe2(x0 + (sx - 1) / 2, y0) && !isSafe2(x0 + (sx - 1) / 2, y0 - 1)) {
+ return false;
+ }
+ x0 += sx;
}
-
- pts LazyThetaStarB::tf_map_to_world(int x, int y) {
- pts pt{};
- pt.x = double(
- costmap_->getOriginX() + (x + 0.5) * costmap_->getResolution());
- pt.y = double(
- costmap_->getOriginY() + (y + 0.5) * costmap_->getResolution());
- // 0.5 added to display the points at the centre of the grid cell
- return pt;
+ } else {
+ while (y0 != y1) {
+ f = f + dx;
+ if (f >= dy) {
+ if (!isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
+ return false;
+ }
+ x0 += sx;
+ f -= dy;
+ }
+ if (f != 0 && !isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
+ return false;
+ }
+ if (dx == 0 && !isSafe2(x0, y0 + (sy - 1) / 2) && !isSafe2(x0 - 1, y0 + (sy - 1) / 2)) {
+ return false;
+ }
+ y0 += sy;
}
+ }
+ return true;
+}
- nav_msgs::msg::Path LazyThetaStarB::linearInterpolation(vector lp, double dist_bw_points) {
-
- nav_msgs::msg::Path pa;
- pa.header.frame_id = "map";
- for (int i = 0; i < int(lp.size() - 1); i++) {
- geometry_msgs::msg::PoseStamped p;
- pts pt_copy = tf_map_to_world(data[lp[i]].x, data[lp[i]].y);
-
-
- p.pose.position.x = pt_copy.x;
- p.pose.position.y = pt_copy.y;
- p.header.stamp = node_->now();
- p.header.frame_id = global_frame_;
- pa.poses.push_back(p);
-
- pts pt2_copy = tf_map_to_world(data[lp[i + 1]].x, data[lp[i + 1]].y);
-
- double distance = double(dist(pt2_copy.x, pt2_copy.y, pt_copy.x, pt_copy.y));
- int loops = int(distance / dist_bw_points);
- double sin_alpha = (pt2_copy.y - pt_copy.y) / distance;
- double cos_alpha = (pt2_copy.x - pt_copy.x) / distance;
- for (int j = 1; j < loops; j++) {
- geometry_msgs::msg::PoseStamped p1;
- p1.pose.position.x = pt_copy.x + j * dist_bw_points * cos_alpha;
- p1.pose.position.y = pt_copy.y + j * dist_bw_points * sin_alpha;
- p1.header.stamp = node_->now();
- p1.header.frame_id = global_frame_;
- pa.poses.push_back(p1);
- }
- geometry_msgs::msg::PoseStamped p2;
- p2.pose.position.x = pt2_copy.x;
- p2.pose.position.y = pt2_copy.y;
- p2.header.stamp = node_->now();
- p2.header.frame_id = global_frame_;
- pa.poses.push_back(p2);
-
- }
+void LazyThetaStarB::initializePosn()
+{
+ for (int i = 0; i < sizeY * sizeX; i++) {
+ posn.push_back(0);
+ }
+}
+void LazyThetaStarB::addIndex(const int & cx, const int & cy, const id & index)
+{
+ posn[sizeX * cy + cx] = index;
+}
- return pa;
+id LazyThetaStarB::getIndex(const int & cx, const int & cy)
+{
+ return posn[sizeX * cy + cx];
+}
+void LazyThetaStarB::backtrace(std::vector * waypt, id curr_id)
+{
+ std::vector wayptRev;
+ do {
+ wayptRev.push_back(curr_id);
+ curr_id = data[curr_id].parentId;
+ if (data[curr_id].got_here == 1) {
+ std::cout
+ << "------------------------------------------------------> got the same error <-------------------------------------------------------"
+ << '\n';
+ break;
}
+ data[curr_id].got_here = 1;
+ } while (curr_id != 0);
+ wayptRev.push_back(0);
+ for (int i = wayptRev.size() - 1; i >= 0; i--) {
+ waypt->push_back(wayptRev[i]);
+ }
+}
- void LazyThetaStarB::clearRobotCell(int mx, int my) {
- costmap_->setCost(mx, my, nav2_costmap_2d::FREE_SPACE);
- }
+void LazyThetaStarB::pushToPq(id & idThis)
+{
+ pq.push_back({idThis, &(data[idThis].g), &(data[idThis].f)});
+ push_heap(pq.begin() + 1, pq.end(), comp);
+}
+bool LazyThetaStarB::isSafe(const int & cx, const int & cy)
+{
+ return costmap_->getCost(cx, cy) < lethal_cost;
+}
- //Code to preferably not to look at
+bool LazyThetaStarB::isSafe2(int cx, int cy)
+{
+ return costmap_->getCost(cx, cy) < lethal_cost;
+}
- //this finds the shortest distance between the points of the raw path given by the planner
-// nav_msgs::msg::Path LazyThetaStarB::AutoLinearInterpolation(vector lp) {
-//
-// nav_msgs::msg::Path the_path;
-// if (lp.size() > 2) {
-// double min_dist = INF_COST;
-//
-// for (int i = 0; i < int(lp.size() - 1); i++) {
-// pts pt_copy = tf_map_to_world(data[lp[i]].x, data[lp[i]].y);
-// pts pt2_copy = tf_map_to_world(data[lp[i + 1]].x, data[lp[i + 1]].y)
-// double dist_curr = dist(pt_copy.x, pt_copy.y, pt2_copy.x, pt2_copy.y);
-//
-// if (dist_curr < min_dist)
-// min_dist = dist_curr;
-// }
-//
-// the_path = linearInterpolation(lp, min_dist);
-//
-// } else {
-// the_path = linearInterpolation(lp, 0.01);
-// }
-// RCLCPP_INFO(node_->get_logger(), "SENT BACK THE PATH!!!!!!");
-// return the_path;
-// }
+bool LazyThetaStarB::withinLimits(const int & x, const int & y)
+{
+ return x > 0 && x <= sizeX && y > 0 && y <= sizeY;
}
-#include "pluginlib/class_list_macros.hpp"
+void LazyThetaStarB::clearRobotCell(int mx, int my)
+{
+ costmap_->setCost(mx, my, nav2_costmap_2d::FREE_SPACE);
+}
-PLUGINLIB_EXPORT_CLASS(lazy_theta_star_b::LazyThetaStarB, nav2_core::GlobalPlanner)
+} // namespace lazyThetaStarB
diff --git a/lazy_theta_star_b/src/planner.cpp b/lazy_theta_star_b/src/planner.cpp
new file mode 100644
index 0000000000..3a14b9c160
--- /dev/null
+++ b/lazy_theta_star_b/src/planner.cpp
@@ -0,0 +1,145 @@
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include
+#include
+#include
+#include "lazy_theta_star_b/planner.h"
+
+namespace planner
+{
+void planner::configure(
+ rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
+ std::string name, std::shared_ptr tf,
+ std::shared_ptr costmapRos)
+{
+ planner_ = std::make_unique();
+ node_ = parent;
+ name_ = name;
+ tf_ = tf;
+ planner_->costmap_ = costmapRos->getCostmap();
+ costmap_ = costmapRos->getCostmap();
+ globalFrame_ = costmapRos->getGlobalFrameID();
+
+ nav2_util::declare_parameter_if_not_declared(
+ node_, name_ + ".howManyCorners", rclcpp::ParameterValue(
+ 8));
+
+ node_->get_parameter(name_ + ".howManyCorners", how_many_corners_);
+
+ if (how_many_corners_ != 8) {
+ how_many_corners_ = 4;
+ }
+
+ nav2_util::declare_parameter_if_not_declared(
+ node_, name_ + ".interpolation_dist_", rclcpp::ParameterValue(
+ 0.1));
+
+ node_->get_parameter(name_ + ".interpolation_dist_", interpolation_dist_);
+}
+
+void planner::cleanup()
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "CleaningUp plugin %s of type planner",
+ name_.c_str());
+}
+
+void planner::activate()
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "Activating plugin %s of type planner",
+ name_.c_str());
+}
+
+void planner::deactivate()
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "Deactivating plugin %s of type planner",
+ name_.c_str());
+}
+
+nav_msgs::msg::Path planner::createPlan(
+ const geometry_msgs::msg::PoseStamped & start,
+ const geometry_msgs::msg::PoseStamped & goal)
+{
+ nav_msgs::msg::Path global_path;
+
+ RCLCPP_INFO(node_->get_logger(), "STARTED!!!");
+
+ planner_->costmap_->worldToMap(start.pose.position.x, start.pose.position.y,
+ reinterpret_cast(planner_->src.x),
+ reinterpret_cast(planner_->src.y));
+
+ planner_->costmap_->worldToMap(goal.pose.position.x, goal.pose.position.y,
+ reinterpret_cast(planner_->dst.x),
+ reinterpret_cast(planner_->dst.y));
+
+ planner_->node_ = node_;
+// planner_->costmap_ = costmap_;
+ planner_->how_many_corners = how_many_corners_;
+ RCLCPP_INFO(node_->get_logger(), "STOPPED APPARENTLY!!!");
+ planner_->makePlan(x, y);
+ RCLCPP_INFO(node_->get_logger(), "NOT REALLY THOUGH!!!");
+
+ global_path = linearInterpolation(interpolation_dist_);
+ x.clear();
+ y.clear();
+ geometry_msgs::msg::PoseStamped pEnd;
+ pEnd.pose.position.x = goal.pose.position.x;
+ pEnd.pose.position.y = goal.pose.position.y;
+ global_path.poses.push_back(pEnd);
+
+ global_path.header.stamp = node_->now();
+ global_path.header.frame_id = globalFrame_;
+
+ return global_path;
+}
+
+nav_msgs::msg::Path planner::linearInterpolation(double distBwPoints)
+{
+ nav_msgs::msg::Path pa;
+ pa.header.frame_id = "map";
+ for (int i = 0; i < static_cast(x.size() - 1); i++) {
+ geometry_msgs::msg::PoseStamped p;
+
+ pts ptCopy = {x[i], y[i]};
+ p.pose.position.x = ptCopy.x;
+ p.pose.position.y = ptCopy.y;
+ pa.poses.push_back(p);
+
+ pts pt2Copy = {x[i + 1], y[i + 1]};
+
+ double distance = std::hypot(pt2Copy.x - ptCopy.x, pt2Copy.y - ptCopy.y);
+ int loops = static_cast(distance / distBwPoints);
+ double sinAlpha = (pt2Copy.y - ptCopy.y) / distance;
+ double cosAlpha = (pt2Copy.x - ptCopy.x) / distance;
+
+ for (int j = 1; j < loops; j++) {
+ p.pose.position.x = ptCopy.x + j * distBwPoints * cosAlpha;
+ p.pose.position.y = ptCopy.y + j * distBwPoints * sinAlpha;
+ pa.poses.push_back(p);
+ }
+
+ p.pose.position.x = pt2Copy.x;
+ p.pose.position.y = pt2Copy.y;
+ pa.poses.push_back(p);
+ }
+
+ return pa;
+}
+
+} // namespace planner
+#include "pluginlib/class_list_macros.hpp"
+PLUGINLIB_EXPORT_CLASS(planner::planner, nav2_core::GlobalPlanner)
From d4dd2631e99e4754aa07242e0bc61e89dcb1c50f Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Sat, 4 Jul 2020 09:31:26 +0530
Subject: [PATCH 06/81] restructured files
---
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
index 7e5aafdb4f..f36860bc65 100644
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -86,22 +86,13 @@ void LazyThetaStarB::makePlan(std::vector & x_path, std::vector &
if (!losCheck(src.x, src.y, dst.x, dst.y)) {
while (pq.size() > 1) {
-
-
-// int moves[8][2] = {{cx, cy + 1},
-// {cx + 1, cy},
-// {cx, cy - 1},
-// {cx - 1, cy},
-// {cx + 1, cy + 1},
-// {cx + 1, cy - 1},
-// {cx - 1, cy - 1},
-// {cx - 1, cy + 1}};
+
int mx, my;
id m_id;
id curr_par = (data[curr_id].parentId);
std::cout << "THE CURRENT POINT IS : " << cx << '\t' << cy << '\n';
- // The condition if current point is the destination
+ // The condition if current point is the destination
if (cx == dst.x && cy == dst.y) {
std::cout<<"Got IT!!!!!!!!!"<<'\n';
if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
From d6f8b8fc85f7973f9226a6c0a199aee93300fb85 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Sat, 4 Jul 2020 09:47:34 +0530
Subject: [PATCH 07/81] Update CMakeLists.txt
---
lazy_theta_star_b/CMakeLists.txt | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/lazy_theta_star_b/CMakeLists.txt b/lazy_theta_star_b/CMakeLists.txt
index dc04e6d324..31d86b63cb 100644
--- a/lazy_theta_star_b/CMakeLists.txt
+++ b/lazy_theta_star_b/CMakeLists.txt
@@ -1,16 +1,9 @@
cmake_minimum_required(VERSION 3.5)
project(lazy_theta_star_b)
-set(CMAKE_C_STANDARD 99)
-set(CMAKE_CXX_STANDARD 14)
-
-
-if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- add_compile_options(-Wall -Wextra -Wpedantic -O3)
-endif()
-
# find dependencies
find_package(ament_cmake REQUIRED)
+find_package(nav2_common REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
@@ -72,12 +65,6 @@ install(FILES global_planner_plugin.xml
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
- # the following line skips the linter which checks for copyrights
- # uncomment the line when a copyright and license is not present in all source files
- # set(ament_cmake_copyright_FOUND TRUE)
- # the following line skips cpplint (only works in a git repo)
- # uncomment the line when this package is not in a git repo
- # set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
From a11fbd9965c1d1d5974833a23fde7ce1c2e99b9d Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Sat, 4 Jul 2020 09:49:42 +0530
Subject: [PATCH 08/81] removed unnecessary comments
---
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 6 +-----
lazy_theta_star_b/src/planner.cpp | 4 ----
2 files changed, 1 insertion(+), 9 deletions(-)
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
index f36860bc65..6dcfc9d61e 100644
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -48,9 +48,6 @@ void LazyThetaStarB::makePlan(std::vector & x_path, std::vector &
if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
!withinLimits(dst.x, dst.y))
{
-// std::cout << !isSafe(src.x, src.y) << '\t' << !isSafe(dst.x, dst.y) << '\t' << !withinLimits(
-// src.x, src.y) << '\t' <<
-// !withinLimits(dst.x, dst.y) << '\n';
RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE!!!!!!");
}
@@ -86,13 +83,12 @@ void LazyThetaStarB::makePlan(std::vector & x_path, std::vector &
if (!losCheck(src.x, src.y, dst.x, dst.y)) {
while (pq.size() > 1) {
-
int mx, my;
id m_id;
id curr_par = (data[curr_id].parentId);
std::cout << "THE CURRENT POINT IS : " << cx << '\t' << cy << '\n';
- // The condition if current point is the destination
+ // The condition if current point is the destination
if (cx == dst.x && cy == dst.y) {
std::cout<<"Got IT!!!!!!!!!"<<'\n';
if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
diff --git a/lazy_theta_star_b/src/planner.cpp b/lazy_theta_star_b/src/planner.cpp
index 3a14b9c160..96dd0ef041 100644
--- a/lazy_theta_star_b/src/planner.cpp
+++ b/lazy_theta_star_b/src/planner.cpp
@@ -76,8 +76,6 @@ nav_msgs::msg::Path planner::createPlan(
{
nav_msgs::msg::Path global_path;
- RCLCPP_INFO(node_->get_logger(), "STARTED!!!");
-
planner_->costmap_->worldToMap(start.pose.position.x, start.pose.position.y,
reinterpret_cast(planner_->src.x),
reinterpret_cast(planner_->src.y));
@@ -89,9 +87,7 @@ nav_msgs::msg::Path planner::createPlan(
planner_->node_ = node_;
// planner_->costmap_ = costmap_;
planner_->how_many_corners = how_many_corners_;
- RCLCPP_INFO(node_->get_logger(), "STOPPED APPARENTLY!!!");
planner_->makePlan(x, y);
- RCLCPP_INFO(node_->get_logger(), "NOT REALLY THOUGH!!!");
global_path = linearInterpolation(interpolation_dist_);
x.clear();
From d6f9584b70f40221bc152d8e4cedc23823138f6b Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Sat, 4 Jul 2020 09:59:56 +0530
Subject: [PATCH 09/81] removed comments
---
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 7 -------
1 file changed, 7 deletions(-)
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
index 6dcfc9d61e..6dfb710be3 100644
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
@@ -333,13 +333,6 @@ void LazyThetaStarB::backtrace(std::vector * waypt, id curr_id)
do {
wayptRev.push_back(curr_id);
curr_id = data[curr_id].parentId;
- if (data[curr_id].got_here == 1) {
- std::cout
- << "------------------------------------------------------> got the same error <-------------------------------------------------------"
- << '\n';
- break;
- }
- data[curr_id].got_here = 1;
} while (curr_id != 0);
wayptRev.push_back(0);
From ca4ac17f7161a6472e5c364bdc78c035746a850c Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:50:30 +0530
Subject: [PATCH 10/81] Delete planner.cpp
---
lazy_theta_star_b/src/planner.cpp | 141 ------------------------------
1 file changed, 141 deletions(-)
delete mode 100644 lazy_theta_star_b/src/planner.cpp
diff --git a/lazy_theta_star_b/src/planner.cpp b/lazy_theta_star_b/src/planner.cpp
deleted file mode 100644
index 96dd0ef041..0000000000
--- a/lazy_theta_star_b/src/planner.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright 2020 Anshumaan Singh
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include
-#include
-#include
-#include "lazy_theta_star_b/planner.h"
-
-namespace planner
-{
-void planner::configure(
- rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
- std::string name, std::shared_ptr tf,
- std::shared_ptr costmapRos)
-{
- planner_ = std::make_unique();
- node_ = parent;
- name_ = name;
- tf_ = tf;
- planner_->costmap_ = costmapRos->getCostmap();
- costmap_ = costmapRos->getCostmap();
- globalFrame_ = costmapRos->getGlobalFrameID();
-
- nav2_util::declare_parameter_if_not_declared(
- node_, name_ + ".howManyCorners", rclcpp::ParameterValue(
- 8));
-
- node_->get_parameter(name_ + ".howManyCorners", how_many_corners_);
-
- if (how_many_corners_ != 8) {
- how_many_corners_ = 4;
- }
-
- nav2_util::declare_parameter_if_not_declared(
- node_, name_ + ".interpolation_dist_", rclcpp::ParameterValue(
- 0.1));
-
- node_->get_parameter(name_ + ".interpolation_dist_", interpolation_dist_);
-}
-
-void planner::cleanup()
-{
- RCLCPP_INFO(
- node_->get_logger(), "CleaningUp plugin %s of type planner",
- name_.c_str());
-}
-
-void planner::activate()
-{
- RCLCPP_INFO(
- node_->get_logger(), "Activating plugin %s of type planner",
- name_.c_str());
-}
-
-void planner::deactivate()
-{
- RCLCPP_INFO(
- node_->get_logger(), "Deactivating plugin %s of type planner",
- name_.c_str());
-}
-
-nav_msgs::msg::Path planner::createPlan(
- const geometry_msgs::msg::PoseStamped & start,
- const geometry_msgs::msg::PoseStamped & goal)
-{
- nav_msgs::msg::Path global_path;
-
- planner_->costmap_->worldToMap(start.pose.position.x, start.pose.position.y,
- reinterpret_cast(planner_->src.x),
- reinterpret_cast(planner_->src.y));
-
- planner_->costmap_->worldToMap(goal.pose.position.x, goal.pose.position.y,
- reinterpret_cast(planner_->dst.x),
- reinterpret_cast(planner_->dst.y));
-
- planner_->node_ = node_;
-// planner_->costmap_ = costmap_;
- planner_->how_many_corners = how_many_corners_;
- planner_->makePlan(x, y);
-
- global_path = linearInterpolation(interpolation_dist_);
- x.clear();
- y.clear();
- geometry_msgs::msg::PoseStamped pEnd;
- pEnd.pose.position.x = goal.pose.position.x;
- pEnd.pose.position.y = goal.pose.position.y;
- global_path.poses.push_back(pEnd);
-
- global_path.header.stamp = node_->now();
- global_path.header.frame_id = globalFrame_;
-
- return global_path;
-}
-
-nav_msgs::msg::Path planner::linearInterpolation(double distBwPoints)
-{
- nav_msgs::msg::Path pa;
- pa.header.frame_id = "map";
- for (int i = 0; i < static_cast(x.size() - 1); i++) {
- geometry_msgs::msg::PoseStamped p;
-
- pts ptCopy = {x[i], y[i]};
- p.pose.position.x = ptCopy.x;
- p.pose.position.y = ptCopy.y;
- pa.poses.push_back(p);
-
- pts pt2Copy = {x[i + 1], y[i + 1]};
-
- double distance = std::hypot(pt2Copy.x - ptCopy.x, pt2Copy.y - ptCopy.y);
- int loops = static_cast(distance / distBwPoints);
- double sinAlpha = (pt2Copy.y - ptCopy.y) / distance;
- double cosAlpha = (pt2Copy.x - ptCopy.x) / distance;
-
- for (int j = 1; j < loops; j++) {
- p.pose.position.x = ptCopy.x + j * distBwPoints * cosAlpha;
- p.pose.position.y = ptCopy.y + j * distBwPoints * sinAlpha;
- pa.poses.push_back(p);
- }
-
- p.pose.position.x = pt2Copy.x;
- p.pose.position.y = pt2Copy.y;
- pa.poses.push_back(p);
- }
-
- return pa;
-}
-
-} // namespace planner
-#include "pluginlib/class_list_macros.hpp"
-PLUGINLIB_EXPORT_CLASS(planner::planner, nav2_core::GlobalPlanner)
From dd1563c68051b73eeba201cb83b5ec41e42ab4d4 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:50:40 +0530
Subject: [PATCH 11/81] Delete lazy_theta_star_b.cpp
---
lazy_theta_star_b/src/lazy_theta_star_b.cpp | 370 --------------------
1 file changed, 370 deletions(-)
delete mode 100644 lazy_theta_star_b/src/lazy_theta_star_b.cpp
diff --git a/lazy_theta_star_b/src/lazy_theta_star_b.cpp b/lazy_theta_star_b/src/lazy_theta_star_b.cpp
deleted file mode 100644
index 6dfb710be3..0000000000
--- a/lazy_theta_star_b/src/lazy_theta_star_b.cpp
+++ /dev/null
@@ -1,370 +0,0 @@
-// Copyright 2020 Anshumaan Singh
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include
-#include "lazy_theta_star_b/lazy_theta_star_b.h"
-
-namespace lazyThetaStarB
-{
-
-void LazyThetaStarB::makePlan(std::vector & x_path, std::vector & y_path)
-{
- RCLCPP_INFO(
- node_->get_logger(), "Path Search Begins");
-
- x_path.clear();
- y_path.clear();
- id id_gen = 0;
- sizeX = costmap_->getSizeInCellsX();
- sizeY = costmap_->getSizeInCellsY();
- posn.clear();
- initializePosn();
-
- std::cout << posn[0] << '\n';
- // has been added so that if the robot is stuck at a place with costmap cost higher than 127
- // then only for that run, the planner be able to give a path
- if (costmap_->getCost(src.x, src.y) >= lethal_cost && costmap_->getCost(src.x, src.y) <= 253) {
- lethal_cost = costmap_->getCost(src.x, src.y);
- }
-
- data.reserve(static_cast( (sizeX) * (sizeY) * 0.01 ) );
- clearRobotCell(src.x, src.y);
-
- RCLCPP_INFO(
- node_->get_logger(), "GOT THE SOURCE AND DESTINATION ------ %i, %i && %i, %i",
- src.x, src.y, dst.x, dst.y);
-
- if (!isSafe(src.x, src.y) || !isSafe(dst.x, dst.y) || !withinLimits(src.x, src.y) ||
- !withinLimits(dst.x, dst.y))
- {
- RCLCPP_INFO(node_->get_logger(), "NO PATH POSSIBLE!!!!!!");
- }
-
- data.push_back({(src.x), (src.y), 0, dist(src.x, src.y, dst.x, dst.y), 0, -1,
- dist(src.x, src.y, dst.x, dst.y)});
-
- addIndex(src.x, src.y, id_gen);
-
- pq.push_back({0, &(data[0].g), &(data[0].f)});
- pq.push_back({0, &(data[0].g), &(data[0].f)});
- // added as a buffer, since my binaryHeapDelMin requires for the start index to 1 instead of 0
-
- // The algorithm begins here
- id curr_id = 0;
- id_gen++;
-
- const int moves[8][2] = {
- {0, +1},
- {0, -1},
- {-1, 0},
- {+1, 0},
- {+1, -1},
- {-1, -1},
- {-1, +1},
- {+1, +1},
- };
-
- int cy;
- int cx;
- cx = (data[curr_id].x);
- cy = (data[curr_id].y);
-
- if (!losCheck(src.x, src.y, dst.x, dst.y)) {
-
- while (pq.size() > 1) {
- int mx, my;
- id m_id;
- id curr_par = (data[curr_id].parentId);
- std::cout << "THE CURRENT POINT IS : " << cx << '\t' << cy << '\n';
-
- // The condition if current point is the destination
- if (cx == dst.x && cy == dst.y) {
- std::cout<<"Got IT!!!!!!!!!"<<'\n';
- if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
- float min_dist = INF_COST;
- int min_dist_id = curr_par;
- std::cout<<"NEED IT!!!!!!!!!"<<'\n';
-
- for (int i = 0; i < how_many_corners; i++) {
- std::cout<<"IT!!!!!!!!!"<<'\n';
- mx = cx + moves[i][0];
- my = cy + moves[i][1];
- if (withinLimits(mx, my)) {
- m_id = getIndex(mx, my);
- if (m_id != 0) {
- if (data[m_id].f < min_dist) {
- min_dist = data[m_id].f;
- min_dist_id = m_id;
- }
- }
- }
- data[curr_id].parentId = min_dist_id;
- data[curr_id].g = data[min_dist_id].g +
- dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
- data[curr_id].f = data[curr_id].g + data[curr_id].h;
- }
- }
- break;
- }
-
- if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
- float min_dist = INF_COST;
- int min_dist_id = curr_par;
-
- for (int i = 0; i < how_many_corners; i++) {
- mx = cx + moves[i][0];
- my = cy + moves[i][1];
- if (withinLimits(mx, my)) {
- m_id = getIndex(mx, my);
- if (m_id != 0) {
- if (data[m_id].f < min_dist) {
- min_dist = data[m_id].f;
- min_dist_id = m_id;
- }
- }
- }
- data[curr_id].parentId = min_dist_id;
- data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x,
- data[min_dist_id].y);
- data[curr_id].f = data[curr_id].g + data[curr_id].h;
- }
- }
- curr_par = data[curr_id].parentId;
-
- for (int i = 0; i < how_many_corners; i++) {
- mx = cx + moves[i][0];
- my = cy + moves[i][1];
-
- if (mx == data[curr_par].x && my == data[curr_par].y) {
- continue;
- }
-
- if (withinLimits(mx, my)) {
- float g_cost = data[curr_par].g + dist(mx, my, data[curr_par].x, data[curr_par].y);
- float h_cost, cal_cost;
- m_id = getIndex(mx, my);
- if (m_id == 0 && isSafe(mx, my)) {
- h_cost = dist(mx, my, dst.x, dst.y);
- cal_cost = g_cost + h_cost;
- data.push_back({mx, my, g_cost, h_cost, curr_par, -1, cal_cost});
- addIndex(mx, my, id_gen);
- pushToPq(id_gen);
- id_gen++;
- continue;
- } else if (m_id != 0) {
- h_cost = data[m_id].h;
- cal_cost = g_cost + h_cost;
- if (data[m_id].f > cal_cost) {
- data[m_id].g = g_cost;
- data[m_id].f = cal_cost;
- data[m_id].parentId = curr_par;
- if (data[m_id].closed == 1) {
- data[m_id].closed = -1;
- pushToPq(m_id);
- }
- }
- continue;
- }
- }
- }
-
- do {
- curr_id = pq[1].pos_id;
- cx = data[curr_id].x;
- cy = data[curr_id].y;
- } while (!isSafe(cx, cy));
- binaryHeapDelMin();
- data[curr_id].closed = -1;
- }
-
- } else {
- RCLCPP_INFO(node_->get_logger(), "Straight Path");
- data.push_back({(dst.x), (dst.y), dist(cx, cy, src.x, src.y), 0, 0});
- curr_id = 1;
- }
-
- RCLCPP_INFO(node_->get_logger(), "REACHED DEST %i, %i", dst.x, dst.y);
-
- backtrace(&path, curr_id);
-
- for (auto & p : path) {
- pts map_coords;
- costmap_->mapToWorld(data[p].x, data[p].y, map_coords.x, map_coords.y);
- RCLCPP_INFO(node_->get_logger(), "%f, %f", map_coords.x, map_coords.y);
- x_path.push_back(map_coords.x);
- y_path.push_back(map_coords.y);
- }
- std::cout << data.size() << '\n';
-
- path.clear();
- data.clear();
-
- pq.clear();
- lethal_cost = LETHAL_COST;
- std::cout << "Publishing the Path" << '\n';
-}
-
-void LazyThetaStarB::binaryHeapDelMin()
-{
- int succ = 2;
- int size = pq.size() - 1;
- int sz = size;
- int hole = 1;
- // the main bottom up part where it compares and assigns the smallest value to the hole
- // remember that for this part the heap starts at index 1
- while (succ < sz) {
- double k1 = *(pq[succ].f);
- double k2 = *(pq[succ + 1].f);
- if (k1 > k2) {
- succ++;
- pq[hole] = pq[succ];
- } else {
- pq[hole] = pq[succ];
- }
- hole = succ;
- succ <<= 1;
- }
- // this part checks if the value to be used to fill the last row's hole is small or not
- // if not small then it slides the small value up till it reaches the apt position
- double bubble = *(pq[sz].f);
- int pred = hole >> 1;
- while (*(pq[pred].f) > bubble) {
- pq[hole] = pq[pred];
- hole = pred;
- pred >>= 1;
- }
- // this part simply assigns the last value in the heap to the hole after checking it
- // for maintaining the heap data structure
- pq[hole] = pq[sz];
- pq.pop_back();
-}
-
-// TODO(Anshhu-man567): FIND A WAY TO PASS THE VALUES BY REFERENCE WHEN CHECKING
-bool LazyThetaStarB::losCheck(int x0, int y0, int x1, int y1)
-{
- int dy = y1 - y0, dx = x1 - x0, f = 0;
- int sx, sy;
-
- if (dy < 0) {
- dy = -dy;
- sy = -1;
- } else {
- sy = 1;
- }
-
- if (dx < 0) {
- dx = -dx;
- sx = -1;
- } else {
- sx = 1;
- }
-
- if (dx >= dy) {
- while (x0 != x1) {
- f += dy;
- if (f >= dx) {
- if (!isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
- return false;
- }
- y0 += sy;
- f -= dx;
- }
- if (f != 0 && !isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
- return false;
- }
- if (dy == 0 && !isSafe2(x0 + (sx - 1) / 2, y0) && !isSafe2(x0 + (sx - 1) / 2, y0 - 1)) {
- return false;
- }
- x0 += sx;
- }
- } else {
- while (y0 != y1) {
- f = f + dx;
- if (f >= dy) {
- if (!isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
- return false;
- }
- x0 += sx;
- f -= dy;
- }
- if (f != 0 && !isSafe2(x0 + (sx - 1) / 2, y0 + (sy - 1) / 2)) {
- return false;
- }
- if (dx == 0 && !isSafe2(x0, y0 + (sy - 1) / 2) && !isSafe2(x0 - 1, y0 + (sy - 1) / 2)) {
- return false;
- }
- y0 += sy;
- }
- }
- return true;
-}
-
-void LazyThetaStarB::initializePosn()
-{
- for (int i = 0; i < sizeY * sizeX; i++) {
- posn.push_back(0);
- }
-}
-
-void LazyThetaStarB::addIndex(const int & cx, const int & cy, const id & index)
-{
- posn[sizeX * cy + cx] = index;
-}
-
-id LazyThetaStarB::getIndex(const int & cx, const int & cy)
-{
- return posn[sizeX * cy + cx];
-}
-
-void LazyThetaStarB::backtrace(std::vector * waypt, id curr_id)
-{
- std::vector wayptRev;
- do {
- wayptRev.push_back(curr_id);
- curr_id = data[curr_id].parentId;
- } while (curr_id != 0);
- wayptRev.push_back(0);
-
- for (int i = wayptRev.size() - 1; i >= 0; i--) {
- waypt->push_back(wayptRev[i]);
- }
-}
-
-void LazyThetaStarB::pushToPq(id & idThis)
-{
- pq.push_back({idThis, &(data[idThis].g), &(data[idThis].f)});
- push_heap(pq.begin() + 1, pq.end(), comp);
-}
-
-bool LazyThetaStarB::isSafe(const int & cx, const int & cy)
-{
- return costmap_->getCost(cx, cy) < lethal_cost;
-}
-
-bool LazyThetaStarB::isSafe2(int cx, int cy)
-{
- return costmap_->getCost(cx, cy) < lethal_cost;
-}
-
-bool LazyThetaStarB::withinLimits(const int & x, const int & y)
-{
- return x > 0 && x <= sizeX && y > 0 && y <= sizeY;
-}
-
-void LazyThetaStarB::clearRobotCell(int mx, int my)
-{
- costmap_->setCost(mx, my, nav2_costmap_2d::FREE_SPACE);
-}
-
-} // namespace lazyThetaStarB
From e099e083392da53f4f474e65e43e76a3e24d898c Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:50:52 +0530
Subject: [PATCH 12/81] Delete lazy_theta_star_b.h
---
.../lazy_theta_star_b/lazy_theta_star_b.h | 122 ------------------
1 file changed, 122 deletions(-)
delete mode 100644 lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
diff --git a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h b/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
deleted file mode 100644
index 9a2641f4d1..0000000000
--- a/lazy_theta_star_b/include/lazy_theta_star_b/lazy_theta_star_b.h
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2020 Anshumaan Singh
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef LAZY_THETA_STAR_B__LAZY_THETA_STAR_B_H_
-#define LAZY_THETA_STAR_B__LAZY_THETA_STAR_B_H_
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include "rclcpp/rclcpp.hpp"
-#include "nav2_costmap_2d/costmap_2d_ros.hpp"
-#include "nav2_costmap_2d/cost_values.hpp"
-
-typedef int id;
-
-#define INF_COST 10000000.0
-#define LETHAL_COST 127
-
-template
-struct pts
-{
- ptsT x, y;
-};
-
-struct pos
-{
- id pos_id;
- double * g;
- double * f;
-};
-
-struct tree_node
-{
- int x, y;
- double g = INF_COST;
- double h = INF_COST;
- id parentId;
- int closed = 0; // 0 - unexplored, 1 - closed, -1 - open
- double f = INF_COST;
- int got_here = 0;
-};
-
-namespace lazyThetaStarB
-{
-
-class LazyThetaStarB
-{
-public:
- int lethal_cost = LETHAL_COST;
-
- nav2_util::LifecycleNode::SharedPtr node_;
- nav2_costmap_2d::Costmap2D * costmap_;
-
- // stores the cell data
- std::vector data;
-
- // stores the raw path given by the planner on the basis of their index in the std::vector data
- std::vector path;
-
- // is the priority queue
- std::vector pq;
- int sizeX = 0;
- int sizeY = 0;
- int how_many_corners;
- pts src{}, dst{};
-
- // The part containing the algorithm
- void makePlan(std::vector & x_path, std::vector & y_path);
-
- // The Line of Sight checking algorithm, takes in the points, and follows the line joining points
- bool losCheck(int x0, int y0, int x1, int y1);
-
- // to pop the minimum value of the queue, it is ever so slightly faster than the stl one,
- // based on the implementation by Peter Sanders (2000)
- void binaryHeapDelMin();
-
- // to compare between values in the priority queue
- static bool comp(pos p1, pos p2)
- {
- return (*(p1.f) != *(p2.f)) ? (*(p1.f) > *(p2.f)) : (*(p1.g) > *(p2.g));
- }
-
- double dist(int & ax, int & ay, int & bx, int & by)
- {
- return sqrt(pow(ax - bx, 2) + pow(ay - by, 2));
- }
-
- bool withinLimits(const int & x, const int & y);
- bool isSafe(const int & cx, const int & cy);
- void pushToPq(id & idThis);
- void clearRobotCell(int mx, int my);
- void backtrace(std::vector * waypt, id curr_id);
-
- // stores the index at which the node data is stored for a particular co-ordinate
- std::vector posn;
-
- // it sets/resets all the values within posn to 0
- void initializePosn();
-
- // functions used to maintain indices
- void addIndex(const int & cx, const int & cy, const id & index);
- id getIndex(const int & cx, const int & cy);
-
- bool isSafe2(int cx, int cy);
-};
-
-} // namespace lazyThetaStarB
-#endif // LAZY_THETA_STAR_B__LAZY_THETA_STAR_B_H_
From efca9625efc55e27023edfb1f544b30e21b1a686 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:51:01 +0530
Subject: [PATCH 13/81] Delete planner.h
---
.../include/lazy_theta_star_b/planner.h | 75 -------------------
1 file changed, 75 deletions(-)
delete mode 100644 lazy_theta_star_b/include/lazy_theta_star_b/planner.h
diff --git a/lazy_theta_star_b/include/lazy_theta_star_b/planner.h b/lazy_theta_star_b/include/lazy_theta_star_b/planner.h
deleted file mode 100644
index 118c8dbbfa..0000000000
--- a/lazy_theta_star_b/include/lazy_theta_star_b/planner.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2020 Anshumaan Singh
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef LAZY_THETA_STAR_B__PLANNER_H_
-#define LAZY_THETA_STAR_B__PLANNER_H_
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "rclcpp/rclcpp.hpp"
-#include "nav2_core/global_planner.hpp"
-#include "nav_msgs/msg/path.hpp"
-#include "nav2_util/robot_utils.hpp"
-#include "nav2_util/lifecycle_node.hpp"
-#include "nav2_costmap_2d/costmap_2d_ros.hpp"
-#include "nav2_costmap_2d/cost_values.hpp"
-#include "nav2_util/node_utils.hpp"
-#include "lazy_theta_star_b/lazy_theta_star_b.h"
-
-namespace planner
-{
-
-template
-struct pts
-{
- ptsT x, y;
-};
-
-class planner : public nav2_core::GlobalPlanner
-{
-public:
- std::shared_ptr tf_;
- nav2_util::LifecycleNode::SharedPtr node_;
- nav2_costmap_2d::Costmap2D * costmap_;
-
- std::string globalFrame_, name_;
- int how_many_corners_;
- double interpolation_dist_;
- std::vector x, y;
- std::unique_ptr planner_;
-
- void configure(
- rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
- std::string name, std::shared_ptr tf,
- std::shared_ptr costmapRos) override;
-
- void cleanup() override;
- void activate() override;
- void deactivate() override;
-
- nav_msgs::msg::Path createPlan(
- const geometry_msgs::msg::PoseStamped & start,
- const geometry_msgs::msg::PoseStamped & goal) override;
-
- nav_msgs::msg::Path linearInterpolation(double distBwPoints);
-};
-
-} // namespace planner
-#endif // LAZY_THETA_STAR_B__PLANNER_H_
From 28925f86ac468bc2ddf989576964483f639f9f79 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:51:10 +0530
Subject: [PATCH 14/81] Delete CMakeLists.txt
---
lazy_theta_star_b/CMakeLists.txt | 75 --------------------------------
1 file changed, 75 deletions(-)
delete mode 100644 lazy_theta_star_b/CMakeLists.txt
diff --git a/lazy_theta_star_b/CMakeLists.txt b/lazy_theta_star_b/CMakeLists.txt
deleted file mode 100644
index 31d86b63cb..0000000000
--- a/lazy_theta_star_b/CMakeLists.txt
+++ /dev/null
@@ -1,75 +0,0 @@
-cmake_minimum_required(VERSION 3.5)
-project(lazy_theta_star_b)
-
-# find dependencies
-find_package(ament_cmake REQUIRED)
-find_package(nav2_common REQUIRED)
-find_package(rclcpp REQUIRED)
-find_package(rclcpp_action REQUIRED)
-find_package(rclcpp_lifecycle REQUIRED)
-find_package(visualization_msgs REQUIRED)
-find_package(nav2_util REQUIRED)
-find_package(nav2_msgs REQUIRED)
-find_package(builtin_interfaces REQUIRED)
-find_package(tf2_ros REQUIRED)
-find_package(nav2_costmap_2d REQUIRED)
-find_package(pluginlib REQUIRED)
-find_package(nav2_core REQUIRED)
-
-include_directories(
- include
-)
-
-set(library_name ${PROJECT_NAME}_plugin)
-
-set(dependencies
- rclcpp
- rclcpp_action
- rclcpp_lifecycle
- std_msgs
- visualization_msgs
- nav2_util
- nav2_msgs
- builtin_interfaces
- tf2_ros
- nav2_costmap_2d
- nav2_core
- pluginlib
- )
-
-add_library(${library_name} SHARED
- src/planner.cpp
- src/lazy_theta_star_b.cpp
- )
-ament_target_dependencies(${library_name}
- ${dependencies}
- )
-
-target_compile_definitions(${library_name} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
-
-pluginlib_export_plugin_description_file(nav2_core global_planner_plugin.xml)
-
-install(TARGETS ${library_name}
- ARCHIVE DESTINATION lib
- LIBRARY DESTINATION lib
- RUNTIME DESTINATION lib/${PROJECT_NAME}
- )
-
-install(DIRECTORY include/
- DESTINATION include/
- )
-
-install(FILES global_planner_plugin.xml
- DESTINATION share/${PROJECT_NAME}
- )
-
-if(BUILD_TESTING)
- find_package(ament_lint_auto REQUIRED)
- ament_lint_auto_find_test_dependencies()
-endif()
-
-
-ament_export_include_directories(include)
-ament_export_libraries(${library_name})
-ament_export_dependencies(${dependencies})
-ament_package()
From c35ea2bfc0359bd78c39d364e1e5e0f566588789 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:51:21 +0530
Subject: [PATCH 15/81] Delete global_planner_plugin.xml
---
lazy_theta_star_b/global_planner_plugin.xml | 5 -----
1 file changed, 5 deletions(-)
delete mode 100644 lazy_theta_star_b/global_planner_plugin.xml
diff --git a/lazy_theta_star_b/global_planner_plugin.xml b/lazy_theta_star_b/global_planner_plugin.xml
deleted file mode 100644
index 5eb448e56b..0000000000
--- a/lazy_theta_star_b/global_planner_plugin.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- The implementation of lazy theta_star
-
-
\ No newline at end of file
From d7f50d081641fa0a545d7fdb5184c57ee0e6c026 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:51:28 +0530
Subject: [PATCH 16/81] Delete package.xml
---
lazy_theta_star_b/package.xml | 32 --------------------------------
1 file changed, 32 deletions(-)
delete mode 100644 lazy_theta_star_b/package.xml
diff --git a/lazy_theta_star_b/package.xml b/lazy_theta_star_b/package.xml
deleted file mode 100644
index fa361b2860..0000000000
--- a/lazy_theta_star_b/package.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
- lazy_theta_star_b
- 0.4.0
- TODO: Package description
- anshu-man
- Apache-2.0
-
- ament_cmake
- rclcpp
- nav2_core
- rclcpp_action
- rclcpp_lifecycle
- std_msgs
- visualization_msgs
- nav2_util
- nav2_msgs
- builtin_interfaces
- tf2_ros
- nav2_costmap_2d
- pluginlib
-
- ament_lint_auto
- ament_lint_common
- ament_cmake_gtest
-
-
- ament_cmake
-
-
-
From 99efed3524ecf493c7b58e0e8d416cc5efc3d28d Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 18:57:05 +0530
Subject: [PATCH 17/81] replaced the files
- refactored code
- improved reliability
- have to write a code similar to that in nav2_system_tests, to test it (working on it)
---
lazy_theta_star_planner/CMakeLists.txt | 77 ++++
.../global_planner_plugin.xml | 5 +
.../lazy_theta_star2.h | 144 +++++++
.../lazy_theta_star_planner.h | 77 ++++
lazy_theta_star_planner/package.xml | 31 ++
.../src/lazy_theta_star2.cpp | 364 ++++++++++++++++++
.../src/lazy_theta_star_planner.cpp | 151 ++++++++
7 files changed, 849 insertions(+)
create mode 100644 lazy_theta_star_planner/CMakeLists.txt
create mode 100644 lazy_theta_star_planner/global_planner_plugin.xml
create mode 100644 lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star2.h
create mode 100644 lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star_planner.h
create mode 100644 lazy_theta_star_planner/package.xml
create mode 100644 lazy_theta_star_planner/src/lazy_theta_star2.cpp
create mode 100644 lazy_theta_star_planner/src/lazy_theta_star_planner.cpp
diff --git a/lazy_theta_star_planner/CMakeLists.txt b/lazy_theta_star_planner/CMakeLists.txt
new file mode 100644
index 0000000000..3e77dd3e6f
--- /dev/null
+++ b/lazy_theta_star_planner/CMakeLists.txt
@@ -0,0 +1,77 @@
+cmake_minimum_required(VERSION 3.5)
+project(lazy_theta_star_planner)
+
+find_package(ament_cmake REQUIRED)
+find_package(builtin_interfaces REQUIRED)
+find_package(nav2_common REQUIRED)
+find_package(nav2_core REQUIRED)
+find_package(nav2_costmap_2d REQUIRED)
+find_package(nav2_msgs REQUIRED)
+find_package(nav2_util REQUIRED)
+find_package(pluginlib REQUIRED)
+find_package(rclcpp REQUIRED)
+find_package(rclcpp_action REQUIRED)
+find_package(rclcpp_lifecycle REQUIRED)
+find_package(tf2_ros REQUIRED)
+find_package(ament_cmake_gtest REQUIRED)
+
+include_directories(
+ include
+)
+
+set(library_name ${PROJECT_NAME}_plugin)
+
+set(dependencies
+ ament_cmake
+ builtin_interfaces
+ nav2_common
+ nav2_core
+ nav2_costmap_2d
+ nav2_msgs
+ nav2_util
+ pluginlib
+ rclcpp
+ rclcpp_action
+ rclcpp_lifecycle
+ tf2_ros
+ )
+
+add_library(${library_name} SHARED
+ src/lazy_theta_star2.cpp
+ src/lazy_theta_star_planner.cpp
+ )
+
+ament_target_dependencies(${library_name}
+ ${dependencies}
+ )
+
+target_compile_definitions(${library_name} PUBLIC "PLUGINLIB_DISABLE_BOOST_FUNCTIONS")
+
+pluginlib_export_plugin_description_file(nav2_core global_planner_plugin.xml)
+
+install(TARGETS ${library_name}
+ ARCHIVE DESTINATION lib
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION lib/${PROJECT_NAME}
+ )
+
+install(DIRECTORY include/
+ DESTINATION include/
+ )
+
+install(FILES global_planner_plugin.xml
+ DESTINATION share/${PROJECT_NAME}
+ )
+
+
+
+if(BUILD_TESTING)
+ find_package(ament_lint_auto REQUIRED)
+ ament_lint_auto_find_test_dependencies()
+endif()
+
+
+ament_export_include_directories(include)
+ament_export_libraries(${library_name})
+ament_export_dependencies(${dependencies})
+ament_package()
diff --git a/lazy_theta_star_planner/global_planner_plugin.xml b/lazy_theta_star_planner/global_planner_plugin.xml
new file mode 100644
index 0000000000..f6f6ef3288
--- /dev/null
+++ b/lazy_theta_star_planner/global_planner_plugin.xml
@@ -0,0 +1,5 @@
+
+
+ The implementation of lazy theta_star
+
+
\ No newline at end of file
diff --git a/lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star2.h b/lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star2.h
new file mode 100644
index 0000000000..ac7a31720f
--- /dev/null
+++ b/lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star2.h
@@ -0,0 +1,144 @@
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef LAZY_THETA_STAR_B__LAZY_THETA_STAR_H_
+#define LAZY_THETA_STAR_B__LAZY_THETA_STAR_H_
+
+#include
+#include
+#include
+#include
+#include "rclcpp/rclcpp.hpp"
+#include "nav2_costmap_2d/costmap_2d_ros.hpp"
+#include "nav2_costmap_2d/cost_values.hpp"
+
+typedef int id;
+typedef double cost;
+typedef int map_pts;
+typedef double world_pts;
+
+#define INF_COST DBL_MAX
+#define LETHAL_COST 252
+
+template
+struct coords
+{
+ coordsT x, y;
+};
+
+struct pos
+{
+ id pos_id;
+ cost * f;
+};
+
+struct tree_node
+{
+ map_pts x, y;
+ cost g = INF_COST;
+ cost h = INF_COST;
+ id parent_id;
+ int closed = 0;
+ cost f = INF_COST;
+// int counter = 0;
+ int got_here = 0;
+};
+
+namespace lazyThetaStar
+{
+class LazyThetaStar
+{
+public:
+ nav2_costmap_2d::Costmap2D * costmap_;
+ nav2_util::LifecycleNode::SharedPtr node_;
+
+ std::vector posn;
+ std::vector data;
+ std::vector pq;
+ int sizeX, sizeY;
+ int how_many_corners;
+ id id_gen;
+ coords src{}, dst{};
+ int lethal_cost = LETHAL_COST;
+
+ const map_pts moves[8][2] = {{0, 1},
+ {0, -1},
+ {1, 0},
+ {-1, 0},
+ {1, -1},
+ {-1, 1},
+ {1, 1},
+ {-1, -1}};
+
+ LazyThetaStar();
+
+ bool getPath(std::vector> & raw_path);
+
+
+ bool losCheck(map_pts & x0, map_pts & y0, map_pts & x1, map_pts & y1) const;
+
+ cost dist(map_pts & ax, map_pts & ay, map_pts & bx, map_pts & by)
+ {
+ return sqrt(pow(ax - bx, 2) + pow(ay - by, 2));
+ }
+
+ // TODO : FIND A WAY TO ADD REFERENCES TO THIS FUNCTION
+ bool isSafe(map_pts cx, map_pts cy) const
+ {
+ return costmap_->getCost(cx, cy) < lethal_cost;
+ }
+
+ bool withinLimits(map_pts & cx, map_pts & cy) const
+ {
+ return cx >= 0 && cx < sizeX && cy >= 0 && cy < sizeY;
+ }
+
+ void addIndex(map_pts cx, map_pts cy, id id_this)
+ {
+ posn[sizeX * cy + cx] = id_this;
+ }
+
+ void getIndex(map_pts & cx, map_pts & cy, id & id_this)
+ {
+ id_this = posn[sizeX * cy + cx];
+ }
+ void initializePosn();
+
+ void binaryHeapDelMin();
+
+ void pushToPq(id id_this);
+
+ static bool comp(pos & p1, pos & p2)
+ {
+ return *(p1.f) > *(p2.f);
+ }
+
+ void backtrace(std::vector> & raw_points, id & curr_id);
+
+ void resetParent(map_pts & cx, map_pts & cy, id & curr_id);
+
+ bool isGoal(map_pts & cx, map_pts & cy);
+
+ void setNeighbors(map_pts & cx, map_pts & cy, id & curr_id);
+
+ void initializeStuff();
+
+ void clearStuff();
+
+ void getNextNode(id & curr_id);
+
+};
+} // namespace lazyThetaStar
+
+#endif //LAZY_THETA_STAR_B_LAZY_THETA_STAR_H
diff --git a/lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star_planner.h b/lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star_planner.h
new file mode 100644
index 0000000000..e263bd1670
--- /dev/null
+++ b/lazy_theta_star_planner/include/lazy_theta_star_planner/lazy_theta_star_planner.h
@@ -0,0 +1,77 @@
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef LAZY_THETA_STAR_PLANNER__LAZY_THETA_STAR_PLANNER_H_
+#define LAZY_THETA_STAR_PLANNER__LAZY_THETA_STAR_PLANNER_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "rclcpp/rclcpp.hpp"
+#include "nav2_core/global_planner.hpp"
+#include "nav_msgs/msg/path.hpp"
+#include "nav2_util/robot_utils.hpp"
+#include "nav2_util/lifecycle_node.hpp"
+#include "nav2_costmap_2d/costmap_2d_ros.hpp"
+#include "nav2_costmap_2d/cost_values.hpp"
+#include "nav2_util/node_utils.hpp"
+#include "lazy_theta_star2.h"
+
+namespace lazyThetaStarPlanner
+{
+
+class LazyThetaStarPlanner : public nav2_core::GlobalPlanner
+{
+public:
+ std::shared_ptr tf_;
+ nav2_util::LifecycleNode::SharedPtr node_;
+ nav2_costmap_2d::Costmap2D * costmap_;
+
+ std::string globalFrame_, name_;
+ int how_many_corners_;
+ double interpolation_dist_;
+ std::unique_ptr planner_;
+
+
+ unsigned int src_[2], dst_[2];
+
+ void configure(
+ rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
+ std::string name, std::shared_ptr tf,
+ std::shared_ptr costmapRos) override;
+
+ void cleanup() override;
+
+ void activate() override;
+
+ void deactivate() override;
+
+ nav_msgs::msg::Path createPlan(
+ const geometry_msgs::msg::PoseStamped & start,
+ const geometry_msgs::msg::PoseStamped & goal) override;
+
+ nav_msgs::msg::Path linearInterpolation(
+ std::vector> & raw_path,
+ double dist_bw_points);
+
+};
+
+} // namespace planner
+
+#endif //LAZY_THETA_STAR_PLANNER__LAZY_THETA_STAR_PLANNER_H_
diff --git a/lazy_theta_star_planner/package.xml b/lazy_theta_star_planner/package.xml
new file mode 100644
index 0000000000..682a84b703
--- /dev/null
+++ b/lazy_theta_star_planner/package.xml
@@ -0,0 +1,31 @@
+
+
+
+ lazy_theta_star_planner
+ 0.0.1
+ TODO: Package description
+ anshu-man
+ Apache-2.0
+
+ ament_cmake
+ rclcpp
+ nav2_core
+ rclcpp_action
+ rclcpp_lifecycle
+ std_msgs
+ visualization_msgs
+ nav2_util
+ nav2_msgs
+ builtin_interfaces
+ tf2_ros
+ nav2_costmap_2d
+ pluginlib
+
+ ament_lint_auto
+ ament_lint_common
+
+
+ ament_cmake
+
+
+
diff --git a/lazy_theta_star_planner/src/lazy_theta_star2.cpp b/lazy_theta_star_planner/src/lazy_theta_star2.cpp
new file mode 100644
index 0000000000..12bd6a87a5
--- /dev/null
+++ b/lazy_theta_star_planner/src/lazy_theta_star2.cpp
@@ -0,0 +1,364 @@
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http:// www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "lazy_theta_star_planner/lazy_theta_star2.h"
+#include
+
+namespace lazyThetaStar
+{
+
+LazyThetaStar::LazyThetaStar()
+{
+ sizeX = 0;
+ sizeY = 0;
+}
+
+bool LazyThetaStar::getPath(std::vector> & raw_path)
+{
+ RCLCPP_INFO(node_->get_logger(), "Path Planning Begins....");
+
+ initializeStuff();
+
+ std::cout << src.x << '\t' << src.y << '\t' << dst.x << '\t' << dst.y << '\n';
+
+ data.push_back({src.x, src.y, 0, dist(src.x, src.y, dst.x, dst.y),
+ 0, 1, dist(src.x, src.y, dst.x, dst.y)});
+ addIndex(src.x, src.y, id_gen);
+ pushToPq(id_gen);
+ pushToPq(id_gen);
+ // extra one added due to binaryHeapDelMin starting from index 1
+
+ id_gen++;
+ id curr_id = 0;
+// map_pts cx = src.x, cy = src.y;
+
+ if (!losCheck(src.x, src.y, dst.x, dst.y)) {
+
+ while (pq.size() > 0) {
+
+ map_pts cx = data[curr_id].x;
+ map_pts cy = data[curr_id].y;
+ std::cout << "the current point is : \t\t\t" << cx << '\t' << cy << '\t' << data[curr_id].f <<
+ '\n';
+ id curr_par = data[curr_id].parent_id;
+
+ if (isGoal(cx, cy)) {
+ if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
+ resetParent(cx, cy, curr_id);
+ }
+ break;
+ }
+
+ std::cout << "ITS PARENTS WERE : " << data[curr_par].x << '\t' << data[curr_par].y << '\t' <<
+ curr_par << '\n';
+ if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
+ resetParent(cx, cy, curr_id);
+ }
+
+ setNeighbors(cx, cy, curr_id);
+
+ getNextNode(curr_id);
+ }
+
+ if (pq.size() < 1) {
+ RCLCPP_INFO(node_->get_logger(), "No Path Found !!!!!!!!!!!");
+ raw_path.clear();
+ return false;
+ }
+
+ } else {
+ RCLCPP_INFO(node_->get_logger(), "Straight Line Path Found!");
+ data.push_back({dst.x, dst.y, dist(src.x, src.y, dst.x, dst.y), 0, 0, 1,
+ dist(src.x, src.y, dst.x, dst.y)});
+ curr_id = id_gen;
+ }
+
+ RCLCPP_INFO(node_->get_logger(), "REACHED DEST %i, %i", data[curr_id].x, data[curr_id].y);
+
+ backtrace(raw_path, curr_id);
+
+ RCLCPP_INFO(node_->get_logger(), "Out of it with path_length %i", raw_path.size());
+ return true;
+}
+
+void LazyThetaStar::initializePosn()
+{
+ posn.clear();
+ for (int i = 0; i < sizeX * sizeY; i++) {
+ posn.push_back(-1);
+ }
+}
+
+bool LazyThetaStar::losCheck(map_pts & x0, map_pts & y0, map_pts & x1, map_pts & y1) const
+{
+ int dy = y1 - y0, dx = x1 - x0, f = 0;
+ int sx, sy;
+ int cx = x0, cy = y0;
+
+ if (dy < 0) {
+ dy = -dy;
+ sy = -1;
+ } else {
+ sy = 1;
+ }
+
+ if (dx < 0) {
+ dx = -dx;
+ sx = -1;
+ } else {
+ sx = 1;
+ }
+
+ if (dx >= dy) {
+ while (cx != x1) {
+ f += dy;
+ if (f >= dx) {
+ if (!isSafe(cx + (sx - 1) / 2, cy + (sy - 1) / 2)) {
+ return false;
+ }
+ cy += sy;
+ f -= dx;
+ }
+ if (f != 0 && !isSafe(cx + (sx - 1) / 2, cy + (sy - 1) / 2)) {
+ return false;
+ }
+ if (dy == 0 && !isSafe(cx + (sx - 1) / 2, cy) && !isSafe(cx + (sx - 1) / 2, cy - 1)) {
+ return false;
+ }
+ cx += sx;
+ }
+ } else {
+ while (cy != y1) {
+ f = f + dx;
+ if (f >= dy) {
+ if (!isSafe(cx + (sx - 1) / 2, cy + (sy - 1) / 2)) {
+ return false;
+ }
+ cx += sx;
+ f -= dy;
+ }
+ if (f != 0 && !isSafe(cx + (sx - 1) / 2, cy + (sy - 1) / 2)) {
+ return false;
+ }
+ if (dx == 0 && !isSafe(cx, cy + (sy - 1) / 2) && !isSafe(cx - 1, cy + (sy - 1) / 2)) {
+ return false;
+ }
+ cy += sy;
+ }
+ }
+ return true;
+}
+
+void LazyThetaStar::binaryHeapDelMin()
+{
+ pop_heap(pq.begin() + 1, pq.end(), comp);
+ pq.pop_back();
+// int hole = 1;
+// int succ = 2, size = pq.size() - 1, sz = size;
+// // the main bottom up part where it compares and assigns the smallest value to the hole
+// // remember that for this part the heap starts at index 1
+//
+// while (succ < sz) {
+// double k1 = *(pq[succ].f);
+// double k2 = *(pq[succ + 1].f);
+// // std::cout< k2) {
+// // std::cout<<"came 1"<<'\n';
+// succ++;
+// // data[hole].key = k2;
+// pq[hole] = pq[succ];
+// } else {
+// // std::cout<<"came 2"<<'\n';
+// // data[hole].key = k1;
+// pq[hole] = pq[succ];
+// }
+// hole = succ;
+// succ <<= 1;
+// }
+//
+// // this part checks if the value to be used to fill the last row's hole is small or not
+// // if not small then it slides the small value up till it reaches the apt position
+// double bubble = *(pq[sz].f);
+// int pred = hole >> 1;
+// // std::cout<<"HERE"<<'\t'< bubble) {
+// // std::cout<<"HERE"<<'\t'<>= 1;
+// }
+// // std::cout<<"HERE AT:"<<'\t'<> & raw_points, id & curr_id)
+{
+ std::vector> path_rev;
+ do {
+ coords world;
+ costmap_->mapToWorld(data[curr_id].x, data[curr_id].y, world.x, world.y);
+ path_rev.push_back({world.x, world.y});
+ RCLCPP_INFO(
+ node_->get_logger(), "%i, %i ---> %f, %f", data[curr_id].x, data[curr_id].y, world.x,
+ world.y);
+ if (data[curr_id].got_here == 1) {
+ std::cout <<
+ "------------------------------------------------------> got the same error <-------------------------------------------------------"
+ <<
+ '\n';
+ break;
+ }
+ data[curr_id].got_here = 1;
+ curr_id = data[curr_id].parent_id;
+ } while (curr_id != 0);
+ coords w;
+ costmap_->mapToWorld(data[curr_id].x, data[curr_id].y, w.x, w.y);
+ path_rev.push_back({w.x, w.y});
+ RCLCPP_INFO(
+ node_->get_logger(), "%i, %i ---> %f, %f", data[curr_id].x, data[curr_id].y, w.x, w.y);
+
+ for (int i = path_rev.size() - 1; i >= 0; i--) {
+ raw_points.push_back(path_rev[i]);
+ }
+}
+
+void LazyThetaStar::resetParent(map_pts & cx, map_pts & cy, id & curr_id)
+{
+ map_pts mx, my;
+ id m_id;
+ cost min_dist = INF_COST;
+ id min_dist_id;
+
+ for (int i = 0; i < how_many_corners; i++) {
+ mx = cx + moves[i][0];
+ my = cy + moves[i][1];
+ if (withinLimits(mx, my)) {
+ getIndex(mx, my, m_id);
+ if (m_id != -1) {
+ if (data[m_id].f < min_dist) {
+ min_dist = data[m_id].f;
+ min_dist_id = m_id;
+ }
+ }
+ }
+ }
+ data[curr_id].parent_id = min_dist_id;
+ data[curr_id].g = data[min_dist_id].g + dist(cx, cy, data[min_dist_id].x, data[min_dist_id].y);
+ data[curr_id].f = data[curr_id].g + data[curr_id].h;
+}
+
+bool LazyThetaStar::isGoal(map_pts & cx, map_pts & cy)
+{
+ return cx == dst.x && cy == dst.y;
+}
+
+void LazyThetaStar::setNeighbors(map_pts & cx, map_pts & cy, id & curr_id)
+{
+ id curr_par = data[curr_id].parent_id;
+ std::cout << "ITS PARENTS ARE : " << data[curr_par].x << '\t' << data[curr_par].y << '\t' <<
+ curr_par << '\n';
+ map_pts px = data[curr_par].x, py = data[curr_par].y;
+ cost g_cost_par = data[curr_par].g;
+
+ map_pts mx, my;
+ id m_id;
+ for (int i = 0; i < 8; i++) {
+ mx = cx + moves[i][0];
+ my = cy + moves[i][1];
+ if (mx == px && my == py) {
+ continue;
+ }
+
+ if (withinLimits(mx, my)) {
+ cost g_cost = g_cost_par + dist(mx, my, px, py);
+ cost h_cost, cal_cost;
+ getIndex(mx, my, m_id);
+
+ if (isSafe(mx, my) && m_id == -1) {
+ h_cost = dist(mx, my, dst.x, dst.y);
+ cal_cost = g_cost + h_cost;
+ data.push_back({mx, my, g_cost, h_cost, curr_par, -1, cal_cost});
+ pushToPq(id_gen);
+ std::cout << "ADDED INDEX 1:" << data[id_gen].x << '\t' << data[id_gen].y << '\t' <<
+ data[id_gen].f << '\n';
+ addIndex(mx, my, id_gen);
+ id_gen++;
+ continue;
+ } else if (m_id != -1) {
+ tree_node & curr_node = data[m_id];
+ h_cost = curr_node.h;
+ cal_cost = g_cost + h_cost;
+ if (curr_node.f > cal_cost) {
+ curr_node.g = g_cost;
+ curr_node.f = cal_cost;
+ curr_node.parent_id = curr_par;
+ if (curr_node.closed == 1) {
+ curr_node.closed = -1;
+ pushToPq(m_id);
+ std::cout << "ADDED INDEX 2:" << data[m_id].x << '\t' << data[m_id].y << '\t' <<
+ data[m_id].f << '\n';
+ }
+ }
+ continue;
+ }
+ }
+ }
+}
+
+void LazyThetaStar::initializeStuff()
+{
+ id_gen = 0;
+ sizeX = costmap_->getSizeInCellsX();
+ sizeY = costmap_->getSizeInCellsY();
+ std::cout << sizeX << '\t' << sizeY << '\n';
+ initializePosn();
+ data.reserve(static_cast(sizeX * sizeY * 0.05));
+}
+
+void LazyThetaStar::clearStuff()
+{
+ data.clear();
+ pq.clear();
+ posn.clear();
+}
+
+void LazyThetaStar::getNextNode(id & curr_id)
+{
+ curr_id = pq[1].pos_id;
+ data[curr_id].closed = -1;
+ binaryHeapDelMin();
+}
+
+
+//void LazyThetaStar::tfMapToWorld(
+// map_pts & mx,
+// map_pts & my,
+// world_pts & wx,
+// world_pts & wy);
+//{
+//wx = costmap_->getOriginX() + (mx) * costmap_->getResolution();
+//wy = costmap_->getOriginY() + (my) * costmap_->getResolution();
+//}
+
+} // namespace lazyThetaStar
diff --git a/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp b/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp
new file mode 100644
index 0000000000..502f5f70aa
--- /dev/null
+++ b/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp
@@ -0,0 +1,151 @@
+// Copyright 2020 Anshumaan Singh
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include
+#include
+#include
+#include "lazy_theta_star_planner/lazy_theta_star_planner.h"
+#include "lazy_theta_star_planner/lazy_theta_star2.h"
+
+
+namespace lazyThetaStarPlanner
+{
+void LazyThetaStarPlanner::configure(
+ rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
+ std::string name, std::shared_ptr tf,
+ std::shared_ptr costmapRos)
+{
+ planner_ = std::make_unique();
+ node_ = parent;
+ name_ = name;
+ planner_->costmap_ = costmapRos->getCostmap();
+ globalFrame_ = costmapRos->getGlobalFrameID();
+
+ nav2_util::declare_parameter_if_not_declared(
+ node_, name_ + ".how_many_corners", rclcpp::ParameterValue(
+ 8));
+
+ node_->get_parameter(name_ + ".how_many_corners", how_many_corners_);
+
+ if (how_many_corners_ != 8) {
+ how_many_corners_ = 4;
+ }
+
+ nav2_util::declare_parameter_if_not_declared(
+ node_, name_ + ".interpolation_dist", rclcpp::ParameterValue(
+ 0.1));
+
+ node_->get_parameter(name_ + ".interpolation_dist", interpolation_dist_);
+
+}
+
+void LazyThetaStarPlanner::cleanup()
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "CleaningUp plugin %s of type lazyThetaStarPlanner",
+ name_.c_str());
+}
+
+void LazyThetaStarPlanner::activate()
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "Activating plugin %s of type lazyThetaStarPlanner",
+ name_.c_str());
+}
+
+void LazyThetaStarPlanner::deactivate()
+{
+ RCLCPP_INFO(
+ node_->get_logger(), "Deactivating plugin %s of type lazyThetaStarPlanner",
+ name_.c_str());
+}
+
+nav_msgs::msg::Path LazyThetaStarPlanner::createPlan(
+ const geometry_msgs::msg::PoseStamped & start,
+ const geometry_msgs::msg::PoseStamped & goal)
+{
+ nav_msgs::msg::Path global_path;
+ std::vector> path;
+
+ planner_->costmap_->worldToMap(start.pose.position.x, start.pose.position.y, src_[0], src_[1]);
+ planner_->src = {static_cast(src_[0]), static_cast(src_[1])};
+
+ planner_->costmap_->worldToMap(goal.pose.position.x, goal.pose.position.y, dst_[0], dst_[1]);
+ planner_->dst = {static_cast(dst_[0]), static_cast(dst_[1])};
+
+ RCLCPP_INFO(
+ node_->get_logger(), "Got the src and dst... (%i, %i) && (%i, %i)", planner_->src.x, planner_->src.y,
+ planner_->dst.x, planner_->dst.y);
+
+ planner_->node_ = node_;
+ planner_->how_many_corners = how_many_corners_;
+ planner_->lethal_cost = LETHAL_COST;
+
+ planner_->initializeStuff();
+ planner_->getPath(path);
+ planner_->clearStuff();
+
+ RCLCPP_INFO(node_->get_logger(), "RECEIVED THE PATH");
+
+ if (path.size() > 1) {
+
+ for (int i = 0; i < path.size(); i++) {
+ std::cout << path[i].x << '\t' << path[i].y << '\n';
+ }
+
+ global_path = linearInterpolation(path, 0.1);
+ } else {
+ global_path.poses.clear();
+ }
+ path.clear();
+ std::cout << global_path.poses.size() << '\n';
+ global_path.header.stamp = node_->now();
+ global_path.header.frame_id = globalFrame_;
+ RCLCPP_INFO(node_->get_logger(), "SENT OUT THE PATH");
+ return global_path;
+}
+
+nav_msgs::msg::Path LazyThetaStarPlanner::linearInterpolation(
+ std::vector> & raw_path,
+ double dist_bw_points)
+{
+ nav_msgs::msg::Path pa;
+
+ for (int j = 0; j < raw_path.size() - 1; j++) {
+ geometry_msgs::msg::PoseStamped p;
+ coords pt1 = {raw_path[j].x, raw_path[j].y};
+ p.pose.position.x = pt1.x;
+ p.pose.position.y = pt1.y;
+ pa.poses.push_back(p);
+
+ coords pt2 = {raw_path[j + 1].x, raw_path[j + 1].y};
+ geometry_msgs::msg::PoseStamped p1;
+ double distance = std::hypot(pt2.x - pt1.x, pt2.y - pt1.y);
+ int loops = distance / dist_bw_points;
+ double sin_alpha = (pt2.y - pt1.y) / distance;
+ double cos_alpha = (pt2.x - pt1.x) / distance;
+ for (int k = 1; k < loops; k++) {
+ p1.pose.position.x = pt1.x + k * dist_bw_points * cos_alpha;
+ p1.pose.position.y = pt1.y + k * dist_bw_points * sin_alpha;
+ pa.poses.push_back(p1);
+ }
+ }
+ return pa;
+}
+
+} // namespace lazyThetaStarPlanner
+
+#include "pluginlib/class_list_macros.hpp"
+
+PLUGINLIB_EXPORT_CLASS(lazyThetaStarPlanner::LazyThetaStarPlanner, nav2_core::GlobalPlanner)
From f4a622b64a9861b55aac9737bae80e258d87ae8b Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 19:03:13 +0530
Subject: [PATCH 18/81] removed comments
---
.../src/lazy_theta_star2.cpp | 118 +++++++-----------
1 file changed, 46 insertions(+), 72 deletions(-)
diff --git a/lazy_theta_star_planner/src/lazy_theta_star2.cpp b/lazy_theta_star_planner/src/lazy_theta_star2.cpp
index 12bd6a87a5..ea52ee5602 100644
--- a/lazy_theta_star_planner/src/lazy_theta_star2.cpp
+++ b/lazy_theta_star_planner/src/lazy_theta_star2.cpp
@@ -41,7 +41,6 @@ bool LazyThetaStar::getPath(std::vector> & raw_path)
id_gen++;
id curr_id = 0;
-// map_pts cx = src.x, cy = src.y;
if (!losCheck(src.x, src.y, dst.x, dst.y)) {
@@ -49,8 +48,6 @@ bool LazyThetaStar::getPath(std::vector> & raw_path)
map_pts cx = data[curr_id].x;
map_pts cy = data[curr_id].y;
- std::cout << "the current point is : \t\t\t" << cx << '\t' << cy << '\t' << data[curr_id].f <<
- '\n';
id curr_par = data[curr_id].parent_id;
if (isGoal(cx, cy)) {
@@ -60,8 +57,6 @@ bool LazyThetaStar::getPath(std::vector> & raw_path)
break;
}
- std::cout << "ITS PARENTS WERE : " << data[curr_par].x << '\t' << data[curr_par].y << '\t' <<
- curr_par << '\n';
if (!(losCheck(cx, cy, data[curr_par].x, data[curr_par].y))) {
resetParent(cx, cy, curr_id);
}
@@ -87,8 +82,7 @@ bool LazyThetaStar::getPath(std::vector> & raw_path)
RCLCPP_INFO(node_->get_logger(), "REACHED DEST %i, %i", data[curr_id].x, data[curr_id].y);
backtrace(raw_path, curr_id);
-
- RCLCPP_INFO(node_->get_logger(), "Out of it with path_length %i", raw_path.size());
+
return true;
}
@@ -162,48 +156,48 @@ bool LazyThetaStar::losCheck(map_pts & x0, map_pts & y0, map_pts & x1, map_pts &
void LazyThetaStar::binaryHeapDelMin()
{
- pop_heap(pq.begin() + 1, pq.end(), comp);
- pq.pop_back();
-// int hole = 1;
-// int succ = 2, size = pq.size() - 1, sz = size;
-// // the main bottom up part where it compares and assigns the smallest value to the hole
-// // remember that for this part the heap starts at index 1
-//
-// while (succ < sz) {
-// double k1 = *(pq[succ].f);
-// double k2 = *(pq[succ + 1].f);
-// // std::cout< k2) {
-// // std::cout<<"came 1"<<'\n';
-// succ++;
-// // data[hole].key = k2;
-// pq[hole] = pq[succ];
-// } else {
-// // std::cout<<"came 2"<<'\n';
-// // data[hole].key = k1;
-// pq[hole] = pq[succ];
-// }
-// hole = succ;
-// succ <<= 1;
-// }
-//
-// // this part checks if the value to be used to fill the last row's hole is small or not
-// // if not small then it slides the small value up till it reaches the apt position
-// double bubble = *(pq[sz].f);
-// int pred = hole >> 1;
-// // std::cout<<"HERE"<<'\t'< bubble) {
-// // std::cout<<"HERE"<<'\t'<>= 1;
-// }
-// // std::cout<<"HERE AT:"<<'\t'< k2) {
+ // std::cout<<"came 1"<<'\n';
+ succ++;
+ // data[hole].key = k2;
+ pq[hole] = pq[succ];
+ } else {
+ // std::cout<<"came 2"<<'\n';
+ // data[hole].key = k1;
+ pq[hole] = pq[succ];
+ }
+ hole = succ;
+ succ <<= 1;
+ }
+
+ // this part checks if the value to be used to fill the last row's hole is small or not
+ // if not small then it slides the small value up till it reaches the apt position
+ double bubble = *(pq[sz].f);
+ int pred = hole >> 1;
+ // std::cout<<"HERE"<<'\t'< bubble) {
+ // std::cout<<"HERE"<<'\t'<>= 1;
+ }
+ // std::cout<<"HERE AT:"<<'\t'<> & raw_points, id &
coords world;
costmap_->mapToWorld(data[curr_id].x, data[curr_id].y, world.x, world.y);
path_rev.push_back({world.x, world.y});
- RCLCPP_INFO(
- node_->get_logger(), "%i, %i ---> %f, %f", data[curr_id].x, data[curr_id].y, world.x,
- world.y);
- if (data[curr_id].got_here == 1) {
- std::cout <<
- "------------------------------------------------------> got the same error <-------------------------------------------------------"
- <<
- '\n';
- break;
- }
- data[curr_id].got_here = 1;
curr_id = data[curr_id].parent_id;
} while (curr_id != 0);
coords w;
costmap_->mapToWorld(data[curr_id].x, data[curr_id].y, w.x, w.y);
path_rev.push_back({w.x, w.y});
- RCLCPP_INFO(
- node_->get_logger(), "%i, %i ---> %f, %f", data[curr_id].x, data[curr_id].y, w.x, w.y);
-
+
for (int i = path_rev.size() - 1; i >= 0; i--) {
raw_points.push_back(path_rev[i]);
}
@@ -276,8 +257,6 @@ bool LazyThetaStar::isGoal(map_pts & cx, map_pts & cy)
void LazyThetaStar::setNeighbors(map_pts & cx, map_pts & cy, id & curr_id)
{
id curr_par = data[curr_id].parent_id;
- std::cout << "ITS PARENTS ARE : " << data[curr_par].x << '\t' << data[curr_par].y << '\t' <<
- curr_par << '\n';
map_pts px = data[curr_par].x, py = data[curr_par].y;
cost g_cost_par = data[curr_par].g;
@@ -300,8 +279,6 @@ void LazyThetaStar::setNeighbors(map_pts & cx, map_pts & cy, id & curr_id)
cal_cost = g_cost + h_cost;
data.push_back({mx, my, g_cost, h_cost, curr_par, -1, cal_cost});
pushToPq(id_gen);
- std::cout << "ADDED INDEX 1:" << data[id_gen].x << '\t' << data[id_gen].y << '\t' <<
- data[id_gen].f << '\n';
addIndex(mx, my, id_gen);
id_gen++;
continue;
@@ -315,9 +292,7 @@ void LazyThetaStar::setNeighbors(map_pts & cx, map_pts & cy, id & curr_id)
curr_node.parent_id = curr_par;
if (curr_node.closed == 1) {
curr_node.closed = -1;
- pushToPq(m_id);
- std::cout << "ADDED INDEX 2:" << data[m_id].x << '\t' << data[m_id].y << '\t' <<
- data[m_id].f << '\n';
+ pushToPq(m_id);
}
}
continue;
@@ -330,8 +305,7 @@ void LazyThetaStar::initializeStuff()
{
id_gen = 0;
sizeX = costmap_->getSizeInCellsX();
- sizeY = costmap_->getSizeInCellsY();
- std::cout << sizeX << '\t' << sizeY << '\n';
+ sizeY = costmap_->getSizeInCellsY();
initializePosn();
data.reserve(static_cast(sizeX * sizeY * 0.05));
}
From 6ad8bbdba5de15875f687df9b27bbdb95cd3e85c Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 19:05:44 +0530
Subject: [PATCH 19/81] removed comments
---
.../src/lazy_theta_star_planner.cpp | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp b/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp
index 502f5f70aa..fbc700c80d 100644
--- a/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp
+++ b/lazy_theta_star_planner/src/lazy_theta_star_planner.cpp
@@ -96,14 +96,7 @@ nav_msgs::msg::Path LazyThetaStarPlanner::createPlan(
planner_->getPath(path);
planner_->clearStuff();
- RCLCPP_INFO(node_->get_logger(), "RECEIVED THE PATH");
-
if (path.size() > 1) {
-
- for (int i = 0; i < path.size(); i++) {
- std::cout << path[i].x << '\t' << path[i].y << '\n';
- }
-
global_path = linearInterpolation(path, 0.1);
} else {
global_path.poses.clear();
@@ -117,7 +110,7 @@ nav_msgs::msg::Path LazyThetaStarPlanner::createPlan(
}
nav_msgs::msg::Path LazyThetaStarPlanner::linearInterpolation(
- std::vector> & raw_path,
+ std::vector > & raw_path,
double dist_bw_points)
{
nav_msgs::msg::Path pa;
@@ -147,5 +140,4 @@ nav_msgs::msg::Path LazyThetaStarPlanner::linearInterpolation(
} // namespace lazyThetaStarPlanner
#include "pluginlib/class_list_macros.hpp"
-
PLUGINLIB_EXPORT_CLASS(lazyThetaStarPlanner::LazyThetaStarPlanner, nav2_core::GlobalPlanner)
From 6376718827d032d4680c8ee8dd472f5767c29f03 Mon Sep 17 00:00:00 2001
From: Anshu-man567 <56119116+Anshu-man567@users.noreply.github.com>
Date: Wed, 15 Jul 2020 23:19:28 +0530
Subject: [PATCH 20/81] Update lazy_theta_star2.cpp
---
.../src/lazy_theta_star2.cpp | 22 +++++++++----------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/lazy_theta_star_planner/src/lazy_theta_star2.cpp b/lazy_theta_star_planner/src/lazy_theta_star2.cpp
index ea52ee5602..f898bbfc85 100644
--- a/lazy_theta_star_planner/src/lazy_theta_star2.cpp
+++ b/lazy_theta_star_planner/src/lazy_theta_star2.cpp
@@ -43,9 +43,7 @@ bool LazyThetaStar::getPath(std::vector