Exemplo n.º 1
0
    def __init__(self):

        # get a logger
        self.log = logging.getLogger("GTK_Main")

        # save init values
        self.fullscreen = False  # this is technicaly not consistant as it is not chnaged on system uests
        self.robot = Robot(self.BT_ADDRESS)
        self.feed_radio = "real"
        self.fix_colour = False
        self.half_time = False

        # do some jazz to see if we are on dice and or video pc
        self.hostname = gethostname()
        self.are_in_inf = False
        self.are_on_vision_pc = False
        if self.hostname.endswith("inf.ed.ac.uk"):
            self.are_in_inf = True
            if self.hostname.split(".")[0] in [
                    "lappy", "mitsubishi", "lexus", "honda"
            ]:
                self.are_on_vision_pc = True

        # setup the window
        builder = gtk.Builder()
        builder.add_from_file("main_ui.xml")

        self.window = builder.get_object("window_main")

        # change out the image with are video widget
        video_holder_box = builder.get_object("box_videoHolder")
        video_holder_img = builder.get_object("image_videoHolder")
        self.gst = GstDrawingArea()
        video_holder_box.remove(video_holder_img)
        video_holder_box.add(self.gst)

        # connect to GUI events
        self.window.set_events(gtk.gdk.KEY_PRESS_MASK
                               | gtk.gdk.KEY_RELEASE_MASK)
        self.window.connect("key_press_event", self.on_key_press)
        self.window.connect("key_release_event", self.on_key_release)
        self.window.connect("destroy", self.clean_quit)
        builder.connect_signals(self)

        # get all wigets that are needed later
        self.table_manualControl = builder.get_object("table_manualControl")

        # show the GUI
        self.gst.show()
        self.window.show()

        self.log.debug("GTK windows complete")
Exemplo n.º 2
0
 def __init__(self):
   
   # get a logger
   self.log = logging.getLogger("GTK_Main")
   
   # save init values
   self.fullscreen = False # this is technicaly not consistant as it is not chnaged on system uests
   self.robot = Robot(self.BT_ADDRESS)
   self.feed_radio = "real"
   self.fix_colour = False
   self.half_time = False
   
   # do some jazz to see if we are on dice and or video pc
   self.hostname = gethostname()
   self.are_in_inf = False
   self.are_on_vision_pc = False
   if self.hostname.endswith("inf.ed.ac.uk"):
     self.are_in_inf = True
     if self.hostname.split(".")[0] in ["lappy", "mitsubishi", "lexus", "honda"]:
       self.are_on_vision_pc = True
   
   # setup the window
   builder = gtk.Builder()
   builder.add_from_file("main_ui.xml")
   
   self.window = builder.get_object("window_main")
   
   # change out the image with are video widget
   video_holder_box = builder.get_object("box_videoHolder") 
   video_holder_img = builder.get_object("image_videoHolder")
   self.gst = GstDrawingArea()
   video_holder_box.remove(video_holder_img)
   video_holder_box.add(self.gst)
   
   # connect to GUI events
   self.window.set_events(gtk.gdk.KEY_PRESS_MASK|gtk.gdk.KEY_RELEASE_MASK)
   self.window.connect("key_press_event", self.on_key_press)
   self.window.connect("key_release_event", self.on_key_release)
   self.window.connect("destroy", self.clean_quit)
   builder.connect_signals(self)
   
   # get all wigets that are needed later
   self.table_manualControl = builder.get_object("table_manualControl")
   
   # show the GUI
   self.gst.show()
   self.window.show()
       
   self.log.debug("GTK windows complete")
Exemplo n.º 3
0
 def __connect(self):
   self.button_connect["text"] = "Connecting"
   try:
     # first try to find are know robot
     self.robot = Robot(host=self.BT_ADDRESS)
   except RobotNotFoundError: # TODO
     # try to find any robot
     self.robot = Robot()
   except Exception as error:
     print "Robot Error" # + str(error)
     self.button_connect["text"] = "Connect"
     self.button_connect["state"] = "active"
     raise error
   
   self.scale_power.set(self.robot.get_power())
   self.button_up["state"] = "active"
   self.button_dn["state"] = "active"
   self.button_le["state"] = "active"
   self.button_ri["state"] = "active"
   self.button_st["state"] = "active"
   self.button_bz["state"] = "active"
   self.scale_power["state"] = "active"
   self.button_connect["state"] = "disabled"
   self.button_connect["text"] = "Connected"
