game_controller.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('pacman_controller')
00003 import rospy
00004 import string
00005 try:
00006     import wx
00007 except ImportError:
00008     raise ImportError,"The wxPython module is required to run this program"
00009 
00010 from std_msgs.msg import String
00011 from collvoid_msgs.msg import PoseTwistWithCovariance
00012 
00013 class GameController(wx.Frame):
00014 
00015     def __init__(self,parent,id,title):
00016         wx.Frame.__init__(self,parent,id,title)
00017         self.parent = parent
00018         self.initialize()
00019         
00020     def initialize(self):
00021         sizer = wx.BoxSizer(wx.VERTICAL)
00022         self.SetSizer(sizer)
00023         self.subCommonPositions = rospy.Subscriber("/position_share", PoseTwistWithCovariance, self.cbCommonPositions)
00024         self.pub = rospy.Publisher('/commands_robot', String)
00025 
00026         self.robotList = []
00027         self.robotList.append("all")
00028 
00029 #        self.reset_srv = rospy.ServiceProxy('/stageros/reset', Empty)
00030 
00031         static_sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Controls"), wx.HORIZONTAL)
00032         sizer.Add(static_sizer, 0)
00033          
00034         start = wx.Button(self,-1,label="Start!")
00035         static_sizer.Add(start, 0)
00036         self.Bind(wx.EVT_BUTTON, self.makeCommand("Start"), start)
00037         
00038         stop = wx.Button(self,-1,label="Stop!")
00039         static_sizer.Add(stop, 0)
00040         self.Bind(wx.EVT_BUTTON, self.makeCommand("Stop"), stop)
00041 
00042         reset = wx.Button(self,-1,label="Init!")
00043         static_sizer.Add(reset, 0)
00044         self.Bind(wx.EVT_BUTTON, self.makeCommand("Init"), reset)
00045 
00046 
00047         grid_sizer = wx.GridBagSizer()
00048         static_sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "New Goals"), wx.HORIZONTAL)
00049         static_sizer.Add(grid_sizer, 0)
00050         sizer.Add(static_sizer, 0)
00051  
00052         self.choiceBox = wx.Choice(self,-1,choices=self.robotList)
00053 
00054         grid_sizer.Add(self.choiceBox,(0,0),(1,2),wx.EXPAND)
00055         self.SetPosition(wx.Point(200,200))
00056         self.SetSize(wx.Size(600,200))
00057         
00058       
00059         saveMap = wx.Button(self,-1,label="Save Map")
00060         grid_sizer.Add(saveMap, (4,0))
00061         self.Bind(wx.EVT_BUTTON, self.makeCommand("Save Map"), saveMap)
00062 
00063 #        setWPoff = wx.Button(self,-1,label="WP Planner Off")
00064 #        grid_sizer.Add(setWPoff, (4,1))
00065 #        self.Bind(wx.EVT_BUTTON, self.makeCommand("1"), setWPoff)
00066 
00067         sendInitGuess = wx.Button(self,-1,label="Send init Guess")
00068         grid_sizer.Add(sendInitGuess, (5,0))
00069         self.Bind(wx.EVT_BUTTON, self.makeCommand("init Guess"), sendInitGuess)
00070 
00071         sendSetup = wx.Button(self,-1,label="Setup")
00072         grid_sizer.Add(sendSetup, (5,1))
00073         self.Bind(wx.EVT_BUTTON, self.makeCommand("Setup"), sendSetup)
00074 
00075         
00076         setCircleOn = wx.Button(self,-1,label="Pause")
00077         grid_sizer.Add(setCircleOn, (6,0))
00078         self.Bind(wx.EVT_BUTTON, self.makeCommand("Pause"), setCircleOn)
00079 
00080         setCircleOff = wx.Button(self,-1,label="Resume")
00081         grid_sizer.Add(setCircleOff, (6,1))
00082         self.Bind(wx.EVT_BUTTON, self.makeCommand("Resume"), setCircleOff)
00083 
00084         grid_sizer.AddGrowableCol(0)
00085         self.SetSizer(sizer)
00086 
00087         self.Layout()
00088         self.Fit()
00089         self.Show(True)
00090 
00091         
00092     def makeCommand(self,string):
00093         return lambda event, s=string: self.sendCommand(s)
00094                
00095     def cbCommonPositions(self,msg):
00096         if self.robotList.count(msg.robot_id) == 0:
00097             rospy.loginfo("robot added")
00098             self.robotList.append(msg.robot_id)
00099             self.choiceBox.Append(msg.robot_id)
00100 
00101     def sendCommand(self,string):
00102         self.pub.publish(String(string))
00103 
00104     
00105 if __name__ == '__main__':
00106     rospy.init_node('game_controller')
00107     app = wx.App()
00108     frame = GameController(None,-1,'Game Controller')
00109 
00110     app.MainLoop()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


pacman_controller
Author(s): Daniel Claes
autogenerated on Sun Aug 25 2013 10:10:43