@@ -11,7 +11,7 @@ HydroacousticCenteringTwistActionServer::HydroacousticCenteringTwistActionServer
1111void HydroacousticCenteringTwistActionServer::bboxArrayCallback (const stingray_interfaces::msg::BboxArray &msg) {
1212 bool found_target = false ;
1313 for (auto bbox : msg.bboxes ) {
14- if (bbox.name == target_bbox_name && abs (bbox.horizontal_angle ) < target_angle_threshold && abs (bbox.horizontal_angle ) < abs (current_target_bbox.horizontal_angle )) {
14+ if (bbox.name == target_bbox_name) { // } && abs(bbox.horizontal_angle) < target_angle_threshold && abs(bbox.horizontal_angle) < abs(current_target_bbox.horizontal_angle)) {
1515 current_target_bbox = bbox;
1616 found_target = true ;
1717 target_disappeared_counter = 0 ;
@@ -61,13 +61,6 @@ void HydroacousticCenteringTwistActionServer::execute(const std::shared_ptr<rclc
6161 auto goal_result = std::make_shared<sauvc_interfaces::action::HydroacousticCenteringTwistAction::Result>();
6262 goal_result->success = false ;
6363
64- bboxArraySub = _node->create_subscription <stingray_interfaces::msg::BboxArray>(
65- goal->bbox_topic , 10 ,
66- std::bind (&HydroacousticCenteringTwistActionServer::bboxArrayCallback, this , std::placeholders::_1));
67-
68- angleHydroacousticSub = _node->create_subscription <std_msgs::msg::Float32>(goal->hydroacoustic_topic , 10 ,
69- std::bind (&HydroacousticCenteringTwistActionServer::hydroacousticCallback, this , std::placeholders::_1));
70-
7164 // check duration
7265 if (goal->duration < 0.0 ) {
7366 goal_result->success = false ;
@@ -76,6 +69,13 @@ void HydroacousticCenteringTwistActionServer::execute(const std::shared_ptr<rclc
7669 return ;
7770 }
7871
72+ bboxArraySub = _node->create_subscription <stingray_interfaces::msg::BboxArray>(
73+ goal->bbox_topic , 10 ,
74+ std::bind (&HydroacousticCenteringTwistActionServer::bboxArrayCallback, this , std::placeholders::_1));
75+
76+ angleHydroacousticSub = _node->create_subscription <std_msgs::msg::Float32>(goal->hydroacoustic_topic , 10 ,
77+ std::bind (&HydroacousticCenteringTwistActionServer::hydroacousticCallback, this , std::placeholders::_1));
78+
7979 // send service request
8080 target_bbox_name = goal->bbox_name ;
8181 target_distance_threshold = goal->distance_threshold ;
@@ -102,18 +102,34 @@ void HydroacousticCenteringTwistActionServer::execute(const std::shared_ptr<rclc
102102
103103 if (isTwistDone (goal) && isCenteringTwistDone ()) {
104104 RCLCPP_INFO (_node->get_logger (), " Twist done, target distance: %f, closer than: %f" , current_target_bbox.pos_z , target_distance_threshold);
105+ twistSrvRequest->surge = 0 ;
106+ // break;
107+ }
108+
109+ if (isTwistDone (goal) && isCenteringTwistDone () && abs (current_uv_state.yaw - twistSrvRequest->yaw ) < goal->angle_threshold ) {
110+ RCLCPP_INFO (_node->get_logger (), " Centering done, current yaw: %f, pinger agnle: %f" , current_uv_state.yaw , current_hydroacoustic_angle);
111+ twistSrvRequest->surge = 0 ;
105112 break ;
106113 }
107- twistSrvRequest->yaw = current_hydroacoustic_angle;
114+
115+ twistSrvRequest->yaw = current_uv_state.yaw + current_hydroacoustic_angle;
108116 RCLCPP_INFO (_node->get_logger (), " Twist action current yaw: %f, request diff: %f, surge: %f" , current_uv_state.yaw , twistSrvRequest->yaw , twistSrvRequest->surge );
117+ RCLCPP_INFO (_node->get_logger (), " Pure current_hydroacoustic_angle: %f" , current_hydroacoustic_angle);
109118 // check if service success
110119 twistSrvClient->async_send_request (twistSrvRequest).wait ();
111- twistSrvRequest->yaw = 0.0 ;
120+ // twistSrvRequest->yaw = 0.0;
112121
113122 if (goal_handle->is_canceling ()) {
114123 goal_result->success = false ;
115124 RCLCPP_INFO (_node->get_logger (), " Goal canceled" );
116125 goal_handle->canceled (goal_result);
126+
127+ target_disappeared_counter = 0 ;
128+ target_bbox_name = " " ;
129+ angleHydroacousticSub.reset ();
130+ bboxArraySub.reset ();
131+ // stop maneuvr service request
132+ stopTwist (twistSrvRequest);
117133 return ;
118134 }
119135 // rclcpp::spin_some(_node);
0 commit comments