Exemplo n.º 4
0
    def __connect(self, widget=None, data=None):
        if not self.button_connect.get_active():
            self.button_connect.set_active(True)  # keep it active
            return  # ingnor button when not acctive

        if self.robot != None:
            self.log.warning("Tryed to connect to a already connected brick")
            return

        self.button_connect.set_label("Connecting")
        try:
            # first try to find are know robot
            self.robot = Robot(host=self.BT_ADDRESS)
            self.button_connect.set_label("Conected")
            self.button_connect.set_active(True)
        except Exception as error:
            self.log.error(error)
            self.button_connect.set_label("Connect")
            self.button_connect.set_active(False)
            self.robot = None
Exemplo n.º 5
0
class GTK_Main(object):

    BT_ADDRESS = "00:16:53:08:A0:E6"

    def __init__(self):

        # get a logger
        self.log = logging.getLogger("GTK_Main")

        # save init values
        self.fullscreen = False  # this is technicaly not consistant as it is not chnaged on system uests
        self.robot = Robot(self.BT_ADDRESS)
        self.feed_radio = "real"
        self.fix_colour = False
        self.half_time = False

        # do some jazz to see if we are on dice and or video pc
        self.hostname = gethostname()
        self.are_in_inf = False
        self.are_on_vision_pc = False
        if self.hostname.endswith("inf.ed.ac.uk"):
            self.are_in_inf = True
            if self.hostname.split(".")[0] in [
                    "lappy", "mitsubishi", "lexus", "honda"
            ]:
                self.are_on_vision_pc = True

        # setup the window
        builder = gtk.Builder()
        builder.add_from_file("main_ui.xml")

        self.window = builder.get_object("window_main")

        # change out the image with are video widget
        video_holder_box = builder.get_object("box_videoHolder")
        video_holder_img = builder.get_object("image_videoHolder")
        self.gst = GstDrawingArea()
        video_holder_box.remove(video_holder_img)
        video_holder_box.add(self.gst)

        # connect to GUI events
        self.window.set_events(gtk.gdk.KEY_PRESS_MASK
                               | gtk.gdk.KEY_RELEASE_MASK)
        self.window.connect("key_press_event", self.on_key_press)
        self.window.connect("key_release_event", self.on_key_release)
        self.window.connect("destroy", self.clean_quit)
        builder.connect_signals(self)

        # get all wigets that are needed later
        self.table_manualControl = builder.get_object("table_manualControl")

        # show the GUI
        self.gst.show()
        self.window.show()

        self.log.debug("GTK windows complete")

    def save_frame(self, widget=None, data=None):
        self.log.debug("_save_frame")
        if self.gst.is_playing():
            name = self.gst.save_frame_to_file(widget=widget, data=data)
        else:
            self.log.warning("No video to save frame")

    def background_remove(self, widget=None, data=None):
        self.log.debug("background_remove")
        if self.gst.is_playing():
            image = self.gst.get_frame(widget=widget, data=data)
            ImageProcess(image).save_png()  #TODO
            #image = ImageProcess(image).get_image()
            #self.gst.show_img(image)
        else:
            self.log.warning("No video to remove background")

    def start_stop(self, widget=None, data=None):
        self.log.debug("__start_stop")
        if self.gst.is_playing():
            self.stop_feed()
        else:
            self.start_feed()

    def on_manual_robot_control(self, widget=None, data=None):
        self.log.debug("click")
        print data

    def on_key_press(self, widget, data=None):
        self.log.debug("click")

        if data.keyval == 65362:  # up
            self.log.debug("Up")
            self.robot.up()
        elif data.keyval == 65364:  # down
            self.log.debug("Down")
            self.robot.down()
        elif data.keyval == 65361:  # left
            self.log.debug("Left")
            self.robot.left()
        elif data.keyval == 65363:  # right
            self.log.debug("Right")
            self.robot.right()
        elif data.keyval == 32:  # space
            self.log.debug("Kick")
            self.robot.kick()
        elif data.keyval == 65307:  # Esc
            self.clean_quit()
        elif data.keyval == 65480:  # F11
            if self.fullscreen:
                self.window.unfullscreen()
                self.fullscreen = False
            else:
                self.window.fullscreen()
                self.fullscreen = True
        elif data.string == "s":  # s
            self.log.debug("Stop!")
            self.robot.stop()
        else:
            self.log.debug("on_key_press:\n\tevent: '{event}'\n\tkeyval: '{keyval}'\n\tstring: '{str_}'"\
            .format(event="key_press_unknown_key", keyval=data.keyval, str_=data.string))
            return False  # since we dont use the key let the rest of the GUI use it. ie enter and F1
        return True  # stop the rest of the GUI reacting

    def on_key_release(self, widget, data=None):
        self.log.debug("un-click")
        self.robot.stop()
        return True

    def clean_quit(self, widget=None, data=None):
        self.log.debug("Clean Quit")
        self.robot = None
        gtk.main_quit()

    def start_feed(self):
        self.gst.start_video(self.feed_radio,
                             fixcolour=self.fix_colour,
                             rotation=self.half_time)
        # TODO
        #self.button.set_label("Stop")
        #self.button.set_active(True)

    def stop_feed(self):
        self.gst.stop_video()
        # TODO
        #self.button.set_label("Start Feed")
        #self.button.set_active(False)

    def fix_video_colour(self, widget=None, data=None):
        self.log.debug("fix_video_colour")
        self.fix_colour = not self.fix_colour

    def flip_video_feed(self, widget=None, data=None):
        self.log.debug("half_time")
        self.half_time = not self.half_time

    def connect_to_brick(self, widget=None, data=None):
        self.log.debug("connect_to_brick")
        if not widget.get_active():
            return False  # ingnor button when not acctive

        try:
            # first try to find are know robot
            self.robot.connect()
            widget.set_label("Conected")
            widget.set_active(True)
        except Exception as error:
            self.log.error(error)
            widget.set_label("Connect")
            widget.set_active(False)

    def radio_feed_change_real(self, widget=None, data=None):
        self.log.debug("radio_feed_change real")
        if self.feed_radio != "real":
            self.feed_radio = "real"

    def radio_feed_change_test(self, widget=None, data=None):
        self.log.debug("radio_feed_change test")
        if self.feed_radio != "test":
            self.feed_radio = "test"

    def radio_feed_change_file(self, widget=None, data=None):
        self.log.debug("radio_feed_change file")
        if self.feed_radio != "file":
            self.feed_radio = "file"

    def change_manual_control(self, widget=None, data=None):
        self.log.debug("change_manual_control")
        if widget.get_active():
            self.log.warning("Request to chnage to manual")
            widget.set_label("Automatic")
            for child in self.table_manualControl.get_children():
                if child != widget:
                    child.show()
                    if type(child) == gtk.VScale():
                        child.set_value(self.robot.get_power())
        else:
            self.log.warning("Request to chnage to automatic")
            widget.set_label("Manual")
            for child in self.table_manualControl.get_children():
                if child != widget:
                    child.hide()

    def manual_power_change(self, widget=None, data=None):
        self.log.debug("manual_power_change")
        self.robot.set_power(widget.get_value())

    def on_manual_robot_control_up(self, widget=None, data=None):
        self.robot.up()

    def on_manual_robot_control_down(self, widget=None, data=None):
        self.robot.down()

    def on_manual_robot_control_stop(self, widget=None, data=None):
        self.robot.stop()

    def on_manual_robot_control_left(self, widget=None, data=None):
        self.robot.left()

    def on_manual_robot_control_right(self, widget=None, data=None):
        self.robot.right()

    def on_manual_robot_control_kick(self, widget=None, data=None):
        self.robot.kick()

    def on_manual_robot_control_buzz(self, widget=None, data=None):
        self.robot.buzz()

    def __del__(self):
        self.log.info("__del__")
        self.robot = None
