applications/from_ros_costmaps.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include <atomic>
9 #include <ros/common.h>
10 #include <ros/node_handle.h>
11 #include <ros/subscriber.h>
12 #include <ros/publisher.h>
13 
14 #include <costmap_2d/costmap_2d.h>
15 #include <costmap_2d/cost_values.h>
16 #include <nav_msgs/OccupancyGrid.h>
17 
19 
20 #include "../../include/cost_map_demos/from_ros_costmaps.hpp"
21 
22 /*****************************************************************************
23 ** Interfaces
24 *****************************************************************************/
25 
26 
27 
28 int main(int argc, char** argv)
29 {
30  ros::init(argc, argv, "converter"); // , ros::init_options::AnonymousName);
31 
32  /********************
33  ** Transforms
34  ********************/
37 
38  /********************
39  ** ROS Costmaps
40  ********************/
41  // MAKE SURE THIS STAY IN SYNC WITH src/tests/rostests/from_ros_costmaps/from_ros_costmaps.cpp!
42  // The following should result in costmaps with strips of increasing cost in the x-direction,
43  // but also 1-4 cells cleared by the footprint (see rviz)
44  cost_map_demos::ROSCostmapServer ros_costmap_5x5("five_by_five", "base_link_5x5", cost_map::Position(0.0, 0.0), 5.0, 5.0);
45  cost_map_demos::ROSCostmapServer ros_costmap_4x4("four_by_four", "base_link_4x4", cost_map::Position(0.0, -5.0), 4.0, 4.0);
46  cost_map_demos::ROSCostmapServer ros_costmap_5x5_3x3_offset("five_by_five_three_by_three_offset", "base_link_5x5_3x3_offset", cost_map::Position(-6.0, 0.0), 5.0, 5.0);
47  cost_map_demos::ROSCostmapServer ros_costmap_5x5_3x3_centre("five_by_five_three_by_three_centre", "base_link_5x5_3x3_centre", cost_map::Position(-6.0, -6.0), 5.0, 5.0);
48  cost_map_demos::ROSCostmapServer ros_costmap_5x5_2_5x2_5_offset("five_by_five_twohalf_by_twohalf_offset", "base_link_5x5_2_5x2_5_offset", cost_map::Position(-12.0, 0.0), 5.0, 5.0);
49 
50  /********************
51  ** New Costmaps
52  ********************/
53  // MAKE SURE THIS STAY IN SYNC WITH src/tests/rostests/from_ros_costmaps/from_ros_costmaps.cpp!
54  cost_map::CostMap cost_map_5x5, cost_map_4x4, cost_map_5x5_3x3_offset, cost_map_5x5_3x3_centre, cost_map_5x5_2_5x2_5_offset;
55  cost_map::fromCostmap2DROS(*(ros_costmap_5x5.getROSCostmap()), "obstacle_costs", cost_map_5x5);
56  cost_map::fromCostmap2DROS(*(ros_costmap_4x4.getROSCostmap()), "obstacle_costs", cost_map_4x4);
57  cost_map::Length geometry_3x3(3.0, 3.0);
58  cost_map::fromCostmap2DROSAtRobotPose(*(ros_costmap_5x5_3x3_offset.getROSCostmap()), geometry_3x3, "obstacle_costs", cost_map_5x5_3x3_offset);
59  cost_map::fromCostmap2DROSAtRobotPose(*(ros_costmap_5x5_3x3_centre.getROSCostmap()), geometry_3x3, "obstacle_costs", cost_map_5x5_3x3_centre);
60  cost_map::Length geometry_2_5x2_5(2.5, 2.5);
61  cost_map::fromCostmap2DROSAtRobotPose(*(ros_costmap_5x5_2_5x2_5_offset.getROSCostmap()), geometry_2_5x2_5, "obstacle_costs", cost_map_5x5_2_5x2_5_offset);
62 
63  /********************
64  ** Publishers
65  ********************/
66  ros::NodeHandle node_handle;
67  ros::Publisher pub_5x5 = node_handle.advertise<nav_msgs::OccupancyGrid>("converted_5x5", 1, true);
68  ros::Publisher pub_4x4 = node_handle.advertise<nav_msgs::OccupancyGrid>("converted_4x4", 1, true);
69  ros::Publisher pub_5x5_3x3_offset = node_handle.advertise<nav_msgs::OccupancyGrid>("converted_5x5_3x3_offset", 1, true);
70  ros::Publisher pub_5x5_3x3_centre = node_handle.advertise<nav_msgs::OccupancyGrid>("converted_5x5_3x3_centre", 1, true);
71  ros::Publisher pub_5x5_2_5x2_5_offset = node_handle.advertise<nav_msgs::OccupancyGrid>("converted_5x5_2_5x2_5_offset", 1, true);
72 
73  nav_msgs::OccupancyGrid occupancy_msg;
74  cost_map::toOccupancyGrid(cost_map_5x5, cost_map_5x5.getLayers()[0], occupancy_msg);
75  pub_5x5.publish(occupancy_msg);
76  cost_map::toOccupancyGrid(cost_map_4x4, cost_map_4x4.getLayers()[0], occupancy_msg);
77  pub_4x4.publish(occupancy_msg);
78  cost_map::toOccupancyGrid(cost_map_5x5_3x3_offset, cost_map_5x5_3x3_offset.getLayers()[0], occupancy_msg);
79  pub_5x5_3x3_offset.publish(occupancy_msg);
80  cost_map::toOccupancyGrid(cost_map_5x5_3x3_centre, cost_map_5x5_3x3_centre.getLayers()[0], occupancy_msg);
81  pub_5x5_3x3_centre.publish(occupancy_msg);
82  cost_map::toOccupancyGrid(cost_map_5x5_2_5x2_5_offset, cost_map_5x5_2_5x2_5_offset.getLayers()[0], occupancy_msg);
83  pub_5x5_2_5x2_5_offset.publish(occupancy_msg);
84 
85  /********************
86  ** Spin & Shutdown
87  ********************/
88  ros::spin();
89 
90  return 0;
91 }
int main(int argc, char **argv)
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Broadcast a set of transforms useful for various demos.
Definition: utilities.hpp:35
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
void toOccupancyGrid(const cost_map::CostMap &cost_map, const std::string &layer, nav_msgs::OccupancyGrid &msg)
bool fromCostmap2DROS(costmap_2d::Costmap2DROS &ros_costmap, const std::string &layer_name, cost_map::CostMap &cost_map)
grid_map::Position Position
void broadcastCostmap2DROSTestSuiteTransforms(TransformBroadcaster &broadcaster)
const std::vector< std::string > & getLayers() const
grid_map::Length Length
bool fromCostmap2DROSAtRobotPose(costmap_2d::Costmap2DROS &ros_costmap, const cost_map::Length &geometry, const std::string &layer_name, cost_map::CostMap &cost_map)


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