Example #1
0
    def on_networktables_updated(self, key, value):
        '''
            Called when NetworkTables keys are updated
        '''

        if key == 'Catapult Values':
            print 'no'
            return

        # if the value is None, assume it is a StringArray
        if value is None:
            try:
                value = network_tables.get_string_array(self.table, key)
            except:
                pass

        # if there's a value we're displaying, then change its
        # contents based on this. or something.

        update_fn = self.tracked_keys.get(key)
        if update_fn is not None:
            print "Autonomous tuner update:", key, value
            # .. beware of loop?
            update_fn(value)
 def on_networktables_updated(self, key, value):
     '''
         Called when NetworkTables keys are updated
     '''
     
     if key == 'Catapult Values':
         print 'no'
         return
     
     # if the value is None, assume it is a StringArray
     if value is None:
         try:
             value = network_tables.get_string_array(self.table, key)
         except:
             pass
     
     # if there's a value we're displaying, then change its
     # contents based on this. or something. 
     
     update_fn = self.tracked_keys.get(key)
     if update_fn is not None:
         print "Autonomous tuner update:", key, value
         # .. beware of loop?
         update_fn(value)
Example #3
0
    def update_autonomous_tunables(self, mode_name):

        self.clear()

        # nothing else needs to happen here
        if mode_name == 'None':
            return

        # put new things in
        # -> TODO: There's some kind of bug with updating network tables array
        #          values. Most unfortunate. It seems to work most of the time
        #          however, so good enough for now

        # find the ordering of duration items
        try:
            durations = network_tables.get_string_array(
                self.table, mode_name + '_durations')
        except:
            durations = []

        try:
            descriptions = network_tables.get_string_array(
                self.table, mode_name + '_descriptions')
        except:
            descriptions = []

        # could handle this gracefully, but no
        if len(descriptions) != len(durations):
            descriptions = [''] * len(durations)

        for duration_name, description in zip(durations, descriptions):

            key = '%s\\%s_duration' % (mode_name, duration_name)

            widget = self.__create_widget(duration_name, key, 0,
                                          self.AUTON_MAX)

            if widget is None:
                continue

            if description != '':
                widget.set_tooltip_text(description)

            self.timing_settings_vbox.pack_start(widget, False, True)

        if len(durations) > 0:
            self.timing_settings_vbox.show_all()

        # now setup the tunables
        try:
            tunables = network_tables.get_string_array(self.table,
                                                       mode_name + '_tunables')
        except:
            tunables = []

        for tunable_name in tunables:

            tunable_name, vmin, vmax = self.__parse_name(tunable_name)
            key = '%s\\%s' % (mode_name, tunable_name)

            widget = self.__create_widget(tunable_name, key, vmin, vmax)

            if widget is None:
                continue

            self.settings_vbox.pack_start(widget, False, True)

        if len(tunables) > 0:
            self.settings_vbox.show_all()

        # setup update functions
        def updated_vars(v):
            self.update_autonomous_tunables(mode_name)

        self.tracked_keys[mode_name + '_durations'] = updated_vars
        self.tracked_keys[mode_name + '_tunables'] = updated_vars
 def update_autonomous_tunables(self, mode_name):
     
     self.clear()
     
     # nothing else needs to happen here
     if mode_name == 'None':
         return
     
     # put new things in
     # -> TODO: There's some kind of bug with updating network tables array
     #          values. Most unfortunate. It seems to work most of the time
     #          however, so good enough for now
     
     # find the ordering of duration items
     try:
         durations = network_tables.get_string_array(self.table, mode_name + '_durations')
     except:
         durations = []
         
     try:
         descriptions = network_tables.get_string_array(self.table, mode_name + '_descriptions')
     except:
         descriptions = []
         
     # could handle this gracefully, but no    
     if len(descriptions) != len(durations):
         descriptions = [''] * len(durations)
     
     for duration_name, description in zip(durations, descriptions):
         
         key = '%s\\%s_duration' % (mode_name, duration_name)
         
         widget = self.__create_widget(duration_name, key, 0, self.AUTON_MAX)
         
         if widget is None:
             continue
             
         if description != '':
             widget.set_tooltip_text(description)
         
         self.timing_settings_vbox.pack_start(widget, False, True)
 
     if len(durations) > 0:
         self.timing_settings_vbox.show_all()
     
     # now setup the tunables
     try:
         tunables = network_tables.get_string_array(self.table, mode_name + '_tunables')
     except:
         tunables = []
     
     for tunable_name in tunables:
         
         tunable_name, vmin, vmax = self.__parse_name(tunable_name)
         key = '%s\\%s' % (mode_name, tunable_name)
         
         widget = self.__create_widget(tunable_name, key, vmin, vmax)
         
         if widget is None:
             continue
     
         self.settings_vbox.pack_start(widget, False, True)
     
     if len(tunables) > 0:
         self.settings_vbox.show_all()
         
     # setup update functions
     def updated_vars(v):
         self.update_autonomous_tunables(mode_name)
     
     self.tracked_keys[mode_name + '_durations'] = updated_vars
     self.tracked_keys[mode_name + '_tunables'] = updated_vars