Rose-Hulman Robotics Team

Changeset 431

Show
Ignore:
Timestamp:
02/25/09 23:53:02 (3 years ago)
Author:
mosttw
Message:

Added controller mode stuff

Location:
trunk/software/rb
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/controller.py

    r430 r431  
    44class Controller(): 
    55        def __init__(self): 
    6                 self.mode = "stop" 
    7                 #self.drive = rb.drive.FakeDrive(rbconfig.left_motor_port, 
    8                 #                               rbconfig.right_motor_port) 
    9                 self.drive = rb.drive.Drive(rbconfig.left_motor_port, 
    10                                             rbconfig.right_motor_port) 
     6                self.mode = None 
     7                self.drive = rb.drive.FakeDrive(rbconfig.left_motor_port, 
     8                                                rbconfig.right_motor_port) 
     9                #self.drive = rb.drive.Drive(rbconfig.left_motor_port, 
     10                #                            rbconfig.right_motor_port) 
    1111         
    1212        def set_mode(self, mode): 
  • trunk/software/rb/drive.py

    r424 r431  
    221221                log_debug("MockDrive: left  motor speed % 3.03f" % left) 
    222222                log_debug("MockDrive: right motor speed % 3.03f" % right) 
    223                 self.left.target = left 
    224                 self.right.target = right 
     223                self.left.target = clip(left,  -1.0, 1.0) 
     224                self.right.target = clip(right,  -1.0, 1.0) 
    225225         
    226226        def getspeed(self): 
  • trunk/software/rb/gui/analog.py

    r425 r431  
    99 
    1010                self.controller = controller 
    11  
     11                self.enabled = False 
    1212                # Register callbacks 
    1313                #connect("motor:speed_changed", self.redraw) 
     
    3434                context = self.window.cairo_create() 
    3535 
    36                 # Draw dimond 
     36                # Draw diamond 
    3737                context.set_source_rgb(0, 254, 0) 
    3838                context.move_to(w/2, 0) 
     
    4141                context.line_to(w, h/2) 
    4242                context.fill() 
    43  
    44                 # Draw Target Speed 
    45                 x = float(self.controller.drive.left.target - self.controller.drive.right.target) 
    46                 y = float(self.controller.drive.left.target + self.controller.drive.right.target) 
    47                 #~ log_debug("left=%f, right=%f, x=%f, y=%f" % 
    48                                 #~ (self.controller.drive.left.target, self.controller.drive.right.target, 
    49                                         #~ ( x/4+0.5), (-y/4+0.5))) 
    50                 x =  ( x/4+0.5) * w 
    51                 y =  (-y/4+0.5) * h 
    52                 context.set_source_rgb(0,0,255) 
    53                 context.arc(x, y, 5, 0, 2*pi) 
    54                 context.fill() 
     43                 
     44                if self.enabled: 
     45                        # Draw Target Speed 
     46                        x = float(self.controller.drive.left.target - self.controller.drive.right.target) 
     47                        y = float(self.controller.drive.left.target + self.controller.drive.right.target) 
     48                        #log_debug("left=%f, right=%f, x=%f, y=%f" % 
     49                                        #(self.controller.drive.left.target, self.controller.drive.right.target, 
     50                                                #( x/4+0.5), (-y/4+0.5))) 
     51                        x =  ( x/4+0.5) * w 
     52                        y =  (-y/4+0.5) * h 
     53                        context.set_source_rgb(0,0,255) 
     54                        context.arc(x, y, 5, 0, 2*pi) 
     55                        context.fill() 
    5556 
    5657                # Draw Current Speed 
     
    6566         
    6667        def motion_cb(self, da, event): 
     68                if not self.enabled: 
     69                        return 
    6770                if (event.type != gtk.gdk.BUTTON_PRESS and 
    6871                    event.state & gtk.gdk.BUTTON1_MASK == 0): 
     
    7881                r = y-x 
    7982 
    80                 log_debug("\tgui: x=%f, y=%f, l=%f, r=%f" % (x,y,l,r)) 
     83                #log_debug("\tgui: x=%f, y=%f, l=%f, r=%f" % (x,y,l,r)) 
    8184                self.controller.set_speed(l, r) 
  • trunk/software/rb/gui/gui.py

    r430 r431  
    5151 
    5252                self.window.show_all() 
     53                self.set_mode('manual') 
    5354                gtk.main() 
    5455 
     
    6263                elif mode == 'manual': 
    6364                        print "Switching to manual mode" 
     65                 
     66                self.analog.enabled = (mode == 'manual') 
     67                 
    6468 
    6569        def key_press_cb(self, widget, event): 
  • trunk/software/rb/shell.py

    r420 r431  
    3030        ''' 
    3131        A robot control shell. 
    32          
    33         The rbconfig variable ``shell_components`` permits automatic loading 
    34         of certain components when the shell is started. 
    35          
    36         TODO: Needs some way of loading sets of commands dynamically, e.g., 
    37         so that motor-related commands can be made present only when their 
    38         dependencies are running. 
    3932        ''' 
    4033         
     
    4437                cmd.Cmd.__init__(self) 
    4538                Controller.__init__(self) 
     39                self.set_mode('manual') 
    4640                try: 
    4741                        self.cmdloop() 
     
    6660         
    6761        def do_exit(self, cmd): 
    68                 print "Goodbye. :(" 
     62                print "Goodbye." 
    6963                return True 
    7064         
    7165        def help_exit(self): 
    7266                print "Exit the shell." 
     67         
     68        do_quit = do_exit 
     69        help_quit = help_exit 
    7370         
    7471        # Loading commands from a file 
     
    145142        def do_disable(self, cmd): 
    146143                print self.drive.disable() 
     144        def help_disable(self): 
     145                print "Disable the drive" 
    147146 
    148147        def do_enable(self, cmd): 
    149148                print self.drive.enable() 
     149        def help_enable(self): 
     150                print "Enable the drive" 
    150151 
    151152        def do_getdc(self, cmd): 
     
    158159                print self.drive.getstat() 
    159160 
    160         def do_eewrite(self, cmd): 
     161        def do_eewrite(self, cmd): 
    161162                print self.drive.eewrite() 
    162163