@@ -117,30 +117,14 @@ void ObjectSorterBase<ObjsMsgType>::objectCallback(
117117 ObjsMsgType output_objects;
118118 output_objects.header = input_msg->header ;
119119
120- double tx;
121- double ty;
122- double cos_yaw;
123- double sin_yaw;
120+ geometry_msgs::msg::TransformStamped tf_input_frame_to_target_frame;
124121 // Even when it failed to get the transform, we still can do the velocity check
125122 bool transform_success = false ;
126123 try {
127- const geometry_msgs::msg::TransformStamped tf_input_frame_to_target_frame =
128- tf_buffer_.lookupTransform (
129- range_calc_frame_id_, // target frame
130- input_msg->header .frame_id , // source frame
131- input_msg->header .stamp , rclcpp::Duration::from_seconds (0.5 ));
132-
133- // Extract translation
134- tx = tf_input_frame_to_target_frame.transform .translation .x ;
135- ty = tf_input_frame_to_target_frame.transform .translation .y ;
136-
137- // Extract yaw from quaternion
138- const geometry_msgs::msg::Quaternion & q = tf_input_frame_to_target_frame.transform .rotation ;
139- const tf2::Quaternion tf_q (q.x , q.y , q.z , q.w );
140- const double yaw = tf2::getYaw (tf_q);
141-
142- cos_yaw = std::cos (yaw);
143- sin_yaw = std::sin (yaw);
124+ tf_input_frame_to_target_frame = tf_buffer_.lookupTransform (
125+ range_calc_frame_id_, // target frame
126+ input_msg->header .frame_id , // source frame
127+ input_msg->header .stamp , rclcpp::Duration::from_seconds (0.5 ));
144128
145129 transform_success = true ;
146130 } catch (tf2::TransformException & ex) {
@@ -161,14 +145,14 @@ void ObjectSorterBase<ObjsMsgType>::objectCallback(
161145 }
162146
163147 if (transform_success) {
164- // We will check the condition in 2D (x-y)
165- const double object_x = object.kinematics .pose_with_covariance .pose .position .x ;
166- const double object_y = object.kinematics .pose_with_covariance .pose .position .y ;
167- const double object_x_in_target_frame = object_x * cos_yaw - object_y * sin_yaw + tx;
168- const double object_y_in_target_frame = object_x * sin_yaw + object_y * cos_yaw + ty;
148+ geometry_msgs::msg::PointStamped object_point;
149+ object_point.point = object.kinematics .pose_with_covariance .pose .position ;
150+ geometry_msgs::msg::PointStamped object_point_transformed;
151+ tf2::doTransform (object_point, object_point_transformed, tf_input_frame_to_target_frame);
169152
170- const double object_diff_x = object_x_in_target_frame - range_calc_offset_x_;
171- const double object_diff_y = object_y_in_target_frame - range_calc_offset_y_;
153+ // We will check the condition in 2D (x-y)
154+ const double object_diff_x = object_point_transformed.point .x - range_calc_offset_x_;
155+ const double object_diff_y = object_point_transformed.point .y - range_calc_offset_y_;
172156
173157 if (!label_settings.isInTargetRange (object_diff_x, object_diff_y)) {
174158 continue ;
0 commit comments