Rose-Hulman Robotics Team

Changeset 449

Show
Ignore:
Timestamp:
03/10/09 20:18:35 (3 years ago)
Author:
mosttw
Message:

Added get gain button

Location:
trunk/software/rb
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/gui/gui.glade

    r445 r449  
    11<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    22<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> 
    3 <!--Generated with glade3 3.4.5 on Sat Mar  7 02:00:15 2009 --> 
     3<!--Generated with glade3 3.4.5 on Tue Mar 10 19:58:15 2009 --> 
    44<glade-interface> 
    55  <widget class="GtkWindow" id="window"> 
     
    166166                        <property name="visible">True</property> 
    167167                        <property name="can_focus">True</property> 
    168                         <property name="label" translatable="yes">Set Left</property> 
     168                        <property name="label" translatable="yes">Left MC</property> 
    169169                        <property name="response_id">0</property> 
    170170                        <property name="active">True</property> 
     
    176176                        <property name="visible">True</property> 
    177177                        <property name="can_focus">True</property> 
    178                         <property name="label" translatable="yes">Set Right</property> 
     178                        <property name="label" translatable="yes">Right MC</property> 
    179179                        <property name="response_id">0</property> 
    180180                        <property name="active">True</property> 
     
    186186                    </child> 
    187187                    <child> 
    188                       <widget class="GtkButton" id="gain_button"> 
     188                      <widget class="GtkButton" id="gain_get_button"> 
     189                        <property name="visible">True</property> 
     190                        <property name="can_focus">True</property> 
     191                        <property name="receives_default">True</property> 
     192                        <property name="label" translatable="yes">Get Gains</property> 
     193                        <property name="response_id">0</property> 
     194                        <signal name="clicked" handler="gain_get_cb"/> 
     195                      </widget> 
     196                      <packing> 
     197                        <property name="position">2</property> 
     198                      </packing> 
     199                    </child> 
     200                    <child> 
     201                      <widget class="GtkButton" id="gain_set_button"> 
    189202                        <property name="visible">True</property> 
    190203                        <property name="can_focus">True</property> 
     
    195208                      </widget> 
    196209                      <packing> 
    197                         <property name="position">2</property> 
     210                        <property name="position">3</property> 
    198211                      </packing> 
    199212                    </child> 
     
    208221                      </widget> 
    209222                      <packing> 
    210                         <property name="position">3</property> 
     223                        <property name="position">4</property> 
    211224                      </packing> 
    212225                    </child> 
  • trunk/software/rb/gui/gui.py

    r445 r449  
    3636                 
    3737                self.init_drive() 
    38                 self.init_gps() 
    39                 self.init_microstrain() 
     38                #self.init_gps() 
     39                #self.init_microstrain() 
    4040                self.init_wiimote() 
    4141                self.transcript = TranscriptLogger('/tmp/rblog.txt', 
     
    146146                return True 
    147147 
     148        def get_motor_checkboxes(self): 
     149                ''' 
     150                Get the values of the motor checkboxes. 
     151                ''' 
     152                left = self.builder.get_object("gain_left_check").get_active() 
     153                right = self.builder.get_object("gain_right_check").get_active() 
     154                return left, right 
     155 
     156        def gain_get_cb(self, widget=None, data=None): 
     157                ''' 
     158                Callback to get the current gains of the motor controllers and 
     159                populate the boxes. 
     160                ''' 
     161                left, right = self.get_motor_checkboxes() 
     162                if not left and not right: 
     163                        return 
     164                 
     165                kp_box = self.builder.get_object("gain_value_kp") 
     166                ki_box = self.builder.get_object("gain_value_ki") 
     167                kd_box = self.builder.get_object("gain_value_kd") 
     168                 
     169                lgains, rgains = self.drive.getgain(left or None, right or None) 
     170                kp, ki, kd = lgains if left else rgains 
     171                 
     172                kp_box.set_value(str(kp)) 
     173                ki_box.set_value(str(ki)) 
     174                kd_box.set_value(str(kd)) 
     175 
    148176        def gain_set_cb(self, widget=None, data=None): 
    149177                ''' 
     
    155183                gains = (kp, ki, kd) 
    156184                 
    157                 left = gains if self.builder.get_object("gain_left_check").get_active() else None 
    158                 right = gains if self.builder.get_object("gain_right_check").get_active() else None 
     185                left, right = self.get_motor_checkboxes() 
    159186                if left or right: 
    160                         self.drive.setgain(left, right) 
     187                        self.drive.setgain(gains if left else None, 
     188                                                                gains if right else None) 
    161189         
    162190        def gain_eeprom_write_cb(self, widget=None, data=None): 
  • trunk/software/rb/gui/gui.xml

    r445 r449  
    11<?xml version="1.0"?> 
    2 <!--Generated with glade3 3.4.5 on Sat Mar  7 02:00:15 2009 --> 
     2<!--Generated with glade3 3.4.5 on Tue Mar 10 19:58:15 2009 --> 
    33<interface> 
    44  <object class="GtkAdjustment" id="adjustment1"> 
     
    184184                        <property name="visible">True</property> 
    185185                        <property name="can_focus">True</property> 
    186                         <property name="label" translatable="yes">Set Left</property> 
     186                        <property name="label" translatable="yes">Left MC</property> 
    187187                        <property name="active">True</property> 
    188188                        <property name="draw_indicator">True</property> 
     
    193193                        <property name="visible">True</property> 
    194194                        <property name="can_focus">True</property> 
    195                         <property name="label" translatable="yes">Set Right</property> 
     195                        <property name="label" translatable="yes">Right MC</property> 
    196196                        <property name="active">True</property> 
    197197                        <property name="draw_indicator">True</property> 
     
    202202                    </child> 
    203203                    <child> 
    204                       <object class="GtkButton" id="gain_button"> 
     204                      <object class="GtkButton" id="gain_get_button"> 
     205                        <property name="visible">True</property> 
     206                        <property name="can_focus">True</property> 
     207                        <property name="receives_default">True</property> 
     208                        <property name="label" translatable="yes">Get Gains</property> 
     209                        <signal handler="gain_get_cb" name="clicked"/> 
     210                      </object> 
     211                      <packing> 
     212                        <property name="position">2</property> 
     213                      </packing> 
     214                    </child> 
     215                    <child> 
     216                      <object class="GtkButton" id="gain_set_button"> 
    205217                        <property name="visible">True</property> 
    206218                        <property name="can_focus">True</property> 
     
    210222                      </object> 
    211223                      <packing> 
    212                         <property name="position">2</property> 
     224                        <property name="position">3</property> 
    213225                      </packing> 
    214226                    </child> 
     
    222234                      </object> 
    223235                      <packing> 
    224                         <property name="position">3</property> 
     236                        <property name="position">4</property> 
    225237                      </packing> 
    226238                    </child> 
  • trunk/software/rb/wiimote.py

    r445 r449  
    3939class Wiimote(object): 
    4040        ''' 
    41         Controller for Wiimote control of the robot.  Because cwiid is 
    42         sensitive to what thread things are run in (in particular, the 
    43         ``cwiid.Wiimote`` class must be instantiated in the main 
    44         thread) some contortions are necessary to accomodate it. 
     41        Navigator that permits Wiimote control of the robot.  Interfaces with 
     42        the controller object to  
    4543        ''' 
    4644 
     
    8987 
    9088        def stop(self): 
    91                 if self.controller.navigator == 'wiimote': 
    92                         log_info('Wiimote: Switched navigator to manual') 
    93                         self.controller.set_navigator('manual') 
     89                if self.controller.navigator in ('wiimote', 'autonomous'): 
     90                        log_info('Wiimote: Set controller to stop because of disconnect') 
     91                        self.controller.set_navigator('stop') 
    9492                self.wm.close() 
    9593                self.wm = None 
     
    104102                            time.sleep(.1) 
    105103 
    106         # FIXME: Integrate this somehow 
    107104        def _control(self): 
    108105                ''' 
     
    134131                                        if data & BTN_A: 
    135132                                                if self.controller.navigator != 'autonomous': 
     133                                                        log_info('Wiimote: Switching to autonomous navigator') 
    136134                                                        self.controller.set_navigator('autonomous') 
    137                                                         log_info('Wiimote: Switched to autonomous navigator') 
     135                                                else: 
     136                                                        log_info('Wiimote: Switching to wiimote navigator') 
     137                                                        self.controller.set_navigator('wiimote') 
    138138                                elif type == MESG_NUNCHUK: 
    139139                                        self.stick = data['stick'] 
    140140                except Exception, e: 
    141                         print e 
    142                         self.running = False 
     141                        log_error("Wiimote: handle_mesg exception: %r" % e) 
     142                        self.stop() 
    143143 
    144144 
    145 if __name__ == '__main__': 
    146         wm = Wiimote()