-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
62 lines (47 loc) · 1.12 KB
/
server.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
#!/usr/bin/env python
import rospy
from std_msgs.msg import String,Bool
import time
import os
import subprocess
import sys
import signal
# import rospy
# import actionlib
# from move_base_msgs.msg import *
class server():
"""docstring for ser"""
def __init__(self):
rospy.init_node('server',anonymous=True)
rospy.Subscriber("start",String,self.callback,queue_size=10)
rospy.spin()
def start(self):
if(self.list[1]=='1'):
self.image = subprocess.Popen(['python',"color_image.py"])
if(self.list[2]=='1'):
self.process = subprocess.Popen(['python', "python_launch.py",'1'])
else:
self.process = subprocess.Popen(['python', "python_launch.py",'0'])
time.sleep(3)
def stop(self):
try:
self.process.send_signal(signal.SIGTERM)
self.process.wait()
if(self.list[1]):
self.image.kill()
self.image.wait()
finally:
self.process.terminate()
if(self.list[1]):
self.image.terminate()
time.sleep(1)
def callback(self,data):
self.list = []
a = data.data
self.list = a.split()
if(self.list[0]=='1'):
self.start()
else:
self.stop()
if __name__ == '__main__':
server()