-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·105 lines (86 loc) · 3.08 KB
/
main.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
#!/usr/bin/env python
import rospy
import sys
from std_msgs.msg import String
from carry_food.msg import PositionValues
import time
class CarryFood():
def __init__(self):
#movement
self.move_pub = rospy.Publisher('/move_stop', PositionValues, queue_size = 1) #to /move
self.camera_sub = rospy.Subscriber('/RLDict', PositionValues, self.control_movement) #from /Camera
self.stop = 0 #move stop counter
self.move_permission = 0 #move permission 0 = False, 1 = True
self.move_turn = 0 #turn 180 angul
#audio
self.audio_pub = rospy.Publisher('/audio_start', String, queue_size = 1, latch = True) #to /audio
self.audio_sub = rospy.Subscriber('/audio_finish', String, self.control_audio) #from /audio
self.audio_finish = 0 #0 = False, 1 = True
def control_audio(self, message):
if message.data == "ryo": #audio accept
self.audio_pub.publish("wait")
if message.data == "ok":
self.audio_finish = 1
return 0
def control_movement(self, message):
if self.move_permission == 0:
return 0
if self.move_turn == 1: #turn 180 angul
message.up_down = 180
self.move_pub.publish(message)
self.move_turn = 0
self.move_permission = 0
return 0
self.move_pub.publish(message)
if message.far_near == 2: #good distance
self.stop += 1
else:
self.stop = 0
if self.stop == 10 *2: #keeped 2 minutes
self.move_permission = 0
return 0
def main(self):
rate = rospy.Rate(10)
time.sleep(3)
#audio start listening to the word, "carry food"
self.audio_finish = 0
self.audio_pub.publish("carry")
while self.audio_finish == 0:
rate.sleep()
self.audio_finish = 0
#turn_180
self.move_turn = 1
self.move_permission = 1
while True:
topic = rospy.wait_for_message('/turn_finish', String)
if topic.data == "finish":
break
#move to the person who ordered
self.move_permission = 1
self.move_stop = 0
while self.move_permission == 1:
rate.sleep()
#audio start listening to the word, "i received the food"
self.audio_finish = 0
self.audio_pub.publish("stand-by")
while self.audio_finish == 0:
rate.sleep()
self.audio_finish = 0
#turn_180
self.turn_finish = 0
self.move_turn = 1
self.move_permission = 1
while True:
topic = rospy.wait_for_message('/turn_finish', String)
if topic.data == "finish":
break
#move to the original person
self.move_permission = 1
self.move_stop = 0
while self.move_permission == 1:
rate.sleep()
sys.exit()
if __name__ == '__main__':
rospy.init_node("main")
carry_food = CarryFood()
carry_food.main()