Revision 8fa2bd2e
ID | 8fa2bd2eac72d68722a41597a349feaf6846326a |
Probably fixed the crashing bugs. Implemented floating point pickers.
scout/scoutsim/BehaviorGUI.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import wx |
4 | 4 |
import wx.lib.intctrl |
5 |
import wx.lib.agw.floatspin |
|
5 | 6 |
import string |
6 | 7 |
import subprocess |
7 | 8 |
import signal |
... | ... | |
12 | 13 |
from scoutsim.srv import * |
13 | 14 |
|
14 | 15 |
# Everyone global variables (PLEASE REFACTOR ME) |
15 |
scouts = defaultdict(str) # Associative array in the form [scout_name: current_behavior]
|
|
16 |
processes = defaultdict() # Associative array in the form [scout_name: process_handler]
|
|
16 |
scouts = defaultdict(str) # Dict in the form [scout_name: current_behavior]
|
|
17 |
processes = defaultdict() # Dict in the form [scout_name: process_handler]
|
|
17 | 18 |
|
18 | 19 |
# |
19 | 20 |
# ROS functions |
... | ... | |
49 | 50 |
behaviorButton.SetLabel("Pause") |
50 | 51 |
behaviorLabel.SetLabel(" | Current Behavior: " + scouts[name]) |
51 | 52 |
else: |
52 |
processes[name].kill()
|
|
53 |
processes[name].wait()
|
|
54 |
subprocess.Popen("rosrun libscout libscout " + name + " 0",
|
|
55 |
shell=True)
|
|
56 |
print "Scout "+name+" was paused."
|
|
57 |
behaviorButton.SetLabel("Resume")
|
|
58 |
behaviorLabel.SetLabel(" | Current Behavior: Paused")
|
|
53 |
processes[name].terminate()
|
|
54 |
del processes[name]
|
|
55 |
subprocess.Popen("rosrun libscout libscout " + name + " 0",
|
|
56 |
shell=True)
|
|
57 |
print "Scout "+name+" was paused."
|
|
58 |
behaviorButton.SetLabel("Resume")
|
|
59 |
behaviorLabel.SetLabel(" | Current Behavior: Paused")
|
|
59 | 60 |
return True |
60 | 61 |
if name in processes: |
61 |
processes[name].kill() |
|
62 |
processes[name].wait() |
|
62 |
processes[name].terminate() |
|
63 | 63 |
# TODO Running a new behavior while paused does not do anything and |
64 | 64 |
# Gives lots of errors. |
65 |
# |
|
66 |
# -- Matt 11/30 -- |
|
67 |
# Might be fixed, can't run it to tell. |
|
65 | 68 |
processes[name] = subprocess.Popen("rosrun libscout libscout " + name + " " |
66 | 69 |
+ str(GetBehaviors().index(behavior) + 1) + "", |
67 | 70 |
shell=True) |
... | ... | |
72 | 75 |
scouts[name] = behavior |
73 | 76 |
|
74 | 77 |
def KillScout(name): |
75 |
try: |
|
76 |
rospy.wait_for_service('/kill'); |
|
77 |
service = rospy.ServiceProxy('/kill', Kill); |
|
78 |
if name in processes: |
|
79 |
# TODO BUG: Pausing a scout and then killing it crashes the program. |
|
80 |
processes[name].kill() # This is perhaps not working |
|
81 |
resp = service(name) |
|
82 |
del scouts[name] |
|
83 |
del processes[name] |
|
84 |
return True |
|
85 |
except rospy.ServiceException, e: |
|
86 |
return False |
|
78 |
try: |
|
79 |
rospy.wait_for_service('/kill') |
|
80 |
service = rospy.ServiceProxy('/kill', Kill) |
|
81 |
if name in processes: |
|
82 |
# TODO BUG: Pausing a scout and then killing it crashes the program. |
|
83 |
# |
|
84 |
# -- Matt 11/30 -- |
|
85 |
# Should be fixed |
|
86 |
processes[name].terminate() |
|
87 |
del processes[name] |
|
88 |
resp = service(name) |
|
89 |
if name in scouts: |
|
90 |
del scouts[name] |
|
91 |
return True |
|
92 |
except rospy.ServiceException, e: |
|
93 |
return False |
|
87 | 94 |
|
88 | 95 |
def PauseScout(name, behaviorLabel, behaviorButton, selectedBehavior): |
89 | 96 |
return SetBehavior(name, behaviorLabel, behaviorButton, |
... | ... | |
115 | 122 |
|
116 | 123 |
# Inputs |
117 | 124 |
newScoutInput = wx.TextCtrl(self.window) |
118 |
startX = wx.lib.intctrl.IntCtrl(self.window, min=0)
|
|
119 |
startY = wx.lib.intctrl.IntCtrl(self.window, min=0)
|
|
120 |
startTheta = wx.lib.intctrl.IntCtrl(self.window, min=0, max=100)
|
|
125 |
startX = wx.lib.agw.floatspin.FloatSpin(self.window, min_val=0, digits=5)
|
|
126 |
startY = wx.lib.agw.floatspin.FloatSpin(self.window, min_val=0, digits=5)
|
|
127 |
startTheta = wx.lib.agw.floatspin.FloatSpin(self.window, min_val=0, digits=5)
|
|
121 | 128 |
addButton = wx.Button(self.window, id=wx.ID_ADD) |
122 | 129 |
|
123 | 130 |
# Pretty Stuff |
... | ... | |
209 | 216 |
return False |
210 | 217 |
|
211 | 218 |
def RemoveScout(self, name): |
212 |
# I don't trust this bit. Remove() should work by itself, |
|
213 |
# but it doesn't want to. Hide()ing before Remove()ing does work |
|
214 |
# for some reason though. It makes me think the sizer is still around |
|
215 |
# somewhere, sneakily leaking memory. Alas, such is life. |
|
216 | 219 |
print("Hidden scoutLayout for " + name + ": " |
217 | 220 |
+ str(self.mainArea.Hide(self.sizer[name], True))) |
218 | 221 |
print("Removed scoutLayout for " + name + ": " |
Also available in: Unified diff