@@ -95,6 +95,24 @@ float CostCritic::findCircumscribedCost(
9595 return circumscribed_cost_;
9696}
9797
98+ bool CostCritic::inCollision (float cost) const
99+ {
100+ bool is_tracking_unknown =
101+ costmap_ros_->getLayeredCostmap ()->isTrackingUnknown ();
102+
103+ using namespace nav2_costmap_2d ; // NOLINT
104+ switch (static_cast <unsigned char >(cost)) {
105+ case (LETHAL_OBSTACLE):
106+ return true ;
107+ case (INSCRIBED_INFLATED_OBSTACLE):
108+ return consider_footprint_ ? false : true ;
109+ case (NO_INFORMATION):
110+ return is_tracking_unknown ? false : true ;
111+ }
112+
113+ return false ;
114+ }
115+
98116void CostCritic::score (CriticData & data)
99117{
100118 if (!enabled_) {
@@ -153,27 +171,36 @@ void CostCritic::score(CriticData & data)
153171 // The footprintCostAtPose will always return "INSCRIBED" if footprint is over it
154172 // So the center point has more information than the footprint
155173 if (!worldToMapFloat (Tx, Ty, x_i, y_i)) {
156- if (!is_tracking_unknown_) {
157- traj_cost = collision_cost_;
158- trajectory_collide = true ;
159- break ;
160- }
161- pose_cost = 255 .0f ; // NO_INFORMATION in float
174+ pose_cost = nav2_costmap_2d::NO_INFORMATION;
162175 } else {
176+ // Get center cost
163177 pose_cost = static_cast <float >(costmap->getCost (getIndex (x_i, y_i)));
164- if (pose_cost < 1 .0f ) {
165- continue ; // In free space
166- }
167- if (inCollision (pose_cost, Tx, Ty, traj_yaw (i, j))) {
168- traj_cost = collision_cost_;
178+ // Skip footprint cost if point cost has already exceeded inscribed obstacle cost
179+ if (pose_cost >= nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE) {
169180 trajectory_collide = true ;
170181 break ;
171182 }
183+ // Get footprint cost
184+ if (consider_footprint_ &&
185+ (pose_cost >= possible_collision_cost_ || possible_collision_cost_ < 1 .0f ))
186+ {
187+ pose_cost = static_cast <float >(collision_checker_.footprintCostAtPose (
188+ static_cast <double >(Tx), static_cast <double >(Ty),
189+ static_cast <double >(traj_yaw (i, j)),
190+ costmap_ros_->getRobotFootprint ()));
191+ }
192+ }
193+ if (pose_cost < 1 .0f ) {
194+ continue ; // In free space
195+ }
196+ // Check if the pose is in collision
197+ if (inCollision (pose_cost)) {
198+ trajectory_collide = true ;
199+ break ;
172200 }
173-
174201 // Let near-collision trajectory points be punished severely
175- // Note that we collision check based on the footprint actual,
176- // but score based on the center- point cost regardless
202+ // This will apply when footprint steps in the inscribed space
203+ // and the center point is not in collision
177204 if (pose_cost >= 253 .0f /* INSCRIBED_INFLATED_OBSTACLE in float*/ ) {
178205 traj_cost += critical_cost_;
179206 } else if (!near_goal) { // Generally prefer trajectories further from obstacles
@@ -183,6 +210,8 @@ void CostCritic::score(CriticData & data)
183210
184211 if (!trajectory_collide) {
185212 all_trajectories_collide = false ;
213+ } else {
214+ traj_cost = collision_cost_;
186215 }
187216 }
188217
0 commit comments