Revision da8ace01 scout/scoutsim/BehaviorGUI.py

View differences:

scout/scoutsim/BehaviorGUI.py
36 36
    return ["CW Circle", "CCW Circle", "Odometry", "Navigation Map",
37 37
        "Scheduler", "Warehouse", "Line Follow", "WL Test"]
38 38

  
39
def SetBehavior(name, behaviorLabel, behaviorButton=False, behavior="Pause",
40
        selectedBehavior="Pause"):
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 + " "
47
                + str(GetBehaviors().index(selectedBehavior) + 1) + "",
48
                shell=True)
49
            print "Scout " + name + " was resumed."
50
            behaviorButton.SetLabel("Pause")
51
            behaviorLabel.SetLabel("  |  Current Behavior: " + scouts[name])
39
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
52 51
        else:
53 52
			processes[name].terminate()
54 53
			del processes[name]
55
			subprocess.Popen("rosrun libscout libscout " + name + " 0",
56
				shell=True) 
54
			subprocess.Popen("rosrun libscout libscout " + name + " 0", shell=True) 
57 55
			print "Scout "+name+" was paused."
58 56
			behaviorButton.SetLabel("Resume")
59 57
			behaviorLabel.SetLabel("  |  Current Behavior: Paused")
60
        return True
61
    if name in processes:
62
        processes[name].terminate()
58
			return True
59
	if name in processes:
60
		processes[name].terminate()
63 61
        # TODO Running a new behavior while paused does not do anything and
64 62
        # Gives lots of errors.
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
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
76 74

  
77 75
def KillScout(name):
78 76
	try:
79 77
		rospy.wait_for_service('/kill')
80 78
		service = rospy.ServiceProxy('/kill', Kill)
81 79
		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()
80
			processes[name].kill()
87 81
			del processes[name]
88 82
		resp = service(name)
89 83
		if name in scouts:
......
228 222
        return
229 223

  
230 224
if __name__ == '__main__':
231
    subprocess.Popen("rosrun scoutsim scoutsim_node race", shell=True)
232
    rospy.wait_for_service('/spawn')
233
    subprocess.Popen("rosservice call /spawn 1.4 0.275 0 scout1", shell=True)
234
    app = wx.App()
235
    GUI(None, title='Colony Scout Manager')
236
    app.MainLoop()
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()

Also available in: Unified diff