Skip to content

Commit c246b27

Browse files
bradygmnls5260
andauthored
Search map allocation and splitting (#109)
* New BeliefMapData msg for communicating updates to the search maps * Add ability for belief maps updates. * Search map splitting (#108) * base code for splitting search bounds into individual regions for agents to search * Small changes and organization. Fixed some build warnings. * Add CGAL to dev dockerfile * Change SearchPrior.msg to have vectors of value and priority to reduce size of overal search mission request * Add priority to grid_map * Set the search priors for each task assignment from the allocations of the overall search space * Move some member variables out of MissionManager.cpp and fixed build warnings * Remove unneccesary member variables in MissionManager. Restructure so search mission allocation resets each call. * Add params for mission manager * Bump docker version --------- Co-authored-by: Nayana Suvarna <[email protected]> * Increment docker image version --------- Co-authored-by: Nayana Suvarna <[email protected]>
1 parent 7aa27c0 commit c246b27

File tree

16 files changed

+602
-47
lines changed

16 files changed

+602
-47
lines changed

docker/Dockerfile.airstack-dev

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ RUN apt update -y && apt install -y \
2727
ros-humble-stereo-image-proc \
2828
ros-humble-image-view \
2929
ros-humble-topic-tools \
30-
ros-humble-grid-map
30+
ros-humble-grid-map \
31+
libcgal-dev
3132

3233
RUN /opt/ros/humble/lib/mavros/install_geographiclib_datasets.sh
3334

docker/docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ services:
5959

6060
# ==============================================================================
6161
robot:
62-
image: &airstack-dev-image airlab-storage.andrew.cmu.edu:5001/shared/airstack-dev:v0.5.1
62+
image: &airstack-dev-image airlab-storage.andrew.cmu.edu:5001/shared/airstack-dev:v0.5.2
6363
build:
6464
context: ../
6565
dockerfile: docker/Dockerfile.airstack-dev

docker/ground_control_station/.bashrc

+2
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,5 @@ function cws(){
157157

158158
source /opt/ros/humble/setup.bash
159159
sws # source the ROS2 workspace by default
160+
161+
export RCUTILS_COLORIZED_OUTPUT=1

ros_ws/src/airstack_msgs/msg/SearchPrior.msg

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ uint8 POINT_PRIOR = 3
66
uint8 grid_prior_type
77

88
geometry_msgs/Polygon points_list # polygon, line seg, or list of point
9-
float32 value # initial value for the polygon, line seg, or point
9+
float32[] value # initial value for the polygon, line seg, or point
1010

1111
# Optional values
12-
float64 priority # Higher values mean higher priority. If empty then the priority is set to 1.0
13-
uint8 sensor_model_id # the type of sensor model for that region type. Default is 0
12+
float32[] priority # Higher values mean higher priority. If empty then the priority is set to 1.0
13+
uint8[] sensor_model_id # the type of sensor model for that region type. Default is 0

ros_ws/src/ground_control_station/mission_manager/CMakeLists.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
55
add_compile_options(-Wall -Wextra -Wpedantic)
66
endif()
77

8+
set(CGAL_DATA_DIR ".")
9+
810
# find dependencies
911
find_package(ament_cmake REQUIRED)
1012
find_package(rclcpp REQUIRED)
1113
find_package(std_msgs REQUIRED)
1214
find_package(airstack_msgs REQUIRED)
1315
find_package(grid_map_ros REQUIRED)
14-
16+
find_package(CGAL REQUIRED)
1517

1618
add_executable(mission_manager_node
1719
src/mission_manager_node.cpp
@@ -26,12 +28,17 @@ ament_target_dependencies(example_search_request_node rclcpp airstack_msgs)
2628

2729
target_include_directories(mission_manager_node PUBLIC
2830
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
29-
$<INSTALL_INTERFACE:include>)
31+
$<INSTALL_INTERFACE:include>
32+
${CGAL_INCLUDE_DIRS})
3033

3134
target_include_directories(example_search_request_node PUBLIC
3235
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3336
$<INSTALL_INTERFACE:include>)
3437

38+
target_link_libraries(mission_manager_node
39+
${CGAL_LIBRARIES} # Link CGAL libraries
40+
)
41+
3542
target_compile_features(mission_manager_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
3643
target_compile_features(example_search_request_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
3744

ros_ws/src/ground_control_station/mission_manager/config/mission_manager.rviz

+14-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ Visualization Manager:
7474
Value: /search_map_basestation
7575
Use Rainbow: true
7676
Value: true
77+
- Class: rviz_default_plugins/MarkerArray
78+
Enabled: true
79+
Name: Search Space Allocation Debugger
80+
Namespaces:
81+
{}
82+
Topic:
83+
Depth: 5
84+
Durability Policy: Volatile
85+
History Policy: Keep Last
86+
Reliability Policy: Reliable
87+
Value: /task_allocation_viz
88+
Value: true
7789
Enabled: true
7890
Global Options:
7991
Background Color: 48; 48; 48
@@ -135,10 +147,10 @@ Visualization Manager:
135147
Invert Z Axis: false
136148
Name: Current View
137149
Near Clip Distance: 0.009999999776482582
138-
Pitch: 1.5047963857650757
150+
Pitch: 1.5697963237762451
139151
Target Frame: <Fixed Frame>
140152
Value: Orbit (rviz)
141-
Yaw: 4.693580150604248
153+
Yaw: 4.71858024597168
142154
Saved: ~
143155
Window Geometry:
144156
Displays:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mission_manager_node:
2+
ros__parameters:
3+
grid_cell_size: 5.0
4+
visualize_search_allocation: true

ros_ws/src/ground_control_station/mission_manager/include/mission_manager/BeliefMap.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BeliefMap
3030
// std::vector<std::vector<int>> sensor_model_id;
3131

3232
BeliefMap();
33-
bool reset_map(rclcpp::Logger logger, airstack_msgs::msg::SearchMissionRequest search_mission_request);
33+
bool reset_map(rclcpp::Logger logger, airstack_msgs::msg::SearchMissionRequest search_mission_request, double grid_cell_size);
3434
bool update_map(rclcpp::Logger logger, const airstack_msgs::msg::BeliefMapData::SharedPtr new_belief_data);
3535
grid_map::GridMap map_;
3636

@@ -39,7 +39,31 @@ class BeliefMap
3939
return !map_.getSize()(0) == 0;
4040
}
4141

42+
double get_min_x() const
43+
{
44+
return min_x;
45+
}
46+
double get_max_x() const
47+
{
48+
return max_x;
49+
}
50+
double get_min_y() const
51+
{
52+
return min_y;
53+
}
54+
double get_max_y() const
55+
{
56+
return max_y;
57+
}
58+
4259
private:
60+
//search map allocation
61+
double min_x = DBL_MAX;
62+
double max_x = -DBL_MAX;
63+
double min_y = DBL_MAX;
64+
double max_y = -DBL_MAX;
65+
double grid_cell_size_;
66+
4367

4468
};
4569

ros_ws/src/ground_control_station/mission_manager/include/mission_manager/MissionManager.h

+63-1
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,71 @@
77
#include <memory>
88
#include <cstdint>
99
#include <string>
10+
#include <limits>
11+
#include <random>
12+
#include <queue>
13+
#include <boost/functional/hash.hpp>
14+
15+
#include <CGAL/Polygon_2.h>
16+
#include <CGAL/Alpha_shape_2.h>
17+
#include <CGAL/Simple_cartesian.h>
18+
#include <CGAL/Polygon_2_algorithms.h>
19+
#include <CGAL/Delaunay_triangulation_2.h>
20+
#include <CGAL/Triangulation_data_structure_2.h>
21+
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
1022

1123
#include "rclcpp/rclcpp.hpp"
1224
#include "std_msgs/msg/string.hpp"
25+
#include <geometry_msgs/msg/point.hpp>
26+
#include "geometry_msgs/msg/point32.hpp"
27+
#include <visualization_msgs/msg/marker_array.hpp>
1328
#include "airstack_msgs/msg/search_mission_request.hpp"
1429
#include "airstack_msgs/msg/task_assignment.hpp"
1530
#include "mission_manager/BeliefMap.h"
1631

32+
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
33+
typedef K::Point_2 Point;
34+
typedef CGAL::Alpha_shape_vertex_base_2<K> Vb;
35+
typedef CGAL::Alpha_shape_face_base_2<K> Fb;
36+
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
37+
typedef CGAL::Delaunay_triangulation_2<K, Tds> Triangulation_2;
38+
typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2;
39+
typedef Alpha_shape_2::Edge Edge;
40+
typedef CGAL::Segment_2<K> Segment;
41+
42+
struct ClusterPoint
43+
{
44+
double x, y;
45+
int cluster;
46+
double cluster_dist;
47+
48+
ClusterPoint(double _x, double _y, int _cluster_idx, double _cluster_dist)
49+
{
50+
x = _x;
51+
y = _y;
52+
cluster = _cluster_idx;
53+
cluster_dist = _cluster_dist;
54+
}
55+
};
56+
57+
struct CompareClusterPoint
58+
{
59+
bool operator()(const ClusterPoint& a, const ClusterPoint& b) const
60+
{
61+
return a.cluster_dist > b.cluster_dist; // Min-heap based on cluster_dist
62+
}
63+
};
64+
65+
1766
class MissionManager
1867
{
1968
public:
2069
MissionManager(int max_number_agents);
2170

22-
std::vector<airstack_msgs::msg::TaskAssignment> assign_tasks(rclcpp::Logger logger) const;
71+
std::vector<airstack_msgs::msg::TaskAssignment> assign_tasks(rclcpp::Logger logger,
72+
const airstack_msgs::msg::SearchMissionRequest &plan_request,
73+
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr pub,
74+
bool visualize_search_allocation);
2375
bool check_agent_changes(rclcpp::Logger logger, uint8_t robot_id, rclcpp::Time current_time);
2476
bool check_target_changes(rclcpp::Logger logger, std::string target_list, rclcpp::Time current_time);
2577
std::vector<bool> get_valid_agents() const { return valid_agents_; }
@@ -30,5 +82,15 @@ class MissionManager
3082
std::vector<rclcpp::Time> time_of_last_call_;
3183
std::vector<bool> valid_agents_;
3284

85+
//search map allocation
86+
std::vector<std::vector<std::vector<double>>> allocate_search_map(rclcpp::Logger logger,
87+
int number_of_search_tasks,
88+
const airstack_msgs::msg::SearchMissionRequest &plan_request,
89+
std::vector<std::vector<double>> &cluster_centroids,
90+
std::vector<std::vector<ClusterPoint>> &clusters);
91+
std::vector<std::vector<double>> calculate_cluster_centroids(rclcpp::Logger logger, int num_agents, const airstack_msgs::msg::SearchMissionRequest &plan_request, std::vector<Point> &CGAL_bounds) const;
92+
std::vector<std::vector<ClusterPoint>> calculate_clusters(rclcpp::Logger logger, int num_agents, std::vector<std::vector<double>> cluster_centroids, const std::vector<Point> &CGAL_bounds) const;
93+
std::vector<std::vector<std::vector<double>>> calculate_cluster_bounds(rclcpp::Logger logger, std::vector<std::vector<ClusterPoint>> clusters) const;
94+
3395
};
3496
#endif /* MISSIONMANAGER_H_INCLUDED */

ros_ws/src/ground_control_station/mission_manager/include/mission_manager/mission_manager_node.h

+17-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "rclcpp/rclcpp.hpp"
1212
#include "std_msgs/msg/string.hpp"
13+
#include "visualization_msgs/msg/marker_array.hpp"
1314
#include "airstack_msgs/msg/search_mission_request.hpp"
1415
#include "airstack_msgs/msg/task_assignment.hpp"
1516
#include "airstack_msgs/msg/belief_map_data.hpp"
@@ -41,6 +42,12 @@ class MissionManagerNode : public rclcpp::Node
4142
MissionManagerNode()
4243
: Node("mission_manager"), count_(0)
4344
{
45+
this->declare_parameter("grid_cell_size", 10.0);
46+
this->declare_parameter("visualize_search_allocation", false);
47+
this->get_parameter("grid_cell_size", grid_cell_size_);
48+
this->get_parameter("visualize_search_allocation", visualize_search_allocation_);
49+
50+
4451
mission_subscriber_ = this->create_subscription<airstack_msgs::msg::SearchMissionRequest>(
4552
"search_mission_request", 1, std::bind(&MissionManagerNode::search_mission_request_callback, this, std::placeholders::_1));
4653

@@ -75,6 +82,9 @@ class MissionManagerNode : public rclcpp::Node
7582
// TODO: set param for rate, make sure not communicated over network
7683
search_map_publisher_ = this->create_publisher<grid_map_msgs::msg::GridMap>(
7784
"search_map_basestation", rclcpp::QoS(1).transient_local());
85+
86+
viz_pub_ = this->create_publisher<visualization_msgs::msg::MarkerArray>("task_allocation_viz", 10.0);
87+
7888
timer_ = this->create_wall_timer(
7989
std::chrono::seconds(1), std::bind(&MissionManagerNode::search_map_publisher, this));
8090
}
@@ -84,6 +94,7 @@ class MissionManagerNode : public rclcpp::Node
8494

8595
// Publisher
8696
std::vector<rclcpp::Publisher<airstack_msgs::msg::TaskAssignment>::SharedPtr> plan_request_pubs_;
97+
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr viz_pub_;
8798
rclcpp::Publisher<grid_map_msgs::msg::GridMap>::SharedPtr search_map_publisher_;
8899

89100
// Subscribers
@@ -97,6 +108,8 @@ class MissionManagerNode : public rclcpp::Node
97108

98109
size_t count_;
99110
rclcpp::TimerBase::SharedPtr timer_;
111+
double grid_cell_size_;
112+
bool visualize_search_allocation_;
100113
int max_number_agents_ = 5; // TODO: get from param server
101114
airstack_msgs::msg::SearchMissionRequest latest_search_mission_request_;
102115
std::shared_ptr<MissionManager> mission_manager_;
@@ -133,16 +146,16 @@ class MissionManagerNode : public rclcpp::Node
133146
latest_search_mission_request_ = *msg;
134147

135148
// TODO: visualize the seach mission request
136-
this->mission_manager_->belief_map_.reset_map(this->get_logger(), *msg);
137-
this->publish_tasks(this->mission_manager_->assign_tasks(this->get_logger()));
149+
this->mission_manager_->belief_map_.reset_map(this->get_logger(), *msg, grid_cell_size_);
150+
this->publish_tasks(this->mission_manager_->assign_tasks(this->get_logger(), latest_search_mission_request_, viz_pub_, visualize_search_allocation_));
138151
}
139152

140153
void agent_odom_callback(const std_msgs::msg::String::SharedPtr msg, const uint8_t &robot_id)
141154
{
142155
RCLCPP_INFO(this->get_logger(), "Received agent odom '%s'", msg->data.c_str());
143156
if (this->mission_manager_->check_agent_changes(this->get_logger(), robot_id, this->now()))
144157
{
145-
this->publish_tasks(this->mission_manager_->assign_tasks(this->get_logger()));
158+
this->publish_tasks(this->mission_manager_->assign_tasks(this->get_logger(), latest_search_mission_request_, viz_pub_, visualize_search_allocation_));
146159
}
147160
}
148161

@@ -154,7 +167,7 @@ class MissionManagerNode : public rclcpp::Node
154167
// Check if change in the number of targets or id numbers
155168
if (this->mission_manager_->check_target_changes(this->get_logger(), msg->data, this->now()))
156169
{
157-
this->publish_tasks(this->mission_manager_->assign_tasks(this->get_logger()));
170+
this->publish_tasks(this->mission_manager_->assign_tasks(this->get_logger(), latest_search_mission_request_, viz_pub_, visualize_search_allocation_));
158171
}
159172
}
160173

0 commit comments

Comments
 (0)