00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 import roslib
00061 roslib.load_manifest('cob_dashboard')
00062 from cob_relayboard.msg import EmergencyStopState
00063 from buttons import *
00064 import thread
00065 import pygtk
00066 pygtk.require('2.0')
00067 import gtk
00068 import roslib
00069 import os
00070 import pynotify
00071 import sys
00072
00073 planning_enabled = False
00074 base_diff_enabled = False
00075
00076
00077 gtk.gdk.threads_init()
00078
00079
00080 def start(func, args):
00081 global planning_enabled
00082 global base_diff_enabled
00083 largs = list(args)
00084 if(largs[0] == "arm"):
00085 if(planning_enabled):
00086 largs.append("planned")
00087 if(largs[0] == "base"):
00088 if(base_diff_enabled):
00089 largs.append("diff")
00090
00091 thread.start_new_thread(func,tuple(largs))
00092
00093 def startGTK(widget, data):
00094 data()
00095
00096
00097 class GtkGeneralPanel(gtk.Frame):
00098 def __init__(self):
00099 gtk.Frame.__init__(self)
00100 if not pynotify.init ("cob_dashboard"):
00101 sys.exit (1)
00102 self.em_stop = False
00103 self.set_label("general")
00104 self.set_shadow_type(gtk.SHADOW_IN)
00105 self.vbox = gtk.VBox(False, 0)
00106 self.add(self.vbox)
00107
00108
00109
00110
00111
00112
00113
00114 hbox=gtk.HBox(True, 0)
00115 self.status_image = gtk.Image()
00116 self.status_image.set_from_file(roslib.packages.get_pkg_dir("cob_dashboard") + "/common/files/icons/weather-clear.png")
00117 hbox.pack_start(self.status_image, False, False, 0)
00118 self.status_label = gtk.Label("Status OK")
00119 hbox.pack_start(self.status_label, False, False, 0)
00120 self.vbox.pack_start(hbox, False, False, 5)
00121
00122
00123
00124
00125
00126 plan_check = gtk.CheckButton("Planning")
00127 plan_check.connect("toggled", self.planned_toggle)
00128 self.vbox.pack_start(plan_check, False, False, 5)
00129
00130 base_mode_check = gtk.CheckButton("Base Diff")
00131 base_mode_check.connect("toggled", self.base_mode_toggle)
00132 self.vbox.pack_start(base_mode_check, False, False, 5)
00133
00134 but = gtk.Button(stock=gtk.STOCK_QUIT )
00135 but.connect("clicked", lambda w: gtk.main_quit())
00136 self.vbox.pack_start(but, False, False, 5)
00137
00138 def setEMStop(self, em):
00139 if(em):
00140
00141 self.status_image.set_from_file(roslib.packages.get_pkg_dir("cob_dashboard") + "/common/files/icons/weather-storm.png")
00142 self.status_label.set_text("EM Stop !")
00143 if(self.em_stop == False):
00144 self.em_stop = True
00145 n = pynotify.Notification("Emergency Stop issued!", "", "dialog-warning")
00146 n.set_timeout(1)
00147 n.show()
00148 else:
00149
00150
00151 self.status_label.set_text("Status OK")
00152 if(self.em_stop == True):
00153 self.em_stop = False
00154 n = pynotify.Notification("Emergency Stop released!", "", "dialog-ok")
00155 n.set_timeout(1)
00156 n.show()
00157
00158 def planned_toggle(self, b):
00159 global planning_enabled
00160 if(planning_enabled):
00161 planning_enabled = False
00162 else:
00163 planning_enabled = True
00164
00165 def base_mode_toggle(self, b):
00166 global base_diff_enabled
00167 if(base_diff_enabled):
00168 base_diff_enabled = False
00169 else:
00170 base_diff_enabled = True
00171
00172
00173
00174 class GtkPanel(gtk.Frame):
00175 def __init__(self, master=None, labeltext=""):
00176 gtk.Frame.__init__(self)
00177 self.set_label(labeltext)
00178 self.set_shadow_type(gtk.SHADOW_IN)
00179 self.vbox = gtk.VBox(False, 0)
00180 self.add(self.vbox)
00181
00182 def addButton(self, text, command):
00183 but = gtk.Button(text)
00184 but.connect("clicked", startGTK, command)
00185
00186 self.vbox.pack_start(but, False, False, 5)
00187
00188
00189 class Knoeppkes():
00190 def delete_event(self, widget, event, data=None):
00191 gtk.main_quit()
00192 return False
00193
00194 def emcb(self, msg):
00195 self.gpanel.setEMStop(msg.emergency_state)
00196
00197 def __init__(self):
00198
00199 rospy.init_node('cob_knoeppkes')
00200 rospy.Subscriber("/emergency_stop_state", EmergencyStopState, self.emcb)
00201
00202 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
00203 self.window.connect("delete_event", self.delete_event)
00204 self.window.set_title("cob_dashboard")
00205 self.window.set_size_request(1000, 500)
00206 vbox = gtk.VBox(False, 1)
00207 self.hbox = gtk.HBox(True, 10)
00208 vbox.pack_start(self.hbox, True, True, 0)
00209 self.gpanel = GtkGeneralPanel()
00210 self.hbox.pack_start(self.gpanel,True, True, 3)
00211 b = buttons()
00212 panels = b.panels
00213 for pname, actions in panels:
00214 panel = GtkPanel(self, pname)
00215 for aname, func, args in actions:
00216 panel.addButton(text=aname, command=lambda f=func, a=args: start(f, a))
00217 self.hbox.pack_start(panel,True, True, 3)
00218
00219 self.status_bar = gtk.Statusbar()
00220 context_id = self.status_bar.get_context_id("Statusbar")
00221 string = "Connected to $ROS_MASTER_URI=" + os.environ.get("ROS_MASTER_URI")
00222 self.status_bar.push(context_id, string)
00223 vbox.pack_start(self.status_bar, False, False, 0)
00224 self.window.add(vbox)
00225 self.window.show_all()
00226 gtk.gdk.threads_init()
00227 gtk.main()
00228
00229 app = Knoeppkes()