Added modified static_layer costmap_2d plugin

This commit is contained in:
Mathieu Labbe
2015-03-22 17:47:35 -04:00
parent 9eee16891e
commit 6acc7cc19a
12 changed files with 399 additions and 36 deletions
+4 -2
View File
@@ -8,7 +8,7 @@ find_package(catkin REQUIRED COMPONENTS
cv_bridge roscpp rospy sensor_msgs std_msgs std_srvs nav_msgs geometry_msgs visualization_msgs cv_bridge roscpp rospy sensor_msgs std_msgs std_srvs nav_msgs geometry_msgs visualization_msgs
image_transport tf tf_conversions laser_geometry pcl_conversions image_transport tf tf_conversions laser_geometry pcl_conversions
pcl_ros nodelet dynamic_reconfigure rviz message_filters class_loader pcl_ros nodelet dynamic_reconfigure rviz message_filters class_loader
genmsg stereo_msgs octomap_ros genmsg stereo_msgs octomap_ros costmap_2d
) )
## System dependencies are found with CMake's conventions ## System dependencies are found with CMake's conventions
@@ -84,7 +84,7 @@ catkin_package(
CATKIN_DEPENDS cv_bridge roscpp rospy sensor_msgs std_msgs std_srvs nav_msgs geometry_msgs visualization_msgs CATKIN_DEPENDS cv_bridge roscpp rospy sensor_msgs std_msgs std_srvs nav_msgs geometry_msgs visualization_msgs
image_transport tf tf_conversions laser_geometry pcl_conversions image_transport tf tf_conversions laser_geometry pcl_conversions
pcl_ros nodelet dynamic_reconfigure rviz message_filters class_loader pcl_ros nodelet dynamic_reconfigure rviz message_filters class_loader
stereo_msgs octomap_ros stereo_msgs octomap_ros costmap_2d
) )
########### ###########
@@ -137,6 +137,7 @@ add_library(rtabmap_ros
src/rviz/MapGraphDisplay.cpp src/rviz/MapGraphDisplay.cpp
src/rviz/InfoDisplay.cpp src/rviz/InfoDisplay.cpp
src/rviz/OrbitOrientedViewController.cpp src/rviz/OrbitOrientedViewController.cpp
src/costmap_2d/static_layer.cpp
${MOC_FILES} ${MOC_FILES}
) )
target_link_libraries(rtabmap_ros target_link_libraries(rtabmap_ros
@@ -238,6 +239,7 @@ install(DIRECTORY
install(FILES install(FILES
nodelet_plugins.xml nodelet_plugins.xml
plugin_description.xml plugin_description.xml
costmap_plugins.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
) )
+8
View File
@@ -0,0 +1,8 @@
<class_libraries>
<library path="lib/librtabmap_ros">
<class type="rtabmap_ros::StaticLayer" base_class_type="costmap_2d::Layer">
<description>Listens to OccupancyGrid messages and copies them in, like from map_server.</description>
</class>
</library>
</class_libraries>
+1 -1
View File
@@ -87,7 +87,7 @@
<param name="base_global_planner" value="navfn/NavfnROS"/> <param name="base_global_planner" value="navfn/NavfnROS"/>
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="global_costmap" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="global_costmap" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="local_costmap" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="local_costmap" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/local_costmap_params_laser.yaml" command="load" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/local_costmap_params_2d.yaml" command="load" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/global_costmap_params.yaml" command="load" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/global_costmap_params.yaml" command="load" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/base_local_planner_params.yaml" command="load" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/base_local_planner_params.yaml" command="load" />
</node> </node>
@@ -27,7 +27,7 @@
<node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen"> <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="global_costmap" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="global_costmap" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="local_costmap" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/costmap_common_params.yaml" command="load" ns="local_costmap" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/local_costmap_params.yaml" command="load" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/local_costmap_params_3d.yaml" command="load" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/global_costmap_params.yaml" command="load" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/global_costmap_params.yaml" command="load" />
<rosparam file="$(find rtabmap_ros)/launch/azimut3/config/base_local_planner_params.yaml" command="load" /> <rosparam file="$(find rtabmap_ros)/launch/azimut3/config/base_local_planner_params.yaml" command="load" />
</node> </node>
@@ -11,23 +11,16 @@ TrajectoryPlannerROS:
min_vel_x: 0.24 min_vel_x: 0.24
max_rotational_vel: 0.5 max_rotational_vel: 0.5
min_in_place_rotational_vel: 0.15 min_in_place_rotational_vel: 0.15
escape_vel: -0.10
holonomic_robot: true
xy_goal_tolerance: 0.20 xy_goal_tolerance: 0.20
yaw_goal_tolerance: 0.20 yaw_goal_tolerance: 0.20
sim_time: 1.5 sim_time: 1.5
sim_granularity: 0.025
vx_samples: 3
vtheta_samples: 30 vtheta_samples: 30
controller_frequency: 20
pdist_scale: 0.6 meter_scoring: true
gdist_scale: 0.8
occdist_scale: 0.01
heading_lookahead: 0.325
dwa: true
oscillation_reset_dist: 0.05 #global planner
meter_scoring: false NavfnROS:
allow_unknown: false
visualize_potential: true
@@ -6,18 +6,5 @@ footprint_padding: 0.03
inflation_radius: 0.55 inflation_radius: 0.55
transform_tolerance: 2 transform_tolerance: 2
controller_patience: 2.0
#planner_frequency: 0.2
NavfnROS:
allow_unknown: false
recovery_behaviors: [
{name: conservative_clear, type: clear_costmap_recovery/ClearCostmapRecovery},
{name: aggressive_clear, type: clear_costmap_recovery/ClearCostmapRecovery}
]
conservative_clear:
reset_distance: 3.00
aggressive_clear:
reset_distance: 1.84
@@ -3,5 +3,8 @@ global_costmap:
robot_base_frame: base_footprint robot_base_frame: base_footprint
update_frequency: 1 update_frequency: 1
publish_frequency: 1 publish_frequency: 1
static_map: true
always_send_full_costmap: true always_send_full_costmap: true
plugins: [
{name: static_layer, type: "rtabmap_ros::StaticLayer"},
{name: inflation_layer, type: "costmap_2d::InflationLayer"}
]
@@ -11,15 +11,15 @@ local_costmap:
origin_x: -2.0 origin_x: -2.0
origin_y: -2.0 origin_y: -2.0
#observation_sources: laser_scan_sensor observation_sources: laser_scan_sensor
observation_sources: laser_scan_sensor point_cloud_sensor #observation_sources: laser_scan_sensor point_cloud_sensor
laser_scan_sensor: { laser_scan_sensor: {
data_type: LaserScan, data_type: LaserScan,
topic: base_scan, topic: base_scan,
expected_update_rate: 0.2, expected_update_rate: 0.2,
marking: true, marking: true,
clearing: true} clearing: false}
point_cloud_sensor: { point_cloud_sensor: {
sensor_frame: base_footprint, sensor_frame: base_footprint,
@@ -30,3 +30,4 @@ local_costmap:
clearing: true, clearing: true,
min_obstacle_height: 0.05, min_obstacle_height: 0.05,
max_obstacle_height: 0.4} max_obstacle_height: 0.4}
@@ -11,15 +11,15 @@ local_costmap:
origin_x: -2.0 origin_x: -2.0
origin_y: -2.0 origin_y: -2.0
observation_sources: laser_scan_sensor point_cloud_sensor #observation_sources: laser_scan_sensor point_cloud_sensor
#observation_sources: point_cloud_sensor observation_sources: point_cloud_sensor
laser_scan_sensor: { laser_scan_sensor: {
data_type: LaserScan, data_type: LaserScan,
topic: base_scan, topic: base_scan,
expected_update_rate: 0.2, expected_update_rate: 0.2,
marking: true, marking: true,
clearing: false} clearing: true}
# assuming receiving a cloud from rtabmap/obstacles_detection node # assuming receiving a cloud from rtabmap/obstacles_detection node
point_cloud_sensor: { point_cloud_sensor: {
+3
View File
@@ -35,6 +35,7 @@
<build_depend>class_loader</build_depend> <build_depend>class_loader</build_depend>
<build_depend>rtabmap</build_depend> <build_depend>rtabmap</build_depend>
<build_depend>move_base_msgs</build_depend> <build_depend>move_base_msgs</build_depend>
<build_depend>costmap_2d</build_depend>
<build_depend>octomap_ros</build_depend> <build_depend>octomap_ros</build_depend>
<build_depend>octomap</build_depend> <build_depend>octomap</build_depend>
@@ -62,6 +63,7 @@
<run_depend>class_loader</run_depend> <run_depend>class_loader</run_depend>
<run_depend>rtabmap</run_depend> <run_depend>rtabmap</run_depend>
<run_depend>move_base_msgs</run_depend> <run_depend>move_base_msgs</run_depend>
<run_depend>costmap_2d</run_depend>
<run_depend>octomap_ros</run_depend> <run_depend>octomap_ros</run_depend>
<run_depend>octomap</run_depend> <run_depend>octomap</run_depend>
@@ -70,5 +72,6 @@
<export> <export>
<nodelet plugin="${prefix}/nodelet_plugins.xml" /> <nodelet plugin="${prefix}/nodelet_plugins.xml" />
<rviz plugin="${prefix}/plugin_description.xml"/> <rviz plugin="${prefix}/plugin_description.xml"/>
<costmap_2d plugin="${prefix}/costmap_plugins.xml"/>
</export> </export>
</package> </package>
+266
View File
@@ -0,0 +1,266 @@
/*********************************************************************
*
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, 2013, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Eitan Marder-Eppstein
* David V. Lu!!
*********************************************************************/
/*
* Modified: added "layered_costmap_->updateMap(0,0,0);" below
*/
#include "static_layer.h"
#include <costmap_2d/costmap_math.h>
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::StaticLayer, costmap_2d::Layer)
using costmap_2d::NO_INFORMATION;
using costmap_2d::LETHAL_OBSTACLE;
using costmap_2d::FREE_SPACE;
namespace rtabmap_ros
{
StaticLayer::StaticLayer() : dsrv_(NULL) {}
StaticLayer::~StaticLayer()
{
if(dsrv_)
delete dsrv_;
}
void StaticLayer::onInitialize()
{
ros::NodeHandle nh("~/" + name_), g_nh;
current_ = true;
global_frame_ = layered_costmap_->getGlobalFrameID();
std::string map_topic;
nh.param("map_topic", map_topic, std::string("map"));
nh.param("subscribe_to_updates", subscribe_to_updates_, false);
nh.param("track_unknown_space", track_unknown_space_, true);
nh.param("use_maximum", use_maximum_, false);
int temp_lethal_threshold, temp_unknown_cost_value;
nh.param("lethal_cost_threshold", temp_lethal_threshold, int(100));
nh.param("unknown_cost_value", temp_unknown_cost_value, int(-1));
nh.param("trinary_costmap", trinary_costmap_, true);
lethal_threshold_ = std::max(std::min(temp_lethal_threshold, 100), 0);
unknown_cost_value_ = temp_unknown_cost_value;
//we'll subscribe to the latched topic that the map server uses
ROS_INFO("Requesting the map...");
map_sub_ = g_nh.subscribe(map_topic, 1, &StaticLayer::incomingMap, this);
map_received_ = false;
has_updated_data_ = false;
ros::Rate r(10);
while (!map_received_ && g_nh.ok())
{
ros::spinOnce();
r.sleep();
}
ROS_INFO("Received a %d X %d map at %f m/pix", getSizeInCellsX(), getSizeInCellsY(), getResolution());
if(subscribe_to_updates_)
{
ROS_INFO("Subscribing to updates");
map_update_sub_ = g_nh.subscribe(map_topic + "_updates", 10, &StaticLayer::incomingUpdate, this);
}
if(dsrv_)
{
delete dsrv_;
}
dsrv_ = new dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig>(nh);
dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig>::CallbackType cb = boost::bind(
&StaticLayer::reconfigureCB, this, _1, _2);
dsrv_->setCallback(cb);
}
void StaticLayer::reconfigureCB(costmap_2d::GenericPluginConfig &config, uint32_t level)
{
if (config.enabled != enabled_)
{
enabled_ = config.enabled;
has_updated_data_ = true;
x_ = y_ = 0;
width_ = size_x_;
height_ = size_y_;
}
}
void StaticLayer::matchSize()
{
Costmap2D* master = layered_costmap_->getCostmap();
resizeMap(master->getSizeInCellsX(), master->getSizeInCellsY(), master->getResolution(),
master->getOriginX(), master->getOriginY());
}
unsigned char StaticLayer::interpretValue(unsigned char value)
{
//check if the static value is above the unknown or lethal thresholds
if (track_unknown_space_ && value == unknown_cost_value_)
return NO_INFORMATION;
else if (value >= lethal_threshold_)
return LETHAL_OBSTACLE;
else if (trinary_costmap_)
return FREE_SPACE;
double scale = (double) value / lethal_threshold_;
return scale * LETHAL_OBSTACLE;
}
void StaticLayer::incomingMap(const nav_msgs::OccupancyGridConstPtr& new_map)
{
unsigned int size_x = new_map->info.width, size_y = new_map->info.height;
ROS_DEBUG("Received a %d X %d map at %f m/pix", size_x, size_y, new_map->info.resolution);
// resize costmap if size, resolution or origin do not match
Costmap2D* master = layered_costmap_->getCostmap();
if (master->getSizeInCellsX() != size_x ||
master->getSizeInCellsY() != size_y ||
master->getResolution() != new_map->info.resolution ||
master->getOriginX() != new_map->info.origin.position.x ||
master->getOriginY() != new_map->info.origin.position.y ||
!layered_costmap_->isSizeLocked())
{
ROS_INFO("Resizing costmap to %d X %d at %f m/pix", size_x, size_y, new_map->info.resolution);
layered_costmap_->resizeMap(size_x, size_y, new_map->info.resolution, new_map->info.origin.position.x,
new_map->info.origin.position.y, true);
}else if(size_x_ != size_x || size_y_ != size_y ||
resolution_ != new_map->info.resolution ||
origin_x_ != new_map->info.origin.position.x ||
origin_y_ != new_map->info.origin.position.y){
matchSize();
}
unsigned int index = 0;
//initialize the costmap with static data
for (unsigned int i = 0; i < size_y; ++i)
{
for (unsigned int j = 0; j < size_x; ++j)
{
unsigned char value = new_map->data[index];
costmap_[index] = interpretValue(value);
++index;
}
}
x_ = y_ = 0;
width_ = size_x_;
height_ = size_y_;
map_received_ = true;
has_updated_data_ = true;
layered_costmap_->updateMap(0,0,0);
}
void StaticLayer::incomingUpdate(const map_msgs::OccupancyGridUpdateConstPtr& update)
{
unsigned int di = 0;
for (unsigned int y = 0; y < update->height ; y++)
{
unsigned int index_base = (update->y + y) * size_x_;
for (unsigned int x = 0; x < update->width ; x++)
{
unsigned int index = index_base + x + update->x;
costmap_[index] = interpretValue( update->data[di++] );
}
}
x_ = update->x;
y_ = update->y;
width_ = update->width;
height_ = update->height;
has_updated_data_ = true;
layered_costmap_->updateMap(0,0,0);
}
void StaticLayer::activate()
{
onInitialize();
}
void StaticLayer::deactivate()
{
map_sub_.shutdown();
if (subscribe_to_updates_)
map_update_sub_.shutdown();
}
void StaticLayer::reset()
{
deactivate();
activate();
}
void StaticLayer::updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x, double* min_y,
double* max_x, double* max_y)
{
if (!map_received_ || !(has_updated_data_ || has_extra_bounds_))
return;
useExtraBounds(min_x, min_y, max_x, max_y);
double mx, my;
mapToWorld(x_, y_, mx, my);
*min_x = std::min(mx, *min_x);
*min_y = std::min(my, *min_y);
mapToWorld(x_ + width_, y_ + height_, mx, my);
*max_x = std::max(mx, *max_x);
*max_y = std::max(my, *max_y);
has_updated_data_ = false;
}
void StaticLayer::updateCosts(costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j)
{
if (!map_received_)
return;
if (!use_maximum_)
updateWithTrueOverwrite(master_grid, min_i, min_j, max_i, max_j);
else
updateWithMax(master_grid, min_i, min_j, max_i, max_j);
}
} // namespace rtabmap_ros
+100
View File
@@ -0,0 +1,100 @@
/*********************************************************************
*
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, 2013, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Eitan Marder-Eppstein
* David V. Lu!!
*********************************************************************/
#ifndef RTABMAP_ROS_STATIC_LAYER_H_
#define RTABMAP_ROS_STATIC_LAYER_H_
#include <ros/ros.h>
#include <costmap_2d/costmap_layer.h>
#include <costmap_2d/layered_costmap.h>
#include <costmap_2d/GenericPluginConfig.h>
#include <dynamic_reconfigure/server.h>
#include <nav_msgs/OccupancyGrid.h>
#include <map_msgs/OccupancyGridUpdate.h>
#include <message_filters/subscriber.h>
namespace rtabmap_ros
{
class StaticLayer : public costmap_2d::CostmapLayer
{
public:
StaticLayer();
virtual ~StaticLayer();
virtual void onInitialize();
virtual void activate();
virtual void deactivate();
virtual void reset();
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x, double* min_y, double* max_x,
double* max_y);
virtual void updateCosts(costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j);
virtual void matchSize();
private:
/**
* @brief Callback to update the costmap's map from the map_server
* @param new_map The map to put into the costmap. The origin of the new
* map along with its size will determine what parts of the costmap's
* static map are overwritten.
*/
void incomingMap(const nav_msgs::OccupancyGridConstPtr& new_map);
void incomingUpdate(const map_msgs::OccupancyGridUpdateConstPtr& update);
void reconfigureCB(costmap_2d::GenericPluginConfig &config, uint32_t level);
unsigned char interpretValue(unsigned char value);
std::string global_frame_; ///< @brief The global frame for the costmap
bool subscribe_to_updates_;
bool map_received_;
bool has_updated_data_;
unsigned int x_,y_,width_,height_;
bool track_unknown_space_;
bool use_maximum_;
bool trinary_costmap_;
ros::Subscriber map_sub_, map_update_sub_;
unsigned char lethal_threshold_, unknown_cost_value_;
mutable boost::recursive_mutex lock_;
dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig> *dsrv_;
};
} // namespace rtabmap_ros
#endif // RTABMAP_ROS_DYNAMIC_LAYER_H_