-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatemachine_TK.py
162 lines (108 loc) · 4.02 KB
/
statemachine_TK.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
#!/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
pub_takeoff= rospy.Publisher('/bebop/takeoff',Empty,queue_size=1)
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!")
# print('Taking off') #i think the node was too speedy or something, ignore this takeoff mess its just a hack for testing
# pub_takeoff.publish()
# print('huh?')
# time.sleep(5.)
# print('Taking off try 2')
# pub_takeoff.publish()
# print('huh?')
# time.sleep(5.)
time.sleep(8)
# #### Move 3, Yaw right (-ve)
command.x = 0
command.y = 0
command.z = 0
command.w = -45 # Yaw Command, positive left
# # SEND IT
print('sending yaw command, Yaw towards the bridge: ',command)
command_pub.publish(command)
# wait for it
time.sleep(4)
print("STARTING BRIDGE SCRIPT")
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/Bridge.py")
print("CROSSED BRIDGE SUCCESSFULLY! \n STAGE 3 COMPLETE!")
time.sleep(3)
# #### Move 3, Yaw right (-ve)
command.x = 0
command.y = -1
command.z = -.5
command.w = 0 # Yaw Command, positive left
# # SEND IT
print('sending transition command, move towards the target: ',command)
command_pub.publish(command)
# wait for it
time.sleep(5)
# print("FINISHED YAWING NOW!")
# time.sleep(4.)
# pub_takeoff.publish()
# time.sleep(4.)
runscript("/home/qdmc/bebop_ws/src/dqmc/scripts/circles_detect_ros.py")
print("STAGE 4 COMPLETE")
# time.sleep(5.)
# command.w = 0
# command.x = 0
# command.y = 0
# command.z = 0
# command_pub.publish(command)
time.sleep(3.)
pub_takeoff.publish()
time.sleep(3.)
# ### 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_ros_no_yaw.py")
print("STAGE 6 COMPLETE")
# 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()