-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmachNode.py
More file actions
executable file
·158 lines (115 loc) · 4.04 KB
/
smachNode.py
File metadata and controls
executable file
·158 lines (115 loc) · 4.04 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
#!/usr/bin/env python
# Required for ROS to execute file as a Python script
import rospy
from std_msgs.msg import String
class SMACHNode:
pub = None
rate = None
state = 'Initialization'
gatePassFlag = False
def __init__(self):
rospy.init_node('smachNode', anonymous=True)
self.pub = rospy.Publisher('state', String, queue_size=10)
self.rate = rospy.Rate(10) # 10hz
def initialization(self):
self.state = 'Initialization'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
# Dummy condition generator
condition = raw_input('Initialization successful? Enter Y or N')
if (condition == 'y'):
self.state = 'Gate Search'
else:
self.state = 'Debug'
def debug(self):
self.state = 'Debug'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
# Dummy condition generator
condition = raw_input('Debug complete? Enter y or n')
if (condition == 'y'):
self.state = 'Initialization'
else:
self.state = 'Debug'
def gateSearch(self):
self.state = 'Gate Search'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
# Dummy condition generator
condition = raw_input('Gate found? Enter y or n')
if (condition == 'y'):
self.state = 'Gate Navigation'
else:
self.state = 'Gate Search'
def gateNavigation(self):
self.state = 'Gate Navigation'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
# Dummy condition generator
condition = raw_input('Is the gate passed or lost? Enter p or l')
if (condition == 'p' and self.gatePassFlag == False):
self.gatePassFlag = True
self.state = 'Pole Search'
elif(condition == 'p' and self.gatePassFlag == True):
self.state = 'Breach and Shutdown'
else:
self.state = 'Gate Search'
def poleSearch(self):
self.state = 'Pole Search'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
# Dummy condition generator
condition = raw_input('Pole found? Enter y or n')
if (condition == 'y'):
self.state = 'Pole Navigation'
else:
self.state = 'Pole Search'
def poleNavigation(self):
self.state = 'Pole Navigation'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
# Dummy condition generator
condition = raw_input('Is the pole passed or lost? Enter p or l')
if (condition == 'p'):
self.state = 'Gate Search'
else:
self.state = 'Pole Search'
def breachAndShutdown(self):
self.state = 'Breach and Shutdown'
rospy.loginfo(self.state)
self.pub.publish(self.state)
self.rate.sleep()
def run(self):
while not rospy.is_shutdown():
if (self.state == 'Initialization'):
self.initialization()
elif (self.state == 'Debug'):
self.debug()
elif (self.state == 'Gate Search'):
self.gateSearch()
elif (self.state == 'Gate Navigation'):
self.gateNavigation()
elif (self.state == 'Pole Search'):
self.poleSearch()
elif (self.state == 'Pole Navigation'):
self.poleNavigation()
elif (self.state == 'Breach and Shutdown'):
self.breachAndShutdown()
break
else:
rospy.loginfo('Invalid State!')
self.pub.publish('Invalid State!')
self.rate.sleep()
break
if __name__ == '__main__':
smachNode = SMACHNode()
try:
smachNode.run()
except rospy.ROSInterruptException:
pass