Changeset c2cf7f2 in robotics
- Timestamp:
- 06/14/14 08:33:28 (8 years ago)
- Branches:
- master
- Children:
- 7868465
- Parents:
- 18a0139
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
car/python/Car_Demo.py
rb821883 rc2cf7f2 7 7 8 8 __changelog__ = """\ 9 Last Update: 2014.06. 099 Last Update: 2014.06.10 10 10 """ 11 11 … … 13 13 """ 14 14 15 import string, time15 import string, sys, time 16 16 import serial 17 import signal 17 18 18 19 #import Configuration as configuration 19 20 20 21 #if configuration.ENABLE_PYSIDE: 21 #try:22 #import PySide as PyQt423 #from PySide import QtCore24 #except Exception, e:25 #print "ERROR: Exception importing PySide:",26 #print e22 try: 23 import PySide as PyQt4 24 from PySide import QtCore 25 except Exception, e: 26 print "ERROR: Exception importing PySide:", 27 print e 27 28 #configuration.ENABLE_PYSIDE = False 28 29 #else: … … 45 46 TAG = 'Robotics:Car' 46 47 47 #DEFAULT_COMMAND = 'neutral'48 DEFAULT_COMMAND = 'neutral' 48 49 #DEFAULT_SERIAL_DEVICE = '/dev/ttyACM0' 49 50 DEFAULT_SERIAL_DEVICE_STEPPER = '/dev/ttyACM0' … … 64 65 65 66 LOOP_TIMER = 80 # 80 ms 67 68 KEY_CODES = { 69 'hover': 'muf008001t100020y000000p000000d', \ 70 'forward': 'mff008001t100020y000000p063005d', \ 71 'backward': 'mbf008001t100020y000000p015003d', \ 72 'left': 'mlf008001t100020y127004p000000d', \ 73 'right': 'mrf008001t100020y000008p000000d', \ 74 'land': 'O', \ 75 } 66 76 67 77 … … 93 103 self.device_pyramid = None 94 104 95 self.configuration = configuration105 #self.configuration = configuration 96 106 97 107 self.name = "Robotics-Car-Demo" … … 186 196 init_rts_cts_flow_control = 0 187 197 188 self.device_stepper = serial.Serial(port = self.serial_port_stepper, \189 baudrate = baudrate, \190 bytesize = init_byte_size, \191 parity = init_parity, \192 stopbits = init_stopbits, \193 xonxoff = init_software_flow_control, \194 rtscts = init_rts_cts_flow_control, \195 timeout = timeout)198 #self.device_stepper = serial.Serial(port = self.serial_port_stepper, \ 199 ##baudrate = baudrate, \ 200 ##bytesize = init_byte_size, \ 201 ##parity = init_parity, \ 202 ##stopbits = init_stopbits, \ 203 ##xonxoff = init_software_flow_control, \ 204 ##rtscts = init_rts_cts_flow_control, \ 205 ##timeout = timeout) 196 206 197 207 self.device_pyramid = serial.Serial(port = self.serial_port_pyramid, \ … … 203 213 rtscts = init_rts_cts_flow_control, \ 204 214 timeout = timeout) 215 205 216 #self.land() 217 self.left() 206 218 207 219 time.sleep(ARDUINO_INITIALIZATION_TIME) … … 239 251 # Issue command 240 252 if self.DEBUG: 241 print '--> [ TAG] Land ("O")'253 print '--> [%s] Land ("O")' % TAG 242 254 243 255 self.command_queue.append("O") 244 #self.device.write("O") 256 #self.device_pyramid.write("O") 257 258 259 ################################################################## 260 261 def left(self): 262 263 "Drive left" 264 265 # Issue command 266 if self.DEBUG: 267 print '--> [%s] Left ("mlf008001t100020y127004p000000d")' % TAG 268 269 self.command_queue.append("mlf008001t100020y127004p000000d") 270 #self.device_pyramid.write("O") 271 272 273 ################################################################## 274 275 def right(self): 276 277 "Drive right" 278 279 # Issue command 280 if self.DEBUG: 281 print '--> [%s] Left ("mrf008001t100020y000008p000000d")' % TAG 282 283 self.command_queue.append("mrf008001t100020y000008p000000d") 284 #self.device_pyramid.write("O") 245 285 246 286 … … 264 304 265 305 if self.DEBUG: 266 print "--> [ TAG] Sending Orbit Command:",306 print "--> [%s] Sending Orbit Command:" % TAG, 267 307 print command 268 308 … … 385 425 self.land() 386 426 387 else: 388 self.device.write(command) 427 elif (command =='left'): 428 self.left() 429 430 elif (command == 'right'): 431 self.right() 432 433 434 else: 435 self.device_pyramid.write(command) 436 437 438 ################################################################## 439 440 def cycleTest(self): 441 442 print "cycleTest(On)" 443 print "..." 444 self.serial_port_pyramid.write('P\n') 445 print "written: P\r" 446 #QtCore.QThread.msleep(1000) 447 time.sleep(1) 448 449 print "cycleTest(Off)" 450 self.serial_port_pyramid.write('O\n') 451 print "written: O\r" 452 #QtCore.QThread.msleep(1000) 453 time.sleep(1) 454 455 456 ################################################################## 457 458 def cycleDemo(self): 459 460 print "cycleDemo()" 461 462 self.serial_port_stepper.write('r090\r') 463 self.serial_port_pyramid.write(KEY_CODES['right'] + '\r') 464 465 self.serial_port_stepper.write('l090\r') 466 QtCore.QThread.msleep(1000) 467 self.serial_port_pyramid.write(KEY_CODES['left'] + '\r') 468 QtCore.QThread.msleep(1000) 389 469 390 470 … … 394 474 395 475 while self.keep_running: 476 477 #self.cycleDemo() 478 479 #self.cycleTest() 480 396 481 397 482 #if self.command_queue != []: … … 460 545 461 546 # Collect default settings and command line parameters 462 device = DEFAULT_SERIAL_DEVICE 547 device = DEFAULT_SERIAL_DEVICE_PYRAMID 463 548 mode = DEFAULT_MODE 464 549 command = DEFAULT_COMMAND
Note: See TracChangeset
for help on using the changeset viewer.