Project

General

Profile

Revision 16d4e150

ID16d4e15009af60484e8b444d8cbd114bb0c9eb1a

Added by Priya over 11 years ago

Fixed pause and resume. Kind of. There are lots of bugs with the GUI.

View differences:

scout/libscout/src/behaviors/pause_scout.cpp
27 27

  
28 28
void pause_scout::run()
29 29
{
30
	motors->set_sides(0, 0, MOTOR_ABSOLUTE);
30
  while(ok()){
31
	  motors->set_sides(0, 0, MOTOR_ABSOLUTE);
32
  }
31 33
}
scout/scoutsim/BehaviorGUI.py
34 34
def GetBehaviors():
35 35
	return ["CW Circle", "CCW Circle", "Odometry", "Navigation Map", "Scheduler", "Warehouse", "Line Follow", "WL Test"]
36 36

  
37
def SetBehavior(name, behaviorLabel, behaviorButton=False, behavior="Pause"):
37
def SetBehavior(name, behaviorLabel, behaviorButton=False, behavior="Pause", selectedBehavior="Pause"):
38 38
	if behavior == "Pause":
39 39
		if name not in processes:
40 40
			return False
41 41
		if not behaviorButton.GetValue():
42
			processes[name].send_signal(signal.SIGCONT)
42
			processes[name] = subprocess.Popen("rosrun libscout libscout "+name+" "+str(GetBehaviors().index(selectedBehavior)+1)+"", shell=True)
43 43
			print "Scout "+name+" was resumed."
44 44
			behaviorButton.SetLabel("Pause")
45 45
			behaviorLabel.SetLabel("  |  Current Behavior: "+scouts[name])
46 46
		else:
47
			processes[name].send_signal(signal.SIGSTOP)
47
			processes[name].kill()
48
			processes[name].wait()
48 49
			subprocess.Popen("rosrun libscout libscout "+name+" 0", shell=True) 
49 50
			print "Scout "+name+" was paused."
50 51
			behaviorButton.SetLabel("Resume")
......
52 53
		return True
53 54
	if name in processes:
54 55
		processes[name].kill()
56
		processes[name].wait()
57
		# Running a new behavior while paused does not do anything and
58
		# Gives lots of behaviors.
55 59
	processes[name] = subprocess.Popen("rosrun libscout libscout "+name+" "+str(GetBehaviors().index(behavior)+1)+"", shell=True) 
56 60
	behaviorButton.SetValue(False)
57 61
	behaviorButton.SetLabel("Pause")
......
64 68
		rospy.wait_for_service('/kill');
65 69
		service = rospy.ServiceProxy('/kill', Kill);
66 70
		if name in processes:
71
			# BUG: Pause-ing a scout and then killing it crashes the program.
67 72
			processes[name].kill() # This is perhaps not working
68 73
		resp = service(name)
69 74
		del scouts[name]
......
72 77
	except rospy.ServiceException, e:
73 78
		return False
74 79

  
75
def PauseScout(name, behaviorLabel, behaviorButton):
76
	return SetBehavior(name, behaviorLabel, behaviorButton)
80
def PauseScout(name, behaviorLabel, behaviorButton, selectedBehavior):
81
	return SetBehavior(name, behaviorLabel, behaviorButton, "Pause", selectedBehavior)
77 82
#
78 83
# End ROS functions
79 84
#
......
165 170
		self.sizer[name].Add(pauseButton, wx.ALIGN_RIGHT)
166 171
		
167 172
		# Events
168
		pauseButton.Bind(wx.EVT_TOGGLEBUTTON, lambda event: PauseScout(name, currBehaviorLabel, pauseButton))
173
		pauseButton.Bind(wx.EVT_TOGGLEBUTTON, lambda event: PauseScout(name, currBehaviorLabel, pauseButton, scoutChoices.GetStringSelection()))
169 174
		runButton.Bind(wx.EVT_BUTTON, lambda event: SetBehavior(name, currBehaviorLabel, pauseButton, scoutChoices.GetStringSelection()))
170 175
		killButton.Bind(wx.EVT_BUTTON, lambda event: self.RemoveScout(name))
171 176

  

Also available in: Unified diff