65 layered_costmap_(NULL),
68 transform_tolerance_(0.3),
69 map_update_thread_shutdown_(false),
73 robot_stopped_(false),
74 map_update_thread_(NULL),
76 plugin_loader_(
"costmap_2d",
"costmap_2d::Layer"),
79 footprint_padding_(0.0)
100 ROS_WARN(
"Timed out waiting for transform from %s to %s to become available before running costmap, tf error: %s",
110 bool rolling_window, track_unknown_space, always_send_full_costmap;
111 private_nh.
param(
"rolling_window", rolling_window,
false);
112 private_nh.
param(
"track_unknown_space", track_unknown_space,
false);
113 private_nh.
param(
"always_send_full_costmap", always_send_full_costmap,
false);
117 if (!private_nh.
hasParam(
"plugins"))
127 private_nh.
getParam(
"plugins", my_list);
128 for (int32_t i = 0; i < my_list.
size(); ++i)
130 std::string pname =
static_cast<std::string
>(my_list[i][
"name"]);
131 std::string type =
static_cast<std::string
>(my_list[i][
"type"]);
132 ROS_INFO(
"%s: Using plugin \"%s\"",
name_.c_str(), pname.c_str());
143 std::string topic_param, topic;
144 if (!private_nh.
searchParam(
"footprint_topic", topic_param))
146 topic_param =
"footprint_topic";
149 private_nh.
param(topic_param, topic, std::string(
"footprint"));
152 if (!private_nh.
searchParam(
"published_footprint_topic", topic_param))
154 topic_param =
"published_footprint";
157 private_nh.
param(topic_param, topic, std::string(
"footprint"));
163 always_send_full_costmap);
177 dsrv_->setCallback(cb);
204 ROS_WARN(
"%s: Parameter \"plugins\" not provided, loading pre-Hydro parameters",
name_.c_str());
207 std::vector < XmlRpc::XmlRpcValue > plugins;
213 if (nh.
getParam(
"static_map", flag) && flag)
218 plugins.push_back(super_map);
228 if (nh.
getParam(
"map_type", s) && s ==
"voxel")
233 plugins.push_back(super_map);
247 plugins.push_back(super_map);
254 nh.
param(
"observation_sources", s, std::string(
""));
255 std::stringstream ss(s);
269 plugins.push_back(super_map);
272 nh.
setParam(
"plugins", super_array);
279 if(plugin_type ==
"costmap_2d::StaticLayer")
286 else if(plugin_type ==
"costmap_2d::VoxelLayer")
295 else if(plugin_type ==
"costmap_2d::ObstacleLayer")
302 else if(plugin_type ==
"costmap_2d::InflationLayer")
317 ROS_WARN(
"%s: Pre-Hydro parameter \"%s\" unused since \"plugins\" is provided",
name_.c_str(), param_name.c_str());
331 double map_update_frequency = config.update_frequency;
333 double map_publish_frequency = config.publish_frequency;
334 if (map_publish_frequency > 0)
340 double map_width_meters = config.width, map_height_meters = config.height, resolution = config.resolution, origin_x =
342 origin_y = config.origin_y;
347 (
unsigned int)(map_height_meters / resolution), resolution, origin_x, origin_y);
366 const costmap_2d::Costmap2DConfig &old_config)
372 if (new_config.footprint == old_config.footprint &&
373 new_config.robot_radius == old_config.robot_radius)
378 if (new_config.footprint !=
"" && new_config.footprint !=
"[]")
380 std::vector<geometry_msgs::Point> new_footprint;
387 ROS_ERROR(
"Invalid footprint string from dynamic reconfigure");
411 geometry_msgs::PoseStamped new_pose;
424 old_pose_.pose.position.z).distance(tf2::Vector3(new_pose.pose.position.x,
425 new_pose.pose.position.y, new_pose.pose.position.z)) < 1e-3) &&
430 new_pose.pose.orientation.y,
431 new_pose.pose.orientation.z,
432 new_pose.pose.orientation.w)) < 1e-3);
439 if (frequency == 0.0)
446 #ifdef HAVE_SYS_TIME_H 447 struct timeval start, end;
448 double start_t, end_t, t_diff;
449 gettimeofday(&start, NULL);
454 #ifdef HAVE_SYS_TIME_H 455 gettimeofday(&end, NULL);
456 start_t = start.tv_sec + double(start.tv_usec) / 1e6;
457 end_t = end.tv_sec + double(end.tv_usec) / 1e6;
458 t_diff = end_t - start_t;
459 ROS_DEBUG(
"Map update time: %.9f", t_diff);
464 unsigned int x0, y0, xn, yn;
478 ROS_WARN(
"Map update loop missed its desired rate of %.4fHz... the loop actually took %.4f seconds", frequency,
488 geometry_msgs::PoseStamped pose;
491 double x = pose.pose.position.x,
492 y = pose.pose.position.y,
497 geometry_msgs::PolygonStamped footprint;
518 (*plugin)->activate();
538 (*plugin)->deactivate();
576 geometry_msgs::PoseStamped robot_pose;
599 ROS_ERROR_THROTTLE(1.0,
"No Transform available Error looking up robot pose: %s\n", ex.what());
609 ROS_ERROR_THROTTLE(1.0,
"Extrapolation Error looking up robot pose: %s\n", ex.what());
616 "Costmap2DROS transform timeout. Current time: %.4f, global_pose stamp: %.4f, tolerance: %.4f",
626 geometry_msgs::PoseStamped global_pose;
630 double yaw =
tf2::getYaw(global_pose.pose.orientation);
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
std::vector< geometry_msgs::Point > makeFootprintFromParams(ros::NodeHandle &nh)
Read the ros-params "footprint" and/or "robot_radius" from the given NodeHandle using searchParam() t...
void start()
Subscribes to sensor topics if necessary and starts costmap updates, can be called to restart the cos...
T & transform(const T &in, T &out, const std::string &target_frame, ros::Duration timeout=ros::Duration(0.0)) const
tf2_ros::Buffer & tf_
Used for transforming point clouds.
bool map_update_thread_shutdown_
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y, bool size_locked=false)
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
tf2Scalar angle(const Quaternion &q) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void warnForOldParameters(ros::NodeHandle &nh)
costmap_2d::Costmap2DConfig old_config_
void pause()
Stops the costmap from updating, but sensor data still comes in over the wire.
dynamic_reconfigure::Server< costmap_2d::Costmap2DConfig > * dsrv_
ros::Duration publish_cycle
void readFootprintFromConfig(const costmap_2d::Costmap2DConfig &new_config, const costmap_2d::Costmap2DConfig &old_config)
Set the footprint from the new_config object.
bool deleteParam(const std::string &key) const
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
void setFootprint(const std::vector< geometry_msgs::Point > &footprint_spec)
Updates the stored footprint, updates the circumscribed and inscribed radii, and calls onFootprintCha...
std::vector< boost::shared_ptr< Layer > > * getPlugins()
boost::thread * map_update_thread_
A thread for updating the map.
void getBounds(unsigned int *x0, unsigned int *xn, unsigned int *y0, unsigned int *yn)
void loadOldParameters(ros::NodeHandle &nh)
bool makeFootprintFromString(const std::string &footprint_string, std::vector< geometry_msgs::Point > &footprint)
Make the footprint from the given string.
virtual bool canTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &target_time, const ros::Duration timeout, std::string *errstr=NULL) const
std::vector< geometry_msgs::Point > toPointVector(geometry_msgs::Polygon polygon)
Convert Polygon msg to vector of Points.
LayeredCostmap * layered_costmap_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::map< std::string, XmlRpcValue > ValueStruct
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
void publish(const boost::shared_ptr< M > &message) const
ros::Subscriber footprint_sub_
void addPlugin(boost::shared_ptr< Layer > plugin)
void setUnpaddedRobotFootprintPolygon(const geometry_msgs::Polygon &footprint)
Set the footprint of the robot to be the given polygon, padded by footprint_padding.
#define ROS_WARN_THROTTLE(period,...)
std::string global_frame_
The global frame for the costmap.
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_THROTTLE(period,...)
std::vector< geometry_msgs::Point > makeFootprintFromRadius(double radius)
Create a circular footprint from a given radius.
void padFootprint(std::vector< geometry_msgs::Point > &footprint, double padding)
Adds the specified amount of padding to the footprint (in place)
void movementCB(const ros::TimerEvent &event)
bool getRobotPose(geometry_msgs::PoseStamped &global_pose) const
Get the pose of the robot in the global frame of the costmap.
void checkOldParam(ros::NodeHandle &nh, const std::string ¶m_name)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void reconfigureCB(costmap_2d::Costmap2DConfig &config, uint32_t level)
Duration cycleTime() const
Costmap2DPublisher * publisher_
geometry_msgs::PoseStamped old_pose_
bool hasParam(const std::string &key) const
pluginlib::ClassLoader< Layer > plugin_loader_
double getYaw(const A &a)
std::string robot_base_frame_
The frame_id of the robot base.
void move_parameter(ros::NodeHandle &old_h, ros::NodeHandle &new_h, std::string name, bool should_delete=true)
bool searchParam(const std::string &key, std::string &result) const
A tool to periodically publish visualization data from a Costmap2D.
void updateBounds(unsigned int x0, unsigned int xn, unsigned int y0, unsigned int yn)
Include the given bounds in the changed-rectangle.
void mapUpdateLoop(double frequency)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
void resetLayers()
Reset each individual layer.
void resume()
Resumes costmap updates.
double transform_tolerance_
timeout before transform errors
void setUnpaddedRobotFootprint(const std::vector< geometry_msgs::Point > &points)
Set the footprint of the robot to be the given set of points, padded by footprint_padding.
ros::Publisher footprint_pub_
void stop()
Stops costmap updates and unsubscribes from sensor topics.
A 2D costmap provides a mapping between points in the world and their associated "costs".
Instantiates different layer plugins and aggregates them into one score.
void updateMap(double robot_x, double robot_y, double robot_yaw)
Update the underlying costmap with new data. If you want to update the map outside of the update loop...
ROSCPP_DECL void spinOnce()
void setArray(XmlRpc::XmlRpcValue::ValueArray *a)
void copyParentParameters(const std::string &plugin_name, const std::string &plugin_type, ros::NodeHandle &nh)
void setStruct(XmlRpc::XmlRpcValue::ValueStruct *a)
void transformFootprint(double x, double y, double theta, const std::vector< geometry_msgs::Point > &footprint_spec, std::vector< geometry_msgs::Point > &oriented_footprint)
Given a pose and base footprint, build the oriented footprint of the robot (list of Points) ...
std::vector< geometry_msgs::Point > padded_footprint_
void getOrientedFootprint(std::vector< geometry_msgs::Point > &oriented_footprint) const
Build the oriented footprint of the robot at the robot's current pose.
void publishCostmap()
Publishes the visualization data over ROS.
void resetMap(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn)
std::vector< geometry_msgs::Point > unpadded_footprint_