diff --git a/src/openarm_camera/openarm_camera/stereo_hand_depth_node.py b/src/openarm_camera/openarm_camera/stereo_hand_depth_node.py index 271f1a0..004a3d5 100644 --- a/src/openarm_camera/openarm_camera/stereo_hand_depth_node.py +++ b/src/openarm_camera/openarm_camera/stereo_hand_depth_node.py @@ -279,13 +279,23 @@ class StereoHandDepthNode(Node): # msg_out.pose.position.y = float(X) # msg_out.pose.position.z = -float(Y) # self.get_logger().info(f"X:{X:.3f}, Y:{Y:.3f}, Z:{Z:.3f}") - msg_out.pose.orientation.x = float(self.target_quat[0]) - msg_out.pose.orientation.y = float(self.target_quat[1]) - msg_out.pose.orientation.z = float(self.target_quat[2]) - msg_out.pose.orientation.w = float(self.target_quat[3]) - msg_out.pose.position.x = float(self.target_pos[0]) - msg_out.pose.position.y = float(self.target_pos[1]) - msg_out.pose.position.z = float(self.target_pos[2]) + # 对位置和姿态做简单平滑(滑动平均) + alpha = 0.2 # 平滑系数,0.0-1.0,越小越平滑 + if not hasattr(self, 'smoothed_pos'): + self.smoothed_pos = self.target_pos.copy() + self.smoothed_quat = self.target_quat.copy() + else: + self.smoothed_pos = alpha * self.target_pos + (1 - alpha) * self.smoothed_pos + self.smoothed_quat = alpha * self.target_quat + (1 - alpha) * self.smoothed_quat + self.smoothed_quat = self.smoothed_quat / np.linalg.norm(self.smoothed_quat) # 归一化 + + msg_out.pose.orientation.x = float(self.smoothed_quat[0]) + msg_out.pose.orientation.y = float(self.smoothed_quat[1]) + msg_out.pose.orientation.z = float(self.smoothed_quat[2]) + msg_out.pose.orientation.w = float(self.smoothed_quat[3]) + msg_out.pose.position.x = float(self.smoothed_pos[0]) + msg_out.pose.position.y = float(self.smoothed_pos[1]) + msg_out.pose.position.z = float(self.smoothed_pos[2]) self.pub.publish(msg_out) # ----------- 可视化(调试用)-----------