lib/from_ros_costmaps.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include "../../include/cost_map_demos/from_ros_costmaps.hpp"
9 
10 /*****************************************************************************
11 ** Namespaces
12 *****************************************************************************/
13 
14 namespace cost_map_demos {
15 
16 /*****************************************************************************
17 ** Costmap2DROS Test Suite Helpers
18 *****************************************************************************/
19 
21  broadcaster.add("base_link_5x5", tf::Vector3(1.0, 1.0, 0.0), tf::Quaternion(0, 0, 0, 1));
22  broadcaster.add("base_link_4x4", tf::Vector3(1.0, -3.0, 0.0), tf::Quaternion(0, 0, 0, 1));
23  broadcaster.add("base_link_5x5_3x3_offset", tf::Vector3(-3.7, 2.4, 0.0), tf::Quaternion(0, 0, 0, 1));
24  broadcaster.add("base_link_5x5_3x3_centre", tf::Vector3(-3.5, -3.5, 0.0), tf::Quaternion(0, 0, 0, 1));
25  broadcaster.add("base_link_5x5_2_5x2_5_offset", tf::Vector3(-9.7, 2.4, 0.0), tf::Quaternion(0, 0, 0, 1));
26  broadcaster.startBroadCastingThread();
27 }
28 
29 /*****************************************************************************
30 ** ROS Costmap Server
31 *****************************************************************************/
32 
33 ROSCostmapServer::ROSCostmapServer(const std::string& name,
34  const std::string& base_link_transform_name,
35  const cost_map::Position& origin,
36  const double& width,
37  const double& height
38 )
39 : transform_listener(ros::Duration(1.0))
40 {
41  ros::NodeHandle private_node_handle("~");
42  // lots of parameters here affect the construction ( e.g. rolling window)
43  // if you don't have any parameters set, then this
44  // - alot of defaults which get dumped on the ros param server
45  // - fires up an obstacle layer and an inflation layer
46  // - creates a publisher for an occupancy grid
47  private_node_handle.setParam(name + "/robot_base_frame", base_link_transform_name);
48  private_node_handle.setParam(name + "/origin_x", origin.x());
49  private_node_handle.setParam(name + "/origin_y", origin.y());
50  private_node_handle.setParam(name + "/width", width);
51  private_node_handle.setParam(name + "/height", height);
52  private_node_handle.setParam(name + "/plugins", std::vector<std::string>());
53  private_node_handle.setParam(name + "/resolution", 0.5);
54  private_node_handle.setParam(name + "/robot_radius", 0.03); // clears 1 cell if inside, up to 4 cells on a vertex
55  costmap = std::make_shared<ROSCostmap>(name, transform_listener);
56 
57  for ( unsigned int index = 0; index < costmap->getCostmap()->getSizeInCellsY(); ++index ) {
58  unsigned int dimension = costmap->getCostmap()->getSizeInCellsX();
59  // @todo assert dimension > 1
60  // set the first row to costmap_2d::FREE_SPACE? but it shows up invisibly in rviz, so don't bother
61  for ( unsigned int fill_index = 0; fill_index < dimension - 2; ++fill_index )
62  {
63  double fraction = static_cast<double>(fill_index + 1) / static_cast<double>(costmap->getCostmap()->getSizeInCellsX());
64  costmap->getCostmap()->setCost(fill_index, index, fraction*costmap_2d::INSCRIBED_INFLATED_OBSTACLE );
65  }
66  costmap->getCostmap()->setCost(dimension - 2, index, costmap_2d::LETHAL_OBSTACLE);
67  costmap->getCostmap()->setCost(dimension - 1, index, costmap_2d::NO_INFORMATION);
68  }
69 }
70 
71 /*****************************************************************************
72  ** Trailers
73  *****************************************************************************/
74 
75 } // namespace cost_map_demos
ROSCostmapServer(const std::string &name, const std::string &base_link_transform_name, const cost_map::Position &origin, const double &width, const double &height)
static const unsigned char INSCRIBED_INFLATED_OBSTACLE
void add(const std::string &name, tf::Vector3 origin, const tf::Quaternion &orientation)
Definition: utilities.cpp:51
Broadcast a set of transforms useful for various demos.
Definition: utilities.hpp:35
static const unsigned char LETHAL_OBSTACLE
static const unsigned char NO_INFORMATION
grid_map::Position Position
void broadcastCostmap2DROSTestSuiteTransforms(TransformBroadcaster &broadcaster)
tf::TransformListener transform_listener
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const


cost_map_demos
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:04:00