-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorientation_node.py
92 lines (77 loc) · 3.01 KB
/
orientation_node.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
import particle_class
import numpy as np
import rospy
import tf
from pyquaternion import Quaternion
from geometry_msgs.msg import PoseStamped, PoseArray
from apriltag_ros.msg import AprilTagDetectionArray
from apriltag_ros.msg import AprilTagDetection
from tf.transformations import rotation_matrix, euler_from_quaternion
NUM_P = 100
PART_DIM = 3 # x, y, z
x_range = (0, 5)
y_range = (0, 5)
z_range = (0, 5)
# cov_mat = 1.5
cov_mat = 0.015
tags = np.array(([[14, 0, 0, 0],
[15, 0.7, 0, 0],
[16, 0, 0.6, 0],
[17, 0.9, 0.6, 0]]))
qx_180 = Quaternion(axis=[1, 0, 0], angle=np.pi)
qz_90n = Quaternion(axis=[0, 0, 1], angle=-np.pi / 2)
dreh=qx_180*qz_90n
for i in range(tags.shape[0]):
pass
rviz = True
def callback(msg, list):
""""""
[publisher_position, publisher_particles, broadcaster] = list
# get length of message
num_meas = len(msg.detections)
yaw_array = np.zeros(num_meas)
# if new measurement: update particles
if num_meas >= 1:
# get data from topic /tag_detection
for i, tag in enumerate(msg.detections):
tag_id = int(tag.id[0])
distance = Quaternion(w=tag.pose.pose.pose.orientation.w, x=tag.pose.pose.pose.orientation.x,
y=tag.pose.pose.pose.orientation.y, z=tag.pose.pose.pose.orientation.z)
distance=distance
# distance = Quaternion.random()
print(np.asarray(distance.yaw_pitch_roll)*180/np.pi)
# print(euler_from_quaternion([distance.x,distance.y]))
# print(index)
#print(yaw_array*180/np.pi)
# print "reale messungen: " + str(measurements)
# calculate position as mean of particle positions
# publish estimated_pose
position = PoseStamped()
position.header.stamp = rospy.Time.now()
position.header.frame_id = "camera_rect"
position.pose.orientation.x = 0
position.pose.orientation.y = 0
position.pose.orientation.z = 0
position.pose.orientation.w = 0
publisher_position.publish(position)
"""
# publish transform
broadcaster.sendTransform((estimated_position[0], estimated_position[1], estimated_position[2]),
(1.0, 0, 0, 0),
rospy.Time.now(),
"TestPose",
"world")
"""
def main():
rospy.init_node('particle_filter_node')
# particle_filter = particle_class.ParticleFilter(NUM_P, PART_DIM, x_range, y_range, z_range, cov_mat)
publisher_orientation = rospy.Publisher('estimated_orientation', PoseStamped, queue_size=1)
publisher_particles = rospy.Publisher('particle_orientation', PoseArray, queue_size=1)
broadcaster = tf.TransformBroadcaster()
rospy.Subscriber("/tag_detections", AprilTagDetectionArray, callback,
[publisher_orientation, publisher_particles, broadcaster], queue_size=1)
while not rospy.is_shutdown():
pass
if __name__ == '__main__':
main()