Exemplo n.º 6
0
class GTK_Main(object):

  BT_ADDRESS = "00:16:53:08:A0:E6"
  
  def __init__(self):
    
    # get a logger
    self.log = logging.getLogger("GTK_Main")
    
    # save init values
    self.fullscreen = False # this is technicaly not consistant as it is not chnaged on system uests
    self.robot = Robot(self.BT_ADDRESS)
    self.feed_radio = "real"
    self.fix_colour = False
    self.half_time = False
    
    # do some jazz to see if we are on dice and or video pc
    self.hostname = gethostname()
    self.are_in_inf = False
    self.are_on_vision_pc = False
    if self.hostname.endswith("inf.ed.ac.uk"):
      self.are_in_inf = True
      if self.hostname.split(".")[0] in ["lappy", "mitsubishi", "lexus", "honda"]:
        self.are_on_vision_pc = True
    
    # setup the window
    builder = gtk.Builder()
    builder.add_from_file("main_ui.xml")
    
    self.window = builder.get_object("window_main")
    
    # change out the image with are video widget
    video_holder_box = builder.get_object("box_videoHolder") 
    video_holder_img = builder.get_object("image_videoHolder")
    self.gst = GstDrawingArea()
    video_holder_box.remove(video_holder_img)
    video_holder_box.add(self.gst)
    
    # connect to GUI events
    self.window.set_events(gtk.gdk.KEY_PRESS_MASK|gtk.gdk.KEY_RELEASE_MASK)
    self.window.connect("key_press_event", self.on_key_press)
    self.window.connect("key_release_event", self.on_key_release)
    self.window.connect("destroy", self.clean_quit)
    builder.connect_signals(self)
    
    # get all wigets that are needed later
    self.table_manualControl = builder.get_object("table_manualControl")
    
    # show the GUI
    self.gst.show()
    self.window.show()
        
    self.log.debug("GTK windows complete")
  
  def save_frame(self, widget=None, data=None):
    self.log.debug("_save_frame")
    if self.gst.is_playing():
      name = self.gst.save_frame_to_file(widget=widget, data=data)
    else:
      self.log.warning("No video to save frame")
  
  def background_remove(self, widget=None, data=None):
    self.log.debug("background_remove")
    if self.gst.is_playing():
      image = self.gst.get_frame(widget=widget, data=data)
      ImageProcess(image).save_png()   #TODO
      #image = ImageProcess(image).get_image()   
      #self.gst.show_img(image)
    else:
      self.log.warning("No video to remove background")
    
  def start_stop(self, widget=None, data=None):
    self.log.debug("__start_stop")
    if self.gst.is_playing():
      self.stop_feed()
    else:
      self.start_feed()
  
  def on_manual_robot_control(self, widget=None, data=None):
    self.log.debug("click")
    print data
  
  def on_key_press(self, widget, data=None):
    self.log.debug("click")
    
    if data.keyval == 65362: # up
      self.log.debug("Up")
      self.robot.up()
    elif data.keyval == 65364: # down
      self.log.debug("Down")
      self.robot.down()
    elif data.keyval == 65361: # left
      self.log.debug("Left")
      self.robot.left()
    elif data.keyval == 65363: # right
      self.log.debug("Right")
      self.robot.right()
    elif data.keyval == 32: # space
      self.log.debug("Kick")
      self.robot.kick()
    elif data.keyval == 65307: # Esc
      self.clean_quit()
    elif data.keyval == 65480: # F11
      if self.fullscreen:
        self.window.unfullscreen()
        self.fullscreen = False
      else:
        self.window.fullscreen()
        self.fullscreen = True
    elif data.string == "s":  # s
      self.log.debug("Stop!")
      self.robot.stop()
    else:
        self.log.debug("on_key_press:\n\tevent: '{event}'\n\tkeyval: '{keyval}'\n\tstring: '{str_}'"\
        .format(event="key_press_unknown_key", keyval=data.keyval, str_=data.string))
        return False # since we dont use the key let the rest of the GUI use it. ie enter and F1
    return True # stop the rest of the GUI reacting
  
  def on_key_release(self, widget, data=None):
    self.log.debug("un-click")
    self.robot.stop()
    return True
  
  def clean_quit(self, widget=None, data=None):
    self.log.debug("Clean Quit")
    self.robot = None
    gtk.main_quit()
    
  def start_feed(self):
    self.gst.start_video(self.feed_radio, fixcolour=self.fix_colour, rotation=self.half_time)
    # TODO
    #self.button.set_label("Stop")
    #self.button.set_active(True)
  
  def stop_feed(self):
    self.gst.stop_video()
    # TODO
    #self.button.set_label("Start Feed")
    #self.button.set_active(False)
  
  def fix_video_colour(self, widget=None, data=None):
    self.log.debug("fix_video_colour")
    self.fix_colour = not self.fix_colour
  
  def flip_video_feed(self, widget=None, data=None):
    self.log.debug("half_time")
    self.half_time = not self.half_time
  
  def connect_to_brick(self, widget=None, data=None):
    self.log.debug("connect_to_brick")
    if not widget.get_active():
      return False # ingnor button when not acctive

    try:
      # first try to find are know robot
      self.robot.connect()
      widget.set_label("Conected")
      widget.set_active(True)
    except Exception as error:
      self.log.error(error)
      widget.set_label("Connect")
      widget.set_active(False)
  
  def radio_feed_change_real(self, widget=None, data=None):
    self.log.debug("radio_feed_change real")
    if self.feed_radio != "real":
      self.feed_radio = "real"
      
  def radio_feed_change_test(self, widget=None, data=None):
    self.log.debug("radio_feed_change test")
    if self.feed_radio != "test":
      self.feed_radio = "test"
      
  def radio_feed_change_file(self, widget=None, data=None):
    self.log.debug("radio_feed_change file")
    if self.feed_radio != "file":
      self.feed_radio = "file"
  
  def change_manual_control(self, widget=None, data=None):
    self.log.debug("change_manual_control")
    if widget.get_active():
      self.log.warning("Request to chnage to manual")
      widget.set_label("Automatic")
      for child in self.table_manualControl.get_children():
        if child != widget:
          child.show()
          if type(child) == gtk.VScale():
            child.set_value( self.robot.get_power() )
    else:
      self.log.warning("Request to chnage to automatic")
      widget.set_label("Manual")
      for child in self.table_manualControl.get_children():
        if child != widget:
          child.hide()
  
  def manual_power_change(self, widget=None, data=None):
    self.log.debug("manual_power_change")
    self.robot.set_power( widget.get_value() )
  
  def on_manual_robot_control_up(self, widget=None, data=None):
    self.robot.up()
  def on_manual_robot_control_down(self, widget=None, data=None):
    self.robot.down()
  def on_manual_robot_control_stop(self, widget=None, data=None):
    self.robot.stop()
  def on_manual_robot_control_left(self, widget=None, data=None):
    self.robot.left()
  def on_manual_robot_control_right(self, widget=None, data=None):
    self.robot.right()
  def on_manual_robot_control_kick(self, widget=None, data=None):
    self.robot.kick()
  def on_manual_robot_control_buzz(self, widget=None, data=None):
    self.robot.buzz()
    
  def __del__(self):
    self.log.info("__del__")
    self.robot = None
