00001
00002 import roslib; roslib.load_manifest('collvoid_controller')
00003 import rospy
00004 import commands
00005 import string
00006 try:
00007 import wx
00008 except ImportError:
00009 raise ImportError,"The wxPython module is required to run this program"
00010
00011 from std_msgs.msg import String
00012 from geometry_msgs.msg import PoseWithCovarianceStamped,PoseStamped
00013 from std_srvs.srv import Empty
00014 from collvoid_msgs.msg import PoseTwistWithCovariance
00015
00016 import tf
00017
00018 class controller(wx.Frame):
00019
00020
00021 def __init__(self,parent,id,title):
00022 wx.Frame.__init__(self,parent,id,title)
00023 self.parent = parent
00024 self.initialized = False
00025 self.initialize()
00026
00027 def initialize(self):
00028 sizer = wx.BoxSizer(wx.VERTICAL)
00029 self.SetSizer(sizer)
00030
00031 self.pub = rospy.Publisher('/commands_robot', String)
00032
00033 self.robotList = []
00034 self.robotList.append("all")
00035
00036 self.reset_srv = rospy.ServiceProxy('/stageros/reset', Empty)
00037
00038 static_sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Controls"), wx.HORIZONTAL)
00039 sizer.Add(static_sizer, 0)
00040
00041 start = wx.Button(self,wx.ID_ANY,label="Start!")
00042 static_sizer.Add(start, 0)
00043 self.Bind(wx.EVT_BUTTON, self.start, start)
00044
00045 stop = wx.Button(self,wx.ID_ANY,label="Stop!")
00046 static_sizer.Add(stop, 0)
00047 self.Bind(wx.EVT_BUTTON, self.stop, stop)
00048
00049 reset = wx.Button(self,wx.ID_ANY,label="Reset!")
00050 static_sizer.Add(reset, 0)
00051 self.Bind(wx.EVT_BUTTON, self.reset, reset)
00052
00053
00054 grid_sizer = wx.GridBagSizer()
00055 static_sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "New Goals"), wx.HORIZONTAL)
00056 static_sizer.Add(grid_sizer, 0)
00057 sizer.Add(static_sizer, 0)
00058
00059 self.choiceBox = wx.Choice(self,wx.ID_ANY,choices=self.robotList)
00060
00061 grid_sizer.Add(self.choiceBox,(0,0),(1,2),wx.EXPAND)
00062 self.SetPosition(wx.Point(200,200))
00063 self.SetSize(wx.Size(600,200))
00064
00065
00066 setCircling = wx.Button(self,wx.ID_ANY,label="Circling On/Off")
00067 grid_sizer.Add(setCircling, (3,1))
00068 self.Bind(wx.EVT_BUTTON, self.setCircling, setCircling)
00069
00070
00071 setOnOff = wx.Button(self,wx.ID_ANY,label="Set On/Off")
00072 grid_sizer.Add(setOnOff, (3,0))
00073 self.Bind(wx.EVT_BUTTON, self.setOnOff, setOnOff)
00074
00075
00076 sendDelayedGoal = wx.Button(self,wx.ID_ANY,label="Send delayed Goal")
00077 grid_sizer.Add(sendDelayedGoal, (4,0))
00078 self.Bind(wx.EVT_BUTTON, self.sendDelayedGoal, sendDelayedGoal)
00079
00080 self.delayTime = wx.TextCtrl(self,wx.ID_ANY,value=u"0.0")
00081 grid_sizer.Add(self.delayTime, (4,1))
00082
00083 sendInitGuess = wx.Button(self,wx.ID_ANY,label="Send init Guess")
00084 grid_sizer.Add(sendInitGuess, (5,0))
00085 self.Bind(wx.EVT_BUTTON, self.sendInitGuess, sendInitGuess)
00086
00087 sendNextGoal = wx.Button(self,wx.ID_ANY,label="Send next Goal")
00088 grid_sizer.Add(sendNextGoal, (5,1))
00089 self.Bind(wx.EVT_BUTTON, self.sendNextGoal, sendNextGoal)
00090
00091
00092 grid_sizer.AddGrowableCol(0)
00093 self.SetSizer(sizer)
00094
00095 self.Layout()
00096 self.Fit()
00097 self.Show(True)
00098
00099 self.subCommonPositions = rospy.Subscriber("/position_share", PoseTwistWithCovariance, self.cbCommonPositions)
00100 self.initialized = True
00101
00102 def cbCommonPositions(self,msg):
00103 if not self.initialized:
00104 return
00105 if self.robotList.count(msg.robot_id) == 0:
00106 rospy.loginfo("robot added")
00107 self.robotList.append(msg.robot_id)
00108 self.choiceBox.Append(msg.robot_id)
00109
00110 def sendDelayedGoal(self, event):
00111 sleepTime = float(self.delayTime.GetValue())
00112 rospy.sleep(sleepTime)
00113 string = "%s send delayed Goal"%self.choiceBox.GetStringSelection()
00114 self.pub.publish(str(string))
00115
00116 def setCircling(self,event):
00117 string = "%s circle"%self.choiceBox.GetStringSelection()
00118 self.pub.publish(str(string))
00119
00120 def setOnOff(self,event):
00121 string = "%s WP change"%self.choiceBox.GetStringSelection()
00122 self.pub.publish(str(string))
00123
00124
00125 def sendNextGoal(self,event):
00126 string = "%s next Goal"%self.choiceBox.GetStringSelection()
00127 self.pub.publish(str(string))
00128
00129 def sendInitGuess(self,event):
00130 string = "%s init Guess"%self.choiceBox.GetStringSelection()
00131 self.pub.publish(str(string))
00132
00133 def stop(self,event):
00134 string = "%s Stop"%self.choiceBox.GetStringSelection()
00135 self.pub.publish(str(string))
00136
00137 def start(self,event):
00138 string = "%s next Goal"%self.choiceBox.GetStringSelection()
00139 self.pub.publish(str(string))
00140
00141 def all_start(self,event):
00142 string = "all Start"
00143 self.pub.publish(str(string))
00144
00145 def all_init_guess(self,event):
00146 string = "all init Guess"
00147 self.pub.publish(str(string))
00148
00149
00150 def reset(self,event):
00151 self.pub.publish("all Stop")
00152 rospy.sleep(0.2)
00153 self.pub.publish("all Restart")
00154
00155 self.reset_srv()
00156
00157
00158 if __name__ == '__main__':
00159 rospy.init_node('controller')
00160 app = wx.App()
00161 frame = controller(None,wx.ID_ANY,'Controller')
00162
00163 app.MainLoop()