Skip to content

Commit 88884cf

Browse files
Fix MAX_NON_OBSTACLE_COST in theta star planner (#5865) (#5868)
(cherry picked from commit 018dca9) Signed-off-by: mini-1235 <mauricepurnawan@gmail.com> Co-authored-by: Maurice Alexander Purnawan <mauricepurnawan@gmail.com>
1 parent 77d6579 commit 88884cf

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

nav2_theta_star_planner/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ The parameters were set to - `w_euc_cost: 1.0`, `w_traversal_cost: 5.0` and the
2525

2626
**f(a)** - total cost (g(a) + h(a)) for the node 'a'
2727

28-
**LETHAL_COST** - a value of the costmap traversal cost that inscribes an obstacle with
29-
respect to a function, value = 253
30-
3128
**curr** - represents the node whose neighbours are being added to the list
3229

3330
**neigh** - one of the neighboring nodes of curr
@@ -36,7 +33,7 @@ respect to a function, value = 253
3633

3734
**euc_cost(a,b)** - euclidean distance between the node type 'a' and type 'b'
3835

39-
**costmap_cost(a,b)** - the costmap traversal cost (ranges from 0 - 252, 254 = unknown value) between the node type 'a' and type 'b'
36+
**costmap_cost(a,b)** - the costmap traversal cost (ranges from 0 - 252, 255 = unknown value) between the node type 'a' and type 'b'
4037

4138
### Cost function
4239
```

nav2_theta_star_planner/include/nav2_theta_star_planner/theta_star.hpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
const double INF_COST = DBL_MAX;
2727
const int UNKNOWN_COST = 255;
28-
const int OBS_COST = 254;
29-
const int LETHAL_COST = 252;
28+
const int OCCUPIED_COST = 254;
29+
const int MAX_NON_OBSTACLE_COST = 252;
3030

3131
struct coordsM
3232
{
@@ -92,14 +92,13 @@ class ThetaStar
9292
bool generatePath(std::vector<coordsW> & raw_path, std::function<bool()> cancel_checker);
9393

9494
/**
95-
* @brief this function checks whether the cost of a point(cx, cy) on the costmap is less than the LETHAL_COST
95+
* @brief this function checks whether the cost of a point(cx, cy) on the costmap is less than or equal to the MAX_NON_OBSTACLE_COST
9696
* @return the result of the check
9797
*/
9898
inline bool isSafe(const int & cx, const int & cy) const
9999
{
100-
return (costmap_->getCost(
101-
cx,
102-
cy) == UNKNOWN_COST && allow_unknown_) || costmap_->getCost(cx, cy) < LETHAL_COST;
100+
return (costmap_->getCost(cx, cy) == UNKNOWN_COST && allow_unknown_) ||
101+
costmap_->getCost(cx, cy) <= MAX_NON_OBSTACLE_COST;
103102
}
104103

105104
/**
@@ -110,8 +109,8 @@ class ThetaStar
110109
const geometry_msgs::msg::PoseStamped & goal);
111110

112111
/**
113-
* @brief checks whether the start and goal points have costmap costs greater than LETHAL_COST
114-
* @return true if the cost of any one of the points is greater than LETHAL_COST
112+
* @brief checks whether the start and goal points have costmap costs greater than MAX_NON_OBSTACLE_COST
113+
* @return true if the cost of any one of the points is greater than MAX_NON_OBSTACLE_COST
115114
*/
116115
bool isUnsafeToPlan() const
117116
{
@@ -193,16 +192,19 @@ class ThetaStar
193192
/**
194193
* @brief it is an overloaded function to ease the cost calculations while performing the LOS check
195194
* @param cost denotes the total straight line traversal cost; it adds the traversal cost for the node (cx, cy) at every instance; it is also being returned
196-
* @return false if the traversal cost is greater than / equal to the LETHAL_COST and true otherwise
195+
* @return false if the traversal cost is greater than the MAX_NON_OBSTACLE_COST and true otherwise
197196
*/
198197
bool isSafe(const int & cx, const int & cy, double & cost) const
199198
{
200199
double curr_cost = getCost(cx, cy);
201-
if ((costmap_->getCost(cx, cy) == UNKNOWN_COST && allow_unknown_) || curr_cost < LETHAL_COST) {
200+
if ((costmap_->getCost(cx, cy) == UNKNOWN_COST && allow_unknown_) ||
201+
curr_cost <= MAX_NON_OBSTACLE_COST)
202+
{
202203
if (costmap_->getCost(cx, cy) == UNKNOWN_COST) {
203-
curr_cost = OBS_COST - 1;
204+
curr_cost = OCCUPIED_COST - 1;
204205
}
205-
cost += w_traversal_cost_ * curr_cost * curr_cost / LETHAL_COST / LETHAL_COST;
206+
cost += w_traversal_cost_ * curr_cost * curr_cost / MAX_NON_OBSTACLE_COST /
207+
MAX_NON_OBSTACLE_COST;
206208
return true;
207209
} else {
208210
return false;
@@ -226,7 +228,8 @@ class ThetaStar
226228
inline double getTraversalCost(const int & cx, const int & cy)
227229
{
228230
double curr_cost = getCost(cx, cy);
229-
return w_traversal_cost_ * curr_cost * curr_cost / LETHAL_COST / LETHAL_COST;
231+
return w_traversal_cost_ * curr_cost * curr_cost / MAX_NON_OBSTACLE_COST /
232+
MAX_NON_OBSTACLE_COST;
230233
}
231234

232235
/**

0 commit comments

Comments
 (0)