-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indigo-devel branch fully ported to ROS2
- Loading branch information
1 parent
14bbccf
commit 82c692f
Showing
15 changed files
with
1,409 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<library path="frontier_exploration_core"> | ||
<class name="frontier_exploration/BoundedExploreLayer" | ||
type="frontier_exploration::BoundedExploreLayer" | ||
base_class_type="nav2_costmap_2d::Layer"> | ||
<description>Demo Layer that marks all points that were ever one meter in front of the robot</description> | ||
</class> | ||
</library> |
148 changes: 148 additions & 0 deletions
148
frontier_exploration/include/frontier_exploration/bounded_explore_layer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#ifndef BOUNDED_EXPLORE_LAYER_H_ | ||
#define BOUNDED_EXPLORE_LAYER_H_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <rclcpp_lifecycle/lifecycle_node.hpp> | ||
#include <nav2_costmap_2d/layer.hpp> | ||
#include <nav2_costmap_2d/layered_costmap.hpp> | ||
|
||
#include <geometry_msgs/msg/polygon.hpp> | ||
#include <geometry_msgs/msg/quaternion.h> | ||
|
||
#include <sensor_msgs/msg/point_cloud2.hpp> | ||
|
||
#include <frontier_msgs/msg/frontier.hpp> | ||
#include <frontier_msgs/srv/update_boundary_polygon.hpp> | ||
#include <frontier_msgs/srv/get_next_frontier.hpp> | ||
|
||
#include <tf2_ros/buffer.h> | ||
#include <tf2/LinearMath/Quaternion.h> | ||
|
||
namespace frontier_exploration | ||
{ | ||
|
||
/** | ||
* @brief costmap_2d layer plugin that holds the state for a bounded frontier exploration task. | ||
* Manages the boundary polygon, superimposes the polygon on the overall exploration costmap, | ||
* and processes costmap to find next frontier to explore. | ||
*/ | ||
class BoundedExploreLayer : public nav2_costmap_2d::Layer, public nav2_costmap_2d::Costmap2D | ||
{ | ||
public: | ||
BoundedExploreLayer(); | ||
~BoundedExploreLayer(); | ||
|
||
/** | ||
* @brief Loads default values and initialize exploration costmap. | ||
*/ | ||
virtual void onInitialize(); | ||
|
||
/** | ||
* @brief Calculate bounds of costmap window to update | ||
*/ | ||
virtual void updateBounds(double origin_x, double origin_y, double origin_yaw, double* polygon_min_x, double* polygon_min_y, double* polygon_max_x, | ||
double* polygon_max_y); | ||
|
||
/** | ||
* @brief Update requested costmap window | ||
*/ | ||
virtual void updateCosts(nav2_costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j); | ||
|
||
bool isDiscretized() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @brief Match dimensions and origin of parent costmap | ||
*/ | ||
void matchSize() override; | ||
|
||
/** | ||
* @brief If clearing operations should be processed on this layer or not | ||
*/ | ||
virtual bool isClearable() {return false;} | ||
|
||
/** | ||
* @brief Reset exploration progress | ||
*/ | ||
virtual void reset(); | ||
|
||
// std::shared_ptr<rclcpp::Node> node = std::make_shared<rclcpp::Node>("bounded_explore_layer"); | ||
|
||
geometry_msgs::msg::Quaternion createQuaternionMsgFromYaw(double yaw); | ||
|
||
rclcpp::Service<frontier_msgs::srv::UpdateBoundaryPolygon>::SharedPtr polygonService_; | ||
rclcpp::Service<frontier_msgs::srv::GetNextFrontier>::SharedPtr frontierService_; | ||
|
||
// rclcpp_lifecycle::LifecycleNode::SharedPtr node = node_.lock(); | ||
// rclcpp::Node::SharedPtr node = std::make_shared<rclcpp::Node>("bounded_explore_layer"); | ||
|
||
protected: | ||
|
||
/** | ||
* @brief ROS Service wrapper for updateBoundaryPolygon | ||
* @param req Service request | ||
* @param res Service response | ||
* @return True on service success, false otherwise | ||
*/ | ||
/** | ||
* @brief Load polygon boundary to draw on map with each update | ||
* @param polygon_stamped polygon boundary | ||
* @return True if polygon successfully loaded, false otherwise | ||
*/ | ||
void updateBoundaryPolygonService( | ||
const std::shared_ptr<rmw_request_id_t> request_header, | ||
const std::shared_ptr<frontier_msgs::srv::UpdateBoundaryPolygon::Request> req, | ||
std::shared_ptr<frontier_msgs::srv::UpdateBoundaryPolygon::Response> res); | ||
|
||
/** | ||
* @brief ROS Service wrapper for getNextFrontier | ||
* @param req Service request | ||
* @param res Service response | ||
* @return True on service success, false otherwise | ||
*/ | ||
/** | ||
* @brief Search the costmap for next reachable frontier to explore | ||
* @param start_pose Pose from which to start search | ||
* @param next_frontier Pose of found frontier | ||
* @return True if a reachable frontier was found, false otherwise | ||
*/ | ||
void getNextFrontierService( | ||
const std::shared_ptr<rmw_request_id_t> request_header, | ||
const std::shared_ptr<frontier_msgs::srv::GetNextFrontier::Request> req, | ||
std::shared_ptr<frontier_msgs::srv::GetNextFrontier::Response> res); | ||
|
||
private: | ||
|
||
/** | ||
* @brief Update the map with exploration boundary data | ||
* @param master_grid Reference to master costmap | ||
*/ | ||
void mapUpdateKeepObstacles(nav2_costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j); | ||
|
||
/** | ||
* @brief Callback executed when a parameter change is detected | ||
* @param event ParameterEvent message | ||
*/ | ||
rcl_interfaces::msg::SetParametersResult dynamicParametersCallback(std::vector<rclcpp::Parameter> parameters); | ||
|
||
geometry_msgs::msg::Polygon polygon_; | ||
std::shared_ptr<tf2_ros::Buffer> tf_buffer_; | ||
|
||
rclcpp_lifecycle::LifecyclePublisher<sensor_msgs::msg::PointCloud2>::SharedPtr frontier_cloud_pub; | ||
|
||
bool enabledLayer_; | ||
bool configured_, marked_; | ||
bool explore_clear_space_; | ||
bool resize_to_boundary_; | ||
std::string frontier_travel_point_; | ||
int max; | ||
double frontierDetectRadius_; | ||
|
||
// Dynamic parameters handler | ||
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_; | ||
}; | ||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import os | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
|
||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable | ||
from launch.conditions import IfCondition | ||
from launch.substitutions import LaunchConfiguration, PythonExpression | ||
from launch_ros.actions import LoadComposableNodes | ||
from launch_ros.actions import Node | ||
from launch_ros.descriptions import ComposableNode | ||
from nav2_common.launch import RewrittenYaml | ||
|
||
|
||
def generate_launch_description(): | ||
# Get the launch directory | ||
exploration_package_dir = get_package_share_directory('frontier_exploration') | ||
|
||
namespace = LaunchConfiguration('namespace') | ||
params_file = LaunchConfiguration('params_file') | ||
log_level = LaunchConfiguration('log_level') | ||
|
||
# Create our own temporary YAML files that include substitutions | ||
param_substitutions = {} | ||
|
||
configured_params = RewrittenYaml( | ||
source_file=params_file, | ||
root_key=namespace, | ||
param_rewrites=param_substitutions, | ||
convert_types=True) | ||
|
||
declare_params_file_cmd = DeclareLaunchArgument( | ||
'params_file', | ||
default_value=os.path.join(exploration_package_dir, 'params', 'exploration_params.yaml'), | ||
description='Full path to the ROS2 parameters file to use for all launched nodes') | ||
|
||
declare_use_composition_cmd = DeclareLaunchArgument( | ||
'use_composition', default_value='False', | ||
description='Use composed bringup if True') | ||
|
||
declare_log_level_cmd = DeclareLaunchArgument( | ||
'log_level', default_value='info', | ||
description='log level') | ||
|
||
declare_namespace_cmd = DeclareLaunchArgument( | ||
'namespace', | ||
default_value='', | ||
description='Top-level namespace') | ||
|
||
load_nodes = GroupAction( | ||
actions=[ | ||
Node( | ||
package='frontier_exploration', | ||
executable='explore_server', | ||
output='screen', | ||
parameters=[configured_params], | ||
arguments=['--ros-args', '--log-level', log_level]), | ||
] | ||
) | ||
|
||
# Create the launch description and populate | ||
ld = LaunchDescription() | ||
|
||
ld.add_action(declare_namespace_cmd) | ||
# Declare the launch options | ||
ld.add_action(declare_params_file_cmd) | ||
ld.add_action(declare_use_composition_cmd) | ||
ld.add_action(declare_log_level_cmd) | ||
# Add the actions to launch all of the navigation nodes | ||
ld.add_action(load_nodes) | ||
|
||
return ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
explore_costmap: | ||
explore_costmap: | ||
ros__parameters: | ||
footprint: "[ [0.48, 0.38], [0.48, -0.38], [-0.48, -0.38], [ -0.48, 0.38 ] ]" | ||
update_frequency: 1.0 | ||
publish_frequency: 1.0 | ||
global_frame: map | ||
robot_base_frame: base_link | ||
use_sim_time: True | ||
# robot_radius: 0.22 | ||
resolution: 0.05 | ||
track_unknown_space: true | ||
plugins: ["static_layer", "obstacle_layer", "bounded_explore_layer"] | ||
# plugins: ["static_layer", "obstacle_layer", "inflation_layer"] | ||
obstacle_layer: | ||
plugin: "nav2_costmap_2d::ObstacleLayer" | ||
enabled: True | ||
observation_sources: scan | ||
scan: | ||
topic: /camera/points | ||
max_obstacle_height: 2.0 | ||
clearing: True | ||
marking: True | ||
data_type: "PointCloud2" | ||
raytrace_max_range: 3.0 | ||
raytrace_min_range: 0.0 | ||
obstacle_max_range: 2.5 | ||
obstacle_min_range: 0.0 | ||
max_obstacle_height: 0.4 | ||
static_layer: | ||
plugin: "nav2_costmap_2d::StaticLayer" | ||
map_subscribe_transient_local: True | ||
bounded_explore_layer: | ||
plugin: "frontier_exploration/BoundedExploreLayer" | ||
enabled: true | ||
resize_to_boundary: false | ||
frontier_travel_point: middle | ||
explore_clear_space: false | ||
always_send_full_costmap: True | ||
|
||
explore_server: | ||
ros__parameters: | ||
frequency: 1.0 | ||
goal_aliasing: 2.0 |
Oops, something went wrong.