- Timestamp:
- 06/04/10 17:05:17 (20 months ago)
- Location:
- trunk/software
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/Makefile
r717 r739 27 27 scripts/calib/calibrate.py 28 28 29 test-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 37 37 SYS_API_ENUMERATION = 9 38 38 SYS_API_SYSTEM_RESUME = 10 39 40 # Manufacturer IDs 41 MANF_BROADCAST = 0 42 MANF_NATIONAL_INSTURMENTS = 1 43 MANF_TEXAS_INSTURMENTS = 2 44 MANF_DEKA = 3 39 45 40 46 logger = logging.getLogger('rb.can') … … 138 144 API_ACKNOWLEDGE = 6 139 145 140 MANF_BROADCAST = 0141 MANF_NATIONAL_INSTURMENTS = 1142 MANF_TEXAS_INSTURMENTS = 2143 MANF_DEKA = 3144 145 146 VOLTAGE_MODE_ENABLE = 0 146 147 VOLTAGE_MODE_DISABLE = 1 147 148 VOLTAGE_SET = 2 148 149 VOLTAGE_RAMP_SET = 3 150 # The voltage is a 16-bit signed integer, so +-VOLTAGE_MAX is the usable 151 # range. 152 VOLTAGE_MAX = 0xffff / 2 149 153 150 154 SPEED_MODE_ENABLE = 0 … … 167 171 168 172 class JaguarDrive(object): 169 def __init__(self, can_bus ):173 def __init__(self, can_bus, mode='voltage'): 170 174 assert can_bus is not None 171 175 self.can_bus = can_bus 172 self.left_controller_nums = [2, 3 ]176 self.left_controller_nums = [2, 3, 6] 173 177 self.right_controller_nums = [4, 5] 174 178 self.controller_nums = (self.left_controller_nums + 175 179 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): 179 184 # Configure encoder lines 180 185 for num in self.controller_nums: … … 218 223 self.can_bus.send(id) 219 224 220 def setspeed(self, l speed, rspeed):225 def setspeed(self, lvalue, rvalue): 221 226 ''' 222 227 Set the target speed of the wheels. 223 228 ''' 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)) 226 247 227 248 for num in self.left_controller_nums: 228 249 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( 229 272 api_class=API_SPEED_CONTROL, 230 273 api_index=SPEED_SET, … … 241 284 self.can_bus.send(id, float_to_fixed1616(rspeed)) 242 285 243 if __name__ == '__main__':286 def demo(): 244 287 import time 245 288 bus = CANBus('/dev/ttyS0') … … 251 294 api_class=API_VOLTAGE_CONTROL, 252 295 api_index=VOLTAGE_SET, 253 device_number= 1)296 device_number=6) 254 297 try: 255 298 print "Ramping up" 256 299 for dc in range(0, 32767, 10): 257 #bus.send(heartbeat_can_id, '')300 bus.send(heartbeat_can_id, '') 258 301 bus.send(set_voltage_can_id, struct.pack('<h', dc)) 259 302 time.sleep(0.05) … … 265 308 print "Ramping down" 266 309 for dc in range(32767, 0, -10): 267 #bus.send(heartbeat_can_id, '')310 bus.send(heartbeat_can_id, '') 268 311 bus.send(set_voltage_can_id, struct.pack('<h', dc)) 269 312 time.sleep(0.05) 270 313 314 if __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 2 2 This file contains settings for the rb module. 3 3 ''' 4 5 #from rb.vision import DTREE, HARD6 4 7 5 NONE = 'none' # Connect to actual hardware/interface … … 9 7 REAL = 'real' # Do not load anything 10 8 11 name = ' RATT' # Human-readable robot name9 name = 'Moxom\'s Master' # Human-readable robot name 12 10 log_level = 'DEBUG' 13 11 #triplog_outdir = '%(robot_name)s-%(year)s-%(month)s-%(day)sT%(hour)s.%(minute)s.%(second)s-logs' … … 26 24 27 25 camera = NONE 26 camera_gst_input = 'rtspsrc location=rtsp://192.168.27.3:554 ! decodebin' 28 27 #camera_gst_input = 'v4l2src' 29 28 camera_gst_input = 'filesrc location="/home/tomwm/Videos/Still_Alive_Typography.flv" ! decodebin' … … 47 46 wiimote = REAL 48 47 #wiimote_addr = '00:19:1D:2C:F2:37' # Tom's wiimote 49 wiimote_addr = 'e8:43:ce:9d:e9:66' 48 wiimote_addr = 'e8:43:ce:9d:e9:66' # Team's wiimote 50 49 51 50 gui = REAL

