base_local_planner
occupancy_velocity_cost_function.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Author: Rein Appeldoorn
3  *********************************************************************/
4 
6 #include <cmath>
7 #include <Eigen/Core>
8 #include <ros/console.h>
9 
10 namespace base_local_planner {
11 
13 {
14  if (costmap != NULL)
15  {
17  }
18 }
19 
21 {
22  if (world_model_ != NULL)
23  {
24  delete world_model_;
25  }
26 }
27 
29 {
30  if (footprint_spec_.size() == 0)
31  {
32  ROS_ERROR("Footprint spec is empty, maybe missing call to setFootprint?");
33  return -9;
34  }
35 
36  double x, y, th;
37  for (unsigned int i = 0; i < traj.getPointsSize(); ++i)
38  {
39  traj.getPoint(i, x, y, th);
40 
41  double footprint_cost = world_model_->footprintCost(x, y, th, footprint_spec_);
42 
43  // We are in collision: discard trajectory
44  if (footprint_cost < 0)
45  return -6.0;
46 
47  // Check the occupancy of the center point
48  unsigned int cell_x, cell_y;
49  if ( ! costmap_->worldToMap(x, y, cell_x, cell_y))
50  return -7.0;
51 
52  double center_cost = costmap_->getCost(cell_x, cell_y);
53  double max_vel = (1 - center_cost / 255.0) * max_trans_vel_;
54 
55  if (hypot(traj.xv_, traj.yv_) > max_vel && i == traj.getPointsSize() - 1)
56  return -5.0;
57  }
58 
59  // Trajectory is valid
60  return 0.0;
61 }
62 
63 } /* namespace base_local_planner */
base_local_planner::WorldModel::footprintCost
virtual double footprintCost(const geometry_msgs::Point &position, const std::vector< geometry_msgs::Point > &footprint, double inscribed_radius, double circumscribed_radius)=0
Subclass will implement this method to check a footprint at a given position and orientation for lega...
costmap_2d::Costmap2D::worldToMap
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
base_local_planner::OccupancyVelocityCostFunction::world_model_
base_local_planner::WorldModel * world_model_
Definition: occupancy_velocity_cost_function.h:38
std::vector::size
T size(T... args)
base_local_planner::OccupancyVelocityCostFunction::footprint_spec_
std::vector< geometry_msgs::Point > footprint_spec_
Definition: occupancy_velocity_cost_function.h:37
base_local_planner::OccupancyVelocityCostFunction::OccupancyVelocityCostFunction
OccupancyVelocityCostFunction(costmap_2d::Costmap2D *costmap)
Definition: occupancy_velocity_cost_function.cpp:14
base_local_planner::OccupancyVelocityCostFunction::max_trans_vel_
double max_trans_vel_
Definition: occupancy_velocity_cost_function.h:39
costmap_2d::Costmap2D
base_local_planner::ObstacleCostFunction::costmap_
costmap_2d::Costmap2D * costmap_
Definition: obstacle_cost_function.h:149
cmath
base_local_planner::CostmapModel
A class that implements the WorldModel interface to provide grid based collision checks for the traje...
Definition: costmap_model.h:85
base_local_planner::ObstacleCostFunction::world_model_
base_local_planner::WorldModel * world_model_
Definition: obstacle_cost_function.h:151
occupancy_velocity_cost_function.h
base_local_planner::OccupancyVelocityCostFunction::scoreTrajectory
double scoreTrajectory(Trajectory &traj)
Definition: occupancy_velocity_cost_function.cpp:30
base_local_planner::OccupancyVelocityCostFunction::costmap_
costmap_2d::Costmap2D * costmap_
Definition: occupancy_velocity_cost_function.h:36
base_local_planner
Definition: alignment_cost_function.h:7
costmap_2d::Costmap2D::getCost
unsigned char getCost(unsigned int mx, unsigned int my) const
base_local_planner::OccupancyVelocityCostFunction::~OccupancyVelocityCostFunction
~OccupancyVelocityCostFunction()
Definition: occupancy_velocity_cost_function.cpp:22