@@ -27,11 +27,35 @@ rclcpp_action::Client<NavigateToPose>::SharedPtr navigation_client_;
27
27
28
28
void NaviWaypointCB (const std_msgs::msg::String::SharedPtr msg)
29
29
{
30
+ RCLCPP_INFO (node->get_logger (), " [NaviWaypointCB] 目标航点= %s" ,msg->data .c_str ());
30
31
waypoint_name = msg->data ;
31
32
32
33
bNewCmd = true ;
33
34
}
34
35
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
+
35
59
int main (int argc, char ** argv)
36
60
{
37
61
rclcpp::init (argc, argv);
@@ -101,7 +125,6 @@ int main(int argc, char** argv)
101
125
break ;
102
126
RCLCPP_INFO (node->get_logger (), " Waiting for the move_base action server to come up" );
103
127
}
104
-
105
128
106
129
// Create the navigation goal request
107
130
auto goal_msg = NavigateToPose::Goal ();
@@ -112,21 +135,22 @@ int main(int argc, char** argv)
112
135
113
136
// Send the navigation goal request
114
137
auto send_goal_options = rclcpp_action::Client<NavigateToPose>::SendGoalOptions ();
138
+ send_goal_options.result_callback = std::bind (&resultCallback, std::placeholders::_1);
115
139
auto goal_handle_future = navigation_client_->async_send_goal (goal_msg, send_goal_options);
116
140
117
141
// 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);
130
154
bNewCmd = false ;
131
155
}
132
156
0 commit comments