Skip to content

Commit e1d5230

Browse files
committed
change result string
1 parent a034307 commit e1d5230

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

src/wp_navi_server.cpp

+37-13
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,35 @@ rclcpp_action::Client<NavigateToPose>::SharedPtr navigation_client_;
2727

2828
void NaviWaypointCB(const std_msgs::msg::String::SharedPtr msg)
2929
{
30+
RCLCPP_INFO(node->get_logger(), "[NaviWaypointCB] 目标航点= %s",msg->data.c_str());
3031
waypoint_name = msg->data;
3132

3233
bNewCmd = true;
3334
}
3435

36+
void resultCallback(const GoalHandleNavigateToPose::WrappedResult & result)
37+
{
38+
switch (result.code) {
39+
case rclcpp_action::ResultCode::SUCCEEDED:
40+
RCLCPP_INFO(node->get_logger(), "Success!!!");
41+
result_msg.data = "navi done";
42+
break;
43+
case rclcpp_action::ResultCode::ABORTED:
44+
RCLCPP_INFO(node->get_logger(), "Goal was aborted");
45+
result_msg.data = "navi aborted";
46+
break;
47+
case rclcpp_action::ResultCode::CANCELED:
48+
RCLCPP_INFO(node->get_logger(), "Goal was canceled");
49+
result_msg.data = "navi canceled";
50+
break;
51+
default:
52+
RCLCPP_INFO(node->get_logger(), "Unknown result code");
53+
result_msg.data = "navi Unknown result";
54+
break;
55+
}
56+
result_pub->publish(result_msg);
57+
}
58+
3559
int main(int argc, char** argv)
3660
{
3761
rclcpp::init(argc, argv);
@@ -101,7 +125,6 @@ int main(int argc, char** argv)
101125
break;
102126
RCLCPP_INFO(node->get_logger(), "Waiting for the move_base action server to come up");
103127
}
104-
105128

106129
// Create the navigation goal request
107130
auto goal_msg = NavigateToPose::Goal();
@@ -112,21 +135,22 @@ int main(int argc, char** argv)
112135

113136
// Send the navigation goal request
114137
auto send_goal_options = rclcpp_action::Client<NavigateToPose>::SendGoalOptions();
138+
send_goal_options.result_callback = std::bind(&resultCallback, std::placeholders::_1);
115139
auto goal_handle_future = navigation_client_->async_send_goal(goal_msg, send_goal_options);
116140

117141
// Wait for the goal to complete
118-
if (rclcpp::spin_until_future_complete(node->get_node_base_interface(), goal_handle_future) == rclcpp::FutureReturnCode::SUCCESS)
119-
{
120-
RCLCPP_INFO(node->get_logger(), "Arrived at WayPoint !");
121-
result_msg.data = "done";
122-
}
123-
else
124-
{
125-
RCLCPP_WARN(node->get_logger(), "Failed to get to WayPoint ...");
126-
result_msg.data = "failure";
127-
}
128-
129-
result_pub->publish(result_msg);
142+
// if (rclcpp::spin_until_future_complete(node->get_node_base_interface(), goal_handle_future) == rclcpp::FutureReturnCode::SUCCESS)
143+
// {
144+
// RCLCPP_INFO(node->get_logger(), "Arrived at WayPoint !");
145+
// result_msg.data = "navi done";
146+
// }
147+
// else
148+
// {
149+
// RCLCPP_WARN(node->get_logger(), "Failed to get to WayPoint ...");
150+
// result_msg.data = "navi failure";
151+
// }
152+
153+
// result_pub->publish(result_msg);
130154
bNewCmd = false;
131155
}
132156

0 commit comments

Comments
 (0)