Skip to content

Commit 394410d

Browse files
committed
migrate coverage_navigator
1 parent f1766e1 commit 394410d

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

opennav_coverage_msgs/action/NavigateCompleteCoverage.action

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ string behavior_tree
1616
uint16 NONE=0
1717
uint16 UNKNOWN=800
1818
uint16 FAILED_TO_LOAD_BEHAVIOR_TREE=801
19+
uint16 TF_ERROR=802
1920

2021
uint16 error_code
2122
string error_msg

opennav_coverage_navigator/include/opennav_coverage_navigator/coverage_navigator.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ class CoverageNavigator
111111
/**
112112
* @brief Goal pose initialization on the blackboard
113113
* @param goal Action template's goal message to process
114+
* @return bool if goal was initialized successfully to be processed
114115
*/
115-
void initializeGoalPose(ActionT::Goal::ConstSharedPtr goal);
116+
bool initializeGoalPose(ActionT::Goal::ConstSharedPtr goal);
116117

117118
rclcpp::Time start_time_;
118119
std::string path_blackboard_id_, field_blackboard_id_, polygon_blackboard_id_;

opennav_coverage_navigator/src/coverage_navigator.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ CoverageNavigator::configure(
5151

5252
// Odometry smoother object for getting current speed
5353
odom_smoother_ = odom_smoother;
54+
55+
// Groot monitoring
56+
if (!node->has_parameter(getName() + ".enable_groot_monitoring")) {
57+
node->declare_parameter(getName() + ".enable_groot_monitoring", false);
58+
}
59+
60+
if (!node->has_parameter(getName() + ".groot_server_port")) {
61+
node->declare_parameter(getName() + ".groot_server_port", 1667);
62+
}
63+
64+
bt_action_server_->setGrootMonitoring(
65+
node->get_parameter(getName() + ".enable_groot_monitoring").as_bool(),
66+
node->get_parameter(getName() + ".groot_server_port").as_int());
67+
5468
return true;
5569
}
5670

@@ -90,11 +104,12 @@ CoverageNavigator::goalReceived(ActionT::Goal::ConstSharedPtr goal)
90104
RCLCPP_ERROR(
91105
logger_, "BT file not found: %s. Navigation canceled.",
92106
bt_xml_filename.c_str());
107+
bt_action_server_->setInternalError(ActionT::Result::FAILED_TO_LOAD_BEHAVIOR_TREE,
108+
std::string("Error loading XML file: ") + bt_xml_filename + ". Navigation canceled.");
93109
return false;
94110
}
95111

96-
initializeGoalPose(goal);
97-
return true;
112+
return initializeGoalPose(goal);
98113
}
99114

100115
void
@@ -185,7 +200,13 @@ CoverageNavigator::onPreempt(ActionT::Goal::ConstSharedPtr goal)
185200
// if pending goal requests the same BT as the current goal, accept the pending goal
186201
// if pending goal has an empty behavior_tree field, it requests the default BT file
187202
// accept the pending goal if the current goal is running the default BT file
188-
initializeGoalPose(bt_action_server_->acceptPendingGoal());
203+
if (!initializeGoalPose(bt_action_server_->acceptPendingGoal())) {
204+
RCLCPP_WARN(
205+
logger_,
206+
"Preemption request was rejected since the goal could not be "
207+
"initialized. For now, continuing to track the last goal until completion.");
208+
bt_action_server_->terminatePendingGoal();
209+
}
189210
} else {
190211
RCLCPP_WARN(
191212
logger_,
@@ -198,14 +219,19 @@ CoverageNavigator::onPreempt(ActionT::Goal::ConstSharedPtr goal)
198219
}
199220
}
200221

201-
void
222+
bool
202223
CoverageNavigator::initializeGoalPose(ActionT::Goal::ConstSharedPtr goal)
203224
{
204225
geometry_msgs::msg::PoseStamped current_pose;
205-
nav2_util::getCurrentPose(
206-
current_pose, *feedback_utils_.tf,
207-
feedback_utils_.global_frame, feedback_utils_.robot_frame,
208-
feedback_utils_.transform_tolerance);
226+
if (!nav2_util::getCurrentPose(
227+
current_pose, *feedback_utils_.tf,
228+
feedback_utils_.global_frame, feedback_utils_.robot_frame,
229+
feedback_utils_.transform_tolerance))
230+
{
231+
bt_action_server_->setInternalError(ActionT::Result::TF_ERROR,
232+
"Initial robot pose is not available.");
233+
return false;
234+
}
209235

210236
if (goal->field_filepath.size() == 0) {
211237
RCLCPP_INFO(
@@ -227,6 +253,8 @@ CoverageNavigator::initializeGoalPose(ActionT::Goal::ConstSharedPtr goal)
227253
blackboard->set<std::vector<geometry_msgs::msg::Polygon>>(
228254
polygon_blackboard_id_, goal->polygons);
229255
blackboard->set<std::string>(polygon_frame_blackboard_id_, goal->frame_id);
256+
257+
return true;
230258
}
231259

232260
} // namespace opennav_coverage_navigator

0 commit comments

Comments
 (0)