1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| def marker_to_robot(self, pose): def pose_vector_to_matrix(pose_vec): """[X, Y, Z, Rx, Ry, Rz] -> 4x4 变换矩阵""" x, y, z, rx, ry, rz = pose_vec rotvec = np.array([rx, ry, rz]) R_mat = R.from_rotvec(rotvec).as_matrix() T = np.eye(4) T[:3, :3] = R_mat T[:3, 3] = [x, y, z] return T def matrix_to_pose_vector(T): """4x4 变换矩阵 -> [X, Y, Z, Rx, Ry, Rz]""" x, y, z = T[:3, 3] rotvec = R.from_matrix(T[:3, :3]).as_rotvec() return [x, y, z, rotvec[0], rotvec[1], rotvec[2]] T_marker_world = pose_vector_to_matrix(pose) theta2 = (314.5-90) / 360 * 2 * np.pi T = np.array([ [np.cos(theta2), 0, np.sin(theta2), 0], [-np.sin(theta2), 0, np.cos(theta2), 0], [0, -1, 0, 0.2], [0, 0, 0, 1] ]) T_move = np.array([ [1, 0, 0, -0.9], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1] ]) T_marker_robot = T_move @ T @ T_marker_world return matrix_to_pose_vector(T_marker_robot) goal = oriented_xyz.get_pose_vector() goal_marker = goal goal = self.marker_to_robot(goal)
goal[-3:] = [current_pose[3], current_pose[4] , current_pose[5]]
|