Revision d2dedb17
| scout/scoutsim/BehaviorGUI.py | ||
|---|---|---|
| 7 | 7 |
import subprocess |
| 8 | 8 |
import signal |
| 9 | 9 |
from collections import defaultdict |
| 10 |
|
|
| 10 | 11 |
# ROS imports |
| 11 | 12 |
import roslib; roslib.load_manifest("scoutsim")
|
| 12 | 13 |
import rospy |
| ... | ... | |
| 37 | 38 |
"Scheduler", "Warehouse", "Line Follow", "WL Test"] |
| 38 | 39 |
|
| 39 | 40 |
def SetBehavior(name, behaviorLabel, behaviorButton=False, behavior="Pause", selectedBehavior="Pause"): |
| 40 |
if behavior == "Pause":
|
|
| 41 |
if name not in processes:
|
|
| 42 |
return False
|
|
| 43 |
if not behaviorButton.GetValue():
|
|
| 44 |
processes[name] = subprocess.Popen("rosrun libscout libscout "
|
|
| 45 |
+ name + " " + str(GetBehaviors().index(selectedBehavior) + 1)
|
|
| 46 |
+ "", shell=True)
|
|
| 47 |
print "Scout " + name + " was resumed."
|
|
| 48 |
behaviorButton.SetLabel("Pause")
|
|
| 49 |
behaviorLabel.SetLabel(" | Current Behavior: " + scouts[name])
|
|
| 50 |
return True
|
|
| 41 |
if behavior == "Pause":
|
|
| 42 |
if name not in processes:
|
|
| 43 |
return False
|
|
| 44 |
if not behaviorButton.GetValue():
|
|
| 45 |
processes[name] = subprocess.Popen("rosrun libscout libscout "
|
|
| 46 |
+ name + " " + str(GetBehaviors().index(selectedBehavior) + 1)
|
|
| 47 |
+ "", shell=True)
|
|
| 48 |
print "Scout " + name + " was resumed."
|
|
| 49 |
behaviorButton.SetLabel("Pause")
|
|
| 50 |
behaviorLabel.SetLabel(" | Current Behavior: " + scouts[name])
|
|
| 51 |
return True
|
|
| 51 | 52 |
else: |
| 52 |
processes[name].terminate() |
|
| 53 |
del processes[name] |
|
| 54 |
subprocess.Popen("rosrun libscout libscout " + name + " 0", shell=True)
|
|
| 55 |
print "Scout "+name+" was paused." |
|
| 56 |
behaviorButton.SetLabel("Resume")
|
|
| 57 |
behaviorLabel.SetLabel(" | Current Behavior: Paused")
|
|
| 58 |
return True |
|
| 59 |
if name in processes: |
|
| 60 |
processes[name].terminate() |
|
| 53 |
if name in processes: |
|
| 54 |
processes[name].terminate() |
|
| 55 |
del processes[name] |
|
| 56 |
subprocess.Popen("rosrun libscout libscout " + name + " 0", shell=True)
|
|
| 57 |
print "Scout "+name+" was paused." |
|
| 58 |
behaviorButton.SetLabel("Resume")
|
|
| 59 |
behaviorLabel.SetLabel(" | Current Behavior: Paused")
|
|
| 60 |
return True |
|
| 61 |
if name in processes: |
|
| 62 |
processes[name].terminate() |
|
| 61 | 63 |
# TODO Running a new behavior while paused does not do anything and |
| 62 | 64 |
# Gives lots of errors. |
| 63 |
#
|
|
| 64 |
# -- Matt 11/30 --
|
|
| 65 |
# Might be fixed, can't run it to tell.
|
|
| 66 |
processes[name] = subprocess.Popen("rosrun libscout libscout " + name + " "
|
|
| 67 |
+ str(GetBehaviors().index(behavior) + 1) + "",
|
|
| 68 |
shell=True)
|
|
| 69 |
behaviorButton.SetValue(False)
|
|
| 70 |
behaviorButton.SetLabel("Pause")
|
|
| 71 |
print "Scout " + name + " was set to behavior: " + behavior
|
|
| 72 |
behaviorLabel.SetLabel(" | Current Behavior: " + behavior)
|
|
| 73 |
scouts[name] = behavior
|
|
| 65 |
#
|
|
| 66 |
# -- Matt 11/30 --
|
|
| 67 |
# Might be fixed, can't run it to tell.
|
|
| 68 |
processes[name] = subprocess.Popen("rosrun libscout libscout " + name + " "
|
|
| 69 |
+ str(GetBehaviors().index(behavior) + 1) + "",
|
|
| 70 |
shell=True)
|
|
| 71 |
behaviorButton.SetValue(False)
|
|
| 72 |
behaviorButton.SetLabel("Pause")
|
|
| 73 |
print "Scout " + name + " was set to behavior: " + behavior
|
|
| 74 |
behaviorLabel.SetLabel(" | Current Behavior: " + behavior)
|
|
| 75 |
scouts[name] = behavior
|
|
| 74 | 76 |
|
| 75 | 77 |
def KillScout(name): |
| 76 |
try:
|
|
| 77 |
rospy.wait_for_service('/kill')
|
|
| 78 |
service = rospy.ServiceProxy('/kill', Kill)
|
|
| 79 |
if name in processes:
|
|
| 80 |
processes[name].kill()
|
|
| 81 |
del processes[name]
|
|
| 82 |
resp = service(name)
|
|
| 83 |
if name in scouts:
|
|
| 84 |
del scouts[name]
|
|
| 85 |
return True
|
|
| 86 |
except rospy.ServiceException, e:
|
|
| 87 |
return False
|
|
| 78 |
try:
|
|
| 79 |
rospy.wait_for_service('/kill')
|
|
| 80 |
service = rospy.ServiceProxy('/kill', Kill)
|
|
| 81 |
if name in processes:
|
|
| 82 |
processes[name].kill()
|
|
| 83 |
del processes[name]
|
|
| 84 |
resp = service(name)
|
|
| 85 |
if name in scouts:
|
|
| 86 |
del scouts[name]
|
|
| 87 |
return True
|
|
| 88 |
except rospy.ServiceException, e:
|
|
| 89 |
return False
|
|
| 88 | 90 |
|
| 89 | 91 |
def PauseScout(name, behaviorLabel, behaviorButton, selectedBehavior): |
| 90 | 92 |
return SetBehavior(name, behaviorLabel, behaviorButton, |
| ... | ... | |
| 222 | 224 |
return |
| 223 | 225 |
|
| 224 | 226 |
if __name__ == '__main__': |
| 225 |
ScoutSimGui = subprocess.Popen("rosrun scoutsim scoutsim_node race", shell=True)
|
|
| 226 |
rospy.wait_for_service('/spawn')
|
|
| 227 |
#subprocess.Popen("rosservice call /spawn 1.4 0.275 0 scout1", shell=True) # why was this here?
|
|
| 228 |
app = wx.App() |
|
| 229 |
GUI(None, title='Colony Scout Manager') |
|
| 230 |
app.MainLoop() |
|
| 231 |
# This doesn't run. I'm sure there is a reason why. |
|
| 232 |
for process in processes: |
|
| 233 |
process.kill() |
|
| 234 |
ScoutSimGui.kill() |
|
| 227 |
ScoutSimGui = subprocess.Popen("rosrun scoutsim scoutsim_node race", shell=True)
|
|
| 228 |
rospy.wait_for_service('/spawn')
|
|
| 229 |
#subprocess.Popen("rosservice call /spawn 1.4 0.275 0 scout1", shell=True) # why was this here?
|
|
| 230 |
app = wx.App() |
|
| 231 |
GUI(None, title='Colony Scout Manager') |
|
| 232 |
app.MainLoop() |
|
| 233 |
# This doesn't run. I'm sure there is a reason why. |
|
| 234 |
for process in processes: |
|
| 235 |
process.kill() |
|
| 236 |
ScoutSimGui.kill() |
|
Also available in: Unified diff