-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get_Data_amcl.py
155 lines (120 loc) · 3.92 KB
/
Get_Data_amcl.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# !/usr/bin/env python
from cmath import pi
from numpy import array
import numpy as np
import rospy
import math
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped
from geometry_msgs.msg import Point
from geometry_msgs.msg import Quaternion
#class Array:
global vetor
list_prev=[]
list_new=[]
amcl_list_prev=[]
amcl_list_new=[]
pose=[]
dist=[]
def quaternion_to_euler(z, w):
t3=+2.0*(w*z)
t4=+1.0-2.0*(z**2)
yaw_rad=math.atan2(t3, t4) #radians
yaw_deg=yaw_rad*180/pi
return yaw_deg
def callback(msg):
x=msg.pose.pose.position.x
y=msg.pose.pose.position.y
z=msg.pose.pose.orientation.z
w=msg.pose.pose.orientation.w
global vetor
vetor=[x, y, z, w]
list_new.clear()
list_new.append(x)
list_new.append(y)
list_new.append(z)
list_new.append(w)
#print("callback")
#print(" ")
def callback2(data):
vetor =[
(data.ranges[46]),
(data.ranges[74]),
(data.ranges[103]),
(data.ranges[131]),
(data.ranges[160]),
(data.ranges[188]),
(data.ranges[217]),
(data.ranges[245]),
(data.ranges[274]),
(data.ranges[302]),
(data.ranges[330]),
(data.ranges[359]),
(data.ranges[387]),
(data.ranges[416]),
(data.ranges[444]),
(data.ranges[473]),
(data.ranges[501]),
(data.ranges[530]),
(data.ranges[558]),
(data.ranges[586]),
(data.ranges[615]),
(data.ranges[643]),
(data.ranges[672]),
(data.ranges[700])]
dist.clear()
dist.append(vetor)
#print("callback2")
#print(" ")
def callback3(msg):
x=msg.pose.pose.position.x
y=msg.pose.pose.position.y
z=msg.pose.pose.orientation.z
w=msg.pose.pose.orientation.w
global amcl_vetor
amcl_vetor=[x, y, z, w]
amcl_list_new.clear()
amcl_list_new.append(x)
amcl_list_new.append(y)
amcl_list_new.append(z)
amcl_list_new.append(w)
#print("callback3")
#print(" ")
def get_data():
amcl_pose_x = amcl_pose_y = pose_x = pose_y = delta_theta=0
amcl_x0 = amcl_y0 = x0 = y0 = amcl_theta0 = theta0 = 0
rospy.init_node('listener_new1', anonymous=True)
r = rospy.Rate(1) # leituras por segundo
while not rospy.is_shutdown():
rospy.Subscriber("pose", Odometry, callback)
rospy.Subscriber("scan", LaserScan, callback2)
rospy.Subscriber("amcl_pose", PoseWithCovarianceStamped, callback3)
if list_new:
if list_prev:
x0 = list_new[0]
y0 = list_new[1]
theta0 = quaternion_to_euler(list_new[2],list_new[3])
delta_theta = quaternion_to_euler(list_new[2],list_new[3]) - quaternion_to_euler(list_prev[2],list_prev[3])
pose_x = list_new[0]-list_prev[0]
pose_y = list_new[1]-list_prev[1]
list_prev.clear()
for x in range(0,4):
list_prev.append(list_new[x])
deltaD = math.sqrt((pose_x**2)+(pose_y**2))
if amcl_list_new:
if amcl_list_prev:
amcl_x0 = amcl_list_new[0]
amcl_y0 = amcl_list_new[1]
amcl_theta0 = quaternion_to_euler(amcl_list_new[2],amcl_list_new[3])
amcl_delta_theta = quaternion_to_euler(amcl_list_new[2],amcl_list_new[3]) - quaternion_to_euler(amcl_list_prev[2],amcl_list_prev[3])
amcl_pose_x = amcl_list_new[0]-amcl_list_prev[0]
amcl_pose_y = amcl_list_new[1]-amcl_list_prev[1]
amcl_list_prev.clear()
for x in range(0,4):
amcl_list_prev.append(amcl_list_new[x])
amcl_deltaD = math.sqrt((amcl_pose_x**2)+(amcl_pose_y**2))
r.sleep()
#return x0, y0, theta0, deltaD, delta_theta, dist, amcl_x0, amcl_y0, amcl_theta0, amcl_deltaD, amcl_delta_theta
if __name__ == '__main__':
get_data()