7 import matplotlib.pyplot
as mplot
9 from mpl_toolkits.mplot3d
import Axes3D
10 from marker_msgs.msg
import MarkerDetection
17 self.
beta_1 = rospy.get_param(
'~beta_1')
18 self.
beta_2 = rospy.get_param(
'~beta_2')
19 self.
beta_3 = rospy.get_param(
'~beta_3')
20 self.
beta_4 = rospy.get_param(
'~beta_4')
21 self.
beta_5 = rospy.get_param(
'~beta_5')
22 self.
beta_6 = rospy.get_param(
'~beta_6')
23 self.
beta_7 = rospy.get_param(
'~beta_7')
24 self.
beta_8 = rospy.get_param(
'~beta_8')
25 self.
beta_9 = rospy.get_param(
'~beta_9')
26 self.
beta_10 = rospy.get_param(
'~beta_10')
27 self.
beta_11 = rospy.get_param(
'~beta_11')
28 self.
beta_12 = rospy.get_param(
'~beta_12')
29 self.
beta_13 = rospy.get_param(
'~beta_13')
30 self.
beta_14 = rospy.get_param(
'~beta_14')
31 self.
beta_15 = rospy.get_param(
'~beta_15')
32 self.
beta_16 = rospy.get_param(
'~beta_16')
33 self.
beta_17 = rospy.get_param(
'~beta_17')
34 self.
beta_18 = rospy.get_param(
'~beta_18')
38 self.
ax = fig.add_subplot(111, projection=
'3d')
39 self.ax.set_title(
"Detected markers")
40 self.ax.set_xlim(-8, 8,
False,
False)
41 self.ax.set_ylim(-8, 8,
False,
False)
42 self.ax.set_zlim( 0, 8,
False,
False)
45 rospy.Subscriber(
'marker', MarkerDetection, self.
cb_marker)
46 self.
pub = rospy.Publisher(
'marker_noise', MarkerDetection, queue_size=10)
57 self.ax.autoscale(
False)
58 self.ax.set_xlabel(
"X axis")
59 self.ax.set_ylabel(
"Y axis")
60 self.ax.set_zlabel(
"Z axis")
63 for marker
in noisy_data.markers:
65 p_o = (marker.pose.position.x, marker.pose.position.y, marker.pose.position.z)
66 q_o = (marker.pose.orientation.x, marker.pose.orientation.y, marker.pose.orientation.z, marker.pose.orientation.w)
69 radial = math.sqrt(p_o[0]**2 + p_o[1]**2 + p_o[2]**2)
70 polar = math.acos(p_o[2]/radial)
71 azimuthal = math.atan2(p_o[1], p_o[0])
72 (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(q_o)
75 sigma_radial = math.sqrt(max(self.
beta_1 * radial**2 + self.
beta_2, 0) + max(min(self.
beta_3 * azimuthal**2 + self.
beta_4, math.pi**2), 0) + max(min(self.
beta_5 * yaw**2 + self.
beta_6, math.pi**2), 0))
76 sigma_azimuthal = min(math.sqrt(max(self.
beta_7 / radial**2 + self.
beta_8, 0) + max(min(self.
beta_9 * azimuthal**2 + self.
beta_10, math.pi**2), 0) + max(min(self.
beta_11 * yaw**2 + self.
beta_12, math.pi**2), 0)), math.pi)
77 sigma_yaw = min(math.sqrt(max(self.
beta_13 * radial**2 + self.
beta_14, 0) + max(min(self.
beta_15 * azimuthal**2 + self.
beta_16, math.pi**2), 0) + max(min(self.
beta_17 * yaw**2 + self.
beta_18, math.pi**2), 0)), math.pi)
80 radial += numpy.random.normal(0, sigma_radial)
81 azimuthal += numpy.random.normal(0, sigma_azimuthal)
82 yaw += numpy.random.normal(0, sigma_yaw)
85 tmp = math.fabs(radial * math.sin(polar))
86 marker.pose.position.x = tmp * math.cos(azimuthal)
87 marker.pose.position.y = tmp * math.sin(azimuthal)
88 marker.pose.position.z = radial * math.cos(polar)
89 tmp = tf.transformations.quaternion_from_euler(roll, pitch, yaw)
90 marker.pose.orientation.x = tmp[0]
91 marker.pose.orientation.y = tmp[1]
92 marker.pose.orientation.z = tmp[2]
93 marker.pose.orientation.w = tmp[3]
96 p_n = (marker.pose.position.x, marker.pose.position.y, marker.pose.position.z)
97 q_n = (marker.pose.orientation.x, marker.pose.orientation.y, marker.pose.orientation.z, marker.pose.orientation.w)
101 o = numpy.array((1,1,1,1))
104 R_o = tf.transformations.quaternion_matrix(q_o)
105 R_n = tf.transformations.quaternion_matrix(q_n)
106 o_o = numpy.dot(R_o, o)
107 o_n = numpy.dot(R_n, o)
110 if len(marker.ids) > 0:
114 self.ax.text(p_o[0], p_o[1], p_o[2], id,
None)
115 self.ax.quiver(p_o[0], p_o[1], p_o[2], o_o[0], o_o[1], o_o[2])
116 self.ax.quiver(p_n[0], p_n[1], p_n[2], o_n[0], o_n[1], o_n[2])
119 self.pub.publish(noisy_data)
121 self.fig.canvas.draw()
123 if __name__ ==
'__main__':
125 rospy.init_node(
'tuw_marker_noise', anonymous=
True)
128 plot_data = rospy.get_param(
'~plot_data')
def cb_marker(self, data)