@@ -34,50 +34,54 @@ void Visualizer::visualize(
34
34
const std::shared_ptr<ComputeCoveragePath::Result> & result,
35
35
const std_msgs::msg::Header & header)
36
36
{
37
- if (!visualize_) {
38
- return ;
39
- }
40
-
41
37
// Visualize coverage path
42
- nav_plan_pub_->publish (std::move (std::make_unique<nav_msgs::msg::Path>(result->nav_path )));
38
+ if (nav_plan_pub_->get_subscription_count () > 0 ) {
39
+ nav_plan_pub_->publish (std::move (std::make_unique<nav_msgs::msg::Path>(result->nav_path )));
40
+ }
43
41
44
42
// Visualize field boundary
45
- auto field_polygon = std::make_unique<geometry_msgs::msg::PolygonStamped>();
46
- field_polygon->header = header;
47
- Polygon boundary = total_field.getGeometry (0 ); // Only outer-most polygon boundary
48
- for (unsigned int i = 0 ; i != boundary.size (); i++) {
49
- field_polygon->polygon .points .push_back (util::toMsg (boundary.getGeometry (i)));
43
+ if (headlands_pub_->get_subscription_count () > 0 ) {
44
+ auto field_polygon = std::make_unique<geometry_msgs::msg::PolygonStamped>();
45
+ field_polygon->header = header;
46
+ Polygon boundary = total_field.getGeometry (0 ); // Only outer-most polygon boundary
47
+ for (unsigned int i = 0 ; i != boundary.size (); i++) {
48
+ field_polygon->polygon .points .push_back (util::toMsg (boundary.getGeometry (i)));
49
+ }
50
+ headlands_pub_->publish (std::move (field_polygon));
50
51
}
51
- headlands_pub_->publish (std::move (field_polygon));
52
52
53
53
// Visualize field for planning (after headland removed)
54
- auto headlandless_polygon = std::make_unique<geometry_msgs::msg::PolygonStamped>();
55
- headlandless_polygon->header = header;
56
- Polygon planning_field = no_headland_field.getGeometry (0 ); // Only outer-most polygon boundary
57
- for (unsigned int i = 0 ; i != planning_field.size (); i++) {
58
- headlandless_polygon->polygon .points .push_back (util::toMsg (planning_field.getGeometry (i)));
54
+ if (planning_field_pub_->get_subscription_count () > 0 ) {
55
+ auto headlandless_polygon = std::make_unique<geometry_msgs::msg::PolygonStamped>();
56
+ headlandless_polygon->header = header;
57
+ Polygon planning_field = no_headland_field.getGeometry (0 ); // Only outer-most polygon boundary
58
+ for (unsigned int i = 0 ; i != planning_field.size (); i++) {
59
+ headlandless_polygon->polygon .points .push_back (util::toMsg (planning_field.getGeometry (i)));
60
+ }
61
+ planning_field_pub_->publish (std::move (headlandless_polygon));
59
62
}
60
- planning_field_pub_->publish (std::move (headlandless_polygon));
61
63
62
64
// Visualize swaths alone
63
- auto output_swaths = std::make_unique<visualization_msgs::msg::Marker>();
64
- output_swaths->header = header;
65
- output_swaths->action = visualization_msgs::msg::Marker::ADD;
66
- output_swaths->type = visualization_msgs::msg::Marker::LINE_LIST;
67
- output_swaths->pose .orientation .w = 1.0 ;
68
- output_swaths->scale .x = 0.3 ;
69
- output_swaths->scale .y = 0.3 ;
70
- output_swaths->scale .z = 0.3 ;
71
- output_swaths->color .b = 1.0 ;
72
- output_swaths->color .a = 1.0 ;
65
+ if (swaths_pub_->get_subscription_count () > 0 ) {
66
+ auto output_swaths = std::make_unique<visualization_msgs::msg::Marker>();
67
+ output_swaths->header = header;
68
+ output_swaths->action = visualization_msgs::msg::Marker::ADD;
69
+ output_swaths->type = visualization_msgs::msg::Marker::LINE_LIST;
70
+ output_swaths->pose .orientation .w = 1.0 ;
71
+ output_swaths->scale .x = 0.3 ;
72
+ output_swaths->scale .y = 0.3 ;
73
+ output_swaths->scale .z = 0.3 ;
74
+ output_swaths->color .b = 1.0 ;
75
+ output_swaths->color .a = 1.0 ;
73
76
74
- for (unsigned int i = 0 ; i != result->coverage_path .swaths .size (); i++) {
75
- auto & swath = result->coverage_path .swaths [i];
76
- output_swaths->points .push_back (util::pointToPoint32 (swath.start ));
77
- output_swaths->points .push_back (util::pointToPoint32 (swath.end ));
78
- }
77
+ for (unsigned int i = 0 ; i != result->coverage_path .swaths .size (); i++) {
78
+ auto & swath = result->coverage_path .swaths [i];
79
+ output_swaths->points .push_back (util::pointToPoint32 (swath.start ));
80
+ output_swaths->points .push_back (util::pointToPoint32 (swath.end ));
81
+ }
79
82
80
- swaths_pub_->publish (std::move (output_swaths));
83
+ swaths_pub_->publish (std::move (output_swaths));
84
+ }
81
85
}
82
86
83
87
} // namespace nav2_coverage
0 commit comments