Rose-Hulman Robotics Team

Changeset 739 for trunk

Show
Ignore:
Timestamp:
06/04/10 17:05:17 (20 months ago)
Author:
mosttw
Message:

More work on motor controllers and updated rbconfig

Location:
trunk/software
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/Makefile

    r717 r739  
    2727        scripts/calib/calibrate.py 
    2828 
     29test-images: all rb/vision/_processing.c 
     30        rm -f test-images/*.out.png test-images/*.json 
     31        rm -f test-images2/*.out.png test-images2/*.json 
     32        rm -f test-images3/*.out.png test-images/*.json 
     33        ./test_vision.py test-images/*.{jpeg,jpg} 
     34        ./test_vision.py test-images2/*.png 
     35        ./test_vision.py test-images3/*.jpg 
  • trunk/software/rb/can.py

    r738 r739  
    3737SYS_API_ENUMERATION = 9 
    3838SYS_API_SYSTEM_RESUME = 10 
     39 
     40# Manufacturer IDs 
     41MANF_BROADCAST = 0 
     42MANF_NATIONAL_INSTURMENTS = 1 
     43MANF_TEXAS_INSTURMENTS = 2 
     44MANF_DEKA = 3 
    3945 
    4046logger = logging.getLogger('rb.can') 
     
    138144API_ACKNOWLEDGE = 6 
    139145 
    140 MANF_BROADCAST = 0 
    141 MANF_NATIONAL_INSTURMENTS = 1 
    142 MANF_TEXAS_INSTURMENTS = 2 
    143 MANF_DEKA = 3 
    144  
    145146VOLTAGE_MODE_ENABLE = 0 
    146147VOLTAGE_MODE_DISABLE = 1 
    147148VOLTAGE_SET = 2 
    148149VOLTAGE_RAMP_SET = 3 
     150# The voltage is a 16-bit signed integer, so +-VOLTAGE_MAX is the usable 
     151# range. 
     152VOLTAGE_MAX = 0xffff / 2 
    149153 
    150154SPEED_MODE_ENABLE = 0 
     
    167171 
    168172class JaguarDrive(object): 
    169     def __init__(self, can_bus): 
     173    def __init__(self, can_bus, mode='voltage'): 
    170174        assert can_bus is not None 
    171175        self.can_bus = can_bus 
    172         self.left_controller_nums = [2, 3] 
     176        self.left_controller_nums = [2, 3, 6] 
    173177        self.right_controller_nums = [4, 5] 
    174178        self.controller_nums = (self.left_controller_nums + 
    175179                                self.right_controller_nums) 
    176         self.init_controllers() 
    177  
    178     def init_controllers(self): 
     180        if mode == 'speed': 
     181            self.init_speed_control() 
     182 
     183    def init_speed_control(self): 
    179184        # Configure encoder lines 
    180185        for num in self.controller_nums: 
     
    218223            self.can_bus.send(id) 
    219224     
    220     def setspeed(self, lspeed, rspeed): 
     225    def setspeed(self, lvalue, rvalue): 
    221226        ''' 
    222227        Set the target speed of the wheels. 
    223228        ''' 
    224         # TODO: Adjust lspeed and rspeed based on wheel diameter, 
    225         # and encoder gear ratio 
     229        assert lvalue <= 1.0 
     230        assert lvalue >= -1.0 
     231        assert rvalue <= 1.0 
     232        assert rvalue >= -1.0 
     233 
     234        self.set_voltage(lvalue, rvalue) 
     235 
     236    def set_voltage(self, lvoltage, rvoltage): 
     237        ''' 
     238        Set the left and right voltages, as floats from -1 to 1. 
     239        ''' 
     240        assert lvoltage <= 1.0 
     241        assert lvoltage >= -1.0 
     242        assert rvoltage <= 1.0 
     243        assert rvoltage >= -1.0 
     244 
     245        lvalue = struct.pack('<h', int(lvoltage * VOLTAGE_MAX)) 
     246        rvalue = struct.pack('<h', int(rvoltage * VOLTAGE_MAX)) 
    226247 
    227248        for num in self.left_controller_nums: 
    228249            id = build_can_id( 
     250                api_class=API_VOLTAGE_CONTROL, 
     251                api_index=VOLTAGE_SET, 
     252                device_number=num 
     253            ) 
     254            self.can_bus.send(id, lvalue) 
     255 
     256        for num in self.right_controller_nums: 
     257            id = build_can_id( 
     258                api_class=API_VOLTAGE_CONTROL, 
     259                api_index=VOLTAGE_SET, 
     260                device_number=num 
     261            ) 
     262            self.can_bus.send(id, rvalue) 
     263 
     264    def set_speed(self, lspeed, rspeed): 
     265        ''' 
     266        Set the target speed of the left and right wheels, as floats 
     267        from -1 to 1. 
     268        ''' 
     269 
     270        for num in self.left_controller_nums: 
     271            id = build_can_id( 
    229272                api_class=API_SPEED_CONTROL, 
    230273                api_index=SPEED_SET, 
     
    241284            self.can_bus.send(id, float_to_fixed1616(rspeed)) 
    242285 
    243 if __name__ == '__main__': 
     286def demo(): 
    244287    import time 
    245288    bus = CANBus('/dev/ttyS0') 
     
    251294            api_class=API_VOLTAGE_CONTROL, 
    252295            api_index=VOLTAGE_SET, 
    253             device_number=1) 
     296            device_number=6) 
    254297    try: 
    255298        print "Ramping up" 
    256299        for dc in range(0, 32767, 10): 
    257             #bus.send(heartbeat_can_id, '') 
     300            bus.send(heartbeat_can_id, '') 
    258301            bus.send(set_voltage_can_id, struct.pack('<h', dc)) 
    259302            time.sleep(0.05) 
     
    265308        print "Ramping down" 
    266309    for dc in range(32767, 0, -10): 
    267         #bus.send(heartbeat_can_id, '') 
     310        bus.send(heartbeat_can_id, '') 
    268311        bus.send(set_voltage_can_id, struct.pack('<h', dc)) 
    269312        time.sleep(0.05) 
    270313 
     314if __name__ == '__main__': 
     315    demo() 
     316    import time 
     317    bus = CANBus('/dev/ttyS0') 
     318    drive = JaguarDrive(bus) 
     319    print "Vroom!" 
     320    for i in range(1, 1000): 
     321        v = i / 1000.0 
     322        drive.setspeed(v, v) 
     323        time.sleep(0.05) 
     324    print "Whoa!" 
     325    for i in range(1000, -1000, -1): 
     326        v = i / 1000.0 
     327        drive.setspeed(v, v) 
     328        time.sleep(0.05) 
     329    print "Whoa!" 
     330    for i in range(-1000, 0): 
     331        v = i / 1000.0 
     332        drive.setspeed(v, v) 
     333        time.sleep(0.05) 
     334    print "Duuuuh." 
  • trunk/software/rbconfig.py

    r724 r739  
    22This file contains settings for the rb module. 
    33''' 
    4  
    5 #from rb.vision import DTREE, HARD  
    64 
    75NONE = 'none' # Connect to actual hardware/interface  
     
    97REAL = 'real' # Do not load anything                  
    108 
    11 name              = 'RATT' # Human-readable robot name 
     9name              = 'Moxom\'s Master' # Human-readable robot name 
    1210log_level         = 'DEBUG' 
    1311#triplog_outdir    = '%(robot_name)s-%(year)s-%(month)s-%(day)sT%(hour)s.%(minute)s.%(second)s-logs' 
     
    2624 
    2725camera            = NONE 
     26camera_gst_input  = 'rtspsrc location=rtsp://192.168.27.3:554 ! decodebin' 
    2827#camera_gst_input  = 'v4l2src' 
    2928camera_gst_input  = 'filesrc location="/home/tomwm/Videos/Still_Alive_Typography.flv" ! decodebin' 
     
    4746wiimote           = REAL 
    4847#wiimote_addr      = '00:19:1D:2C:F2:37' # Tom's wiimote 
    49 wiimote_addr      = 'e8:43:ce:9d:e9:66' 
     48wiimote_addr      = 'e8:43:ce:9d:e9:66' # Team's wiimote 
    5049 
    5150gui               = REAL