-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
173 lines (106 loc) · 2.86 KB
/
scan.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
import rospy
from miro_constants import miro
import time
#Miro
import miro_msgs
from miro_msgs.msg import platform_config,platform_sensors,platform_state,platform_mics,platform_control,core_state,core_control,core_config,bridge_config,bridge_stream
import math
import numpy
#import time
import sys
from miro_constants import miro
from datetime import datetime
from geometry_msgs.msg import (
PoseStamped,
Pose,
Point,
Quaternion,
)
#to do
# change the config file
# find neck state/control and tune angle max/min
# check Compute_x
#Initialise global variable
sonar_value=0.8
yaw_angle=0.0
safety=0.15 #15 cm
Angle_max_right= -1.0
Angle_max_left= 1.0
def Compute_x(a,b,d):
b=(2*a*b)/(a**2+1)
c=(b**2-d**2)/(a**2+1)
delta=b**2-4*c
if(delta<0):
return 0 #error
elif(delta==0):
return -1*b/(2*a)
elif(a>=0):
return (-1*b+math.sqrt(delta))/(2*a)
else:
return (-1*b-math.sqrt(delta))/(2*a)
#-----------------------Callback functions---------------------------------
def listenerMiro():
def callbackss(data):
global sonar_value,yaw_angle
sonar_value= data.sonar_range.range
yaw_angle= data.joint_state.position[2]
rospy.Subscriber('/miro/rob01/platform/sensors', platform_sensors, callbackss)
def MiroScan():
rate = rospy.Rate(100)
global sonar_value,yaw_angle
#-------------------------------------------------------
# Publishers
#Neck joints
pub_control_neck = rospy.Publisher("/miro/rob01/platform/control",platform_control)
#-------------------------------------------------------
q = platform_control()
q.body_config_speed = [0, 0,-1,0]
#Taking the distance to the obstacle
d=sonar_value
theta_r=Angle_max_right
theta_l=Angle_max_left
i=0
while(yaw_angle>=Angle_max_right):
q.body_config = [0, 0, -3.14, 0]
pub_control_neck.publish(q)
rate.sleep()
#turn head back to middle
while(yaw_angle<-0.08):
q.body_config = [0, 0, 0, 0]
pub_control_neck.publish(q)
rate.sleep()
#do nothing
i=0
while(yaw_angle<=Angle_max_left):
q.body_config = [0, 0, 3.14, 0]
pub_control_neck.publish(q)
#To be sure it's not just a false value of the sonar we will need 3 values of 0.0
rate.sleep()
#turn head back to middle
while(yaw_angle>0.08):
q.body_config = [0, 0, 0, 0]
pub_control_neck.publish(q)
rate.sleep()
rospy.set_param("state_avoid",True)
rospy.set_param("state_scan",False)
def loop ():
i=0
while not rospy.is_shutdown():
listenerMiro()
name_param = rospy.search_param('state_scan')
if(rospy.get_param(name_param)):
print i
i+=1
MiroScan()
def init():
# report
rospy.loginfo("test")
print("initialising...")
print(sys.version)
print(datetime.time(datetime.now()))
rospy.init_node('scan', anonymous=True)
if __name__ == "__main__":
rospy.loginfo("test")
init()
loop()