-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatemachine.py
More file actions
191 lines (138 loc) · 4.75 KB
/
statemachine.py
File metadata and controls
191 lines (138 loc) · 4.75 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env python
import rospy
import roslaunch
import time
import os
import subprocess
import numpy as np
from geometry_msgs.msg import Quaternion
from std_msgs.msg import Empty
# from bondpy import bondpy
############################################## STATE MACHINE ######################################################
# def init():
# ## Initialize all the inputs required. (Cameras and Odom)
# uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
# roslaunch.configure_logging(uuid)
# # Bebop and both cameras
# cli_args1 = ['bebop_driver', 'bebop_node.launch']
# cli_args2 = ['dqmc', 'justcamera.launch']
# battery = ['dqmc', 'batterycheck.launch']
# # roslaunch_file1 = roslaunch.rlutil.resolve_launch_arguments(cli_args1)
# # roslaunch_args1 = cli_args1[2:]
# roslaunch_file1 = roslaunch.rlutil.resolve_launch_arguments(cli_args1)
# roslaunch_file2 = roslaunch.rlutil.resolve_launch_arguments(cli_args2)
# roslaunch_file3 = roslaunch.rlutil.resolve_launch_arguments(battery)
# launch_files = [roslaunch_file1, roslaunch_file2, roslaunch_file3]
# parent = roslaunch.parent.ROSLaunchParent(uuid, launch_files)
# parent.start()
# return 0
def runscript(input_file, flag=1):
process = subprocess.Popen(input_file, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
if flag==1:
while True:
output = process.stdout.readline()
print(output)
if process.poll() is not None:
break
def main():
# runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/MoveToController.py",0)
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/Window_and_wall.py")
print(" Passed Window SUCCESSFULLY! \n Finished Stage 1 and stage 2!")
time.sleep(3)
print("STARTING BRIDGE SCRIPT")
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/Bridge.py")
print("CROSSED BRIDGE SUCCESSFULLY! \n STAGE 4 COMPLETE!")
time.sleep(2)
#### Move 3, Yaw right (-ve)
# command.x = 0
# command.y = 0
# command.z = 0
# command.w = -60 # Yaw Command, positive left
# # SEND IT
# print('sending command 3, Yaw towards the window: ',command)
# command_pub.publish(command)
# wait for it
# time.sleep(5)
# command.x = 0
# command.y = 0
# command.z = 0
# command.w = 0 # Yaw Command, positive left
# # SEND IT
# print('Yawing towards bridge: ',command)
# command_pub.publish(command)
# # wait for it
# time.sleep(3)
command.x = 0
command.y = 0
command.z = -0.6
command.w = 0 # Yaw Command, positive left
# SEND IT
print('DROP IT!: ',command)
command_pub.publish(command)
# wait for it
time.sleep(4)
# command.x = 0
# command.y = 0
# command.z = 0
# command.w = 0 # Yaw Command, positive left
# # SEND IT
# print('Yawing towards bridge: ',command)
# command_pub.publish(command)
# # wait for it
# time.sleep(2)
# command.x = 0
# command.y = 0
# command.z = 0
# command.w = -60 # Yaw Command, positive left
# # SEND IT
# print('sending command 3, Yaw towards the window: ',command)
# command_pub.publish(command)
# # wait for it
# time.sleep(4)
# command.x = 0
# command.y = 0
# command.z = 0
# command.w = 0 # Yaw Command, positive left
# # SEND IT
# print('Yawing towards bridge: ',command)
# command_pub.publish(command)
# # wait for it
# time.sleep(2)
# print("FINISHED YAWING NOW!")
# time.sleep(4.)
# pub_takeoff.publish()
# time.sleep(4.)
print("DETECTING CIRCLES NOW")
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/circles_detect_land.py")
time.sleep(3.)
command.w = 0
command.x = 0
command.y = 0
command.z = 0
command_pub.publish(command)
time.sleep(2.)
pub_takeoff.publish()
time.sleep(3.)
print("YAWING ON CIRCLE NOW")
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/circles_detect_yaw.py")
print("STAGE 4 COMPLETE")
### KILLL COMMAND! rospy.signal_shutdown('WOOOOOOOOOOOOOOOHOOOOO')
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/FindFeet_Controller_V2.py")
print("STAGE 5 COMPLETE")
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/circles_detect_land.py")
print("STAGE 6 COMPLETE")
print("YAYYYYYYYYYYYY!! FINALLY!")
# runscript("stage12.py")
# runscript("stage3.py")
# runscript("stage4.py")
# runscript("stage5.py")
# runscript("stage6.py")
return 0
if __name__ == '__main__':
rospy.init_node('ALLNODE')
pub_takeoff= rospy.Publisher('/bebop/takeoff',Empty,queue_size=1)
command_pub = rospy.Publisher('/moveto_cmd_body', Quaternion, queue_size=1)
command=Quaternion()
path = os.getcwd()
# init()
main()