Exemplo n.º 7
0
class Application(Frame):
  
  MAX_MOTOR_POWER = 127
  BT_ADDRESS = "00:16:53:08:A0:E6"
  
  def __init__(self, master=None):
    Frame.__init__(self, master)
    self.pack()
    self.__createWidgets()
    self.bind_all('<Key>', self.__keypress)
    self.robot = None
  
  def __send_command_up(self):
    if self.robot != None:
      self.robot.up()
  def __send_command_down(self):
    if self.robot != None:
      self.robot.down()
  def __send_command_left(self):
    if self.robot != None:
      self.robot.left()
  def __send_command_right(self):
    if self.robot != None:
      self.robot.right()
  def __send_command_stop(self):
    if self.robot != None:
      self.robot.stop()
  def __send_command_kick(self):
    if self.robot != None:
      self.robot.kick()
  def __send_command_buzz(self):
    if self.robot != None:
      self.robot.buzz()
  def __send_command_power(self, value):
    if self.robot != None:
      self.robot.set_power(value)
  
  def __connect(self):
    self.button_connect["text"] = "Connecting"
    try:
      # first try to find are know robot
      self.robot = Robot(host=self.BT_ADDRESS)
    except RobotNotFoundError: # TODO
      # try to find any robot
      self.robot = Robot()
    except Exception as error:
      print "Robot Error" # + str(error)
      self.button_connect["text"] = "Connect"
      self.button_connect["state"] = "active"
      raise error
    
    self.scale_power.set(self.robot.get_power())
    self.button_up["state"] = "active"
    self.button_dn["state"] = "active"
    self.button_le["state"] = "active"
    self.button_ri["state"] = "active"
    self.button_st["state"] = "active"
    self.button_bz["state"] = "active"
    self.scale_power["state"] = "active"
    self.button_connect["state"] = "disabled"
    self.button_connect["text"] = "Connected"

  def __createWidgets(self):
    self.QUIT = Button(self)
    self.QUIT["text"] = "QUIT"
    self.QUIT["command"] =  self.quit

    self.QUIT.pack({"side": "bottom"})
    
    self.button_up = Button(self)
    self.button_up["text"] = "Up"
    self.button_up["command"] = self.__send_command_up
    self.button_up["state"] = "disabled"
    
    self.button_dn = Button(self)
    self.button_dn["text"] = "Down"
    self.button_dn["command"] = self.__send_command_down
    self.button_dn["state"] = "disabled"
    
    self.button_le = Button(self)
    self.button_le["text"] = "Left"
    self.button_le["command"] = self.__send_command_left
    self.button_le["state"] = "disabled"
    
    self.button_ri = Button(self)
    self.button_ri["text"] = "Right"
    self.button_ri["command"] = self.__send_command_right
    self.button_ri["state"] = "disabled"
    
    self.button_st = Button(self)
    self.button_st["text"] = "Stop"
    self.button_st["command"] = self.__send_command_stop
    self.button_st["state"] = "disabled"
    
    self.button_bz = Button(self)
    self.button_bz["text"] = "Buzz"
    self.button_bz["command"] = self.__send_command_buzz
    self.button_bz["state"] = "disabled"
    
    self.button_connect = Button(self)
    self.button_connect["text"] = "Connect"
    self.button_connect["command"] = self.__connect
    
    self.scale_power = Scale(self)
    self.scale_power["from_"] = -1 * self.MAX_MOTOR_POWER
    self.scale_power["to"] = self.MAX_MOTOR_POWER
    self.scale_power["orient"] = "horizontal"
    self.scale_power["command"] = self.__send_command_power
    self.scale_power["state"] = "disabled"
    
    self.button_connect.pack({"side": "bottom"})
    self.scale_power.pack({"side": "bottom"})
    self.button_bz.pack({"side": "bottom"})
    self.button_up.pack({"side": "top"})
    self.button_dn.pack({"side": "bottom"})
    self.button_le.pack({"side": "left"})
    self.button_ri.pack({"side": "right"})
    self.button_st.pack({"side": "top"})

  def __keypress(self, event):
    if event.keysym == 'Escape':
      root.destroy()    
    elif event.keysym == 'Up':
      self.__send_command_up()
    elif event.keysym == 'Down':
      self.__send_command_down()
    elif event.keysym == 'Left':
      self.__send_command_left()
    elif event.keysym == 'Right':
      self.__send_command_right()
    elif event.keysym == 'space':
      self.__send_command_kick()
    elif event.keysym == 's':
      self.__send_command_stop()
    elif event.keysym == 'b':
      self.__send_command_buzz()
    elif event.keysym == 'c':
      self.__connect()