10 from marker_msgs.msg
import MarkerDetection
11 from geometry_msgs.msg
import PoseStamped
14 return (position.x, position.y, position.z)
17 return (orientation.x, orientation.y, orientation.z, orientation.w)
22 self.
input = rospy.get_param(
'~input')
24 self.
odom = rospy.get_param(
'~frame_id_odom',
'odom')
31 rospy.Subscriber(
'markers', MarkerDetection, self.
cb_marker)
34 with open(self.
input,
'r') as f: 36 if line ==
'id;x;y;z;roll;pitch;yaw\n':
41 raise ValueError(
'Not a valid line: ' + line)
45 msg.header.frame_id = rospy.resolve_name(self.
odom)[1:]
46 msg.pose.position.x = float(tmp[1]) + 0.15
47 msg.pose.position.y = float(tmp[2])
48 msg.pose.position.z = float(tmp[3]) + 0.15
49 q = tf.transformations.quaternion_from_euler(float(tmp[4]) + math.pi/2, float(tmp[5]), float(tmp[6]))
50 msg.pose.orientation.x = q[0]
51 msg.pose.orientation.y = q[1]
52 msg.pose.orientation.z = q[2]
53 msg.pose.orientation.w = q[3]
59 with open(self.
output,
'a+')
as f:
60 if os.path.getsize(self.
output) == 0:
61 f.write(
'exp_length;exp_angle;exp_orientation;length;angle;orientation\n')
63 for marker
in msg.markers:
65 predmsg = self.tf_listener.transformPose(msg.header.frame_id, self.
markers[marker.ids[0]])
68 (x_, y_, z_) = (predmsg.pose.position.x, predmsg.pose.position.y, predmsg.pose.position.z)
69 l_ = math.sqrt(x_*x_ + z_*z_)
70 a_ = math.atan2(x_, z_)
73 (roll_, pitch_, yaw_) = tf.transformations.euler_from_quaternion(
get_vector_orientation(predmsg.pose.orientation))
76 (x, y, z) = (marker.pose.position.x, marker.pose.position.y, marker.pose.position.z)
77 l = math.sqrt(x*x + z*z)
81 (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(
get_vector_orientation(marker.pose.orientation))
84 if msg.distance_min < l
and l < msg.distance_max
and -msg.fov_horizontal/2 < a
and a < msg.fov_horizontal/2:
85 f.write(
'{};{};{};{};{};{}\n'.format(l_, a_, pitch_, l, a, pitch))
87 except tf.Exception
as ex:
88 rospy.logwarn(
'[%s cb_marker] %s', rospy.get_name(), ex)
90 if __name__ ==
'__main__':
92 rospy.init_node(
'tuw_record', anonymous=
True)
def get_vector_orientation(orientation)
def get_vector_position(position)