Changeset 241
- Timestamp:
- 12/04/10 15:27:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/brainstorms/Puzzlebox/Brainstorms/Wheelchair_Control.py
r240 r241 10 10 11 11 __changelog__ = """ 12 Last Update: 2010.1 1.3012 Last Update: 2010.12.04 13 13 14 14 """ … … 37 37 DEFAULT_COMMAND = 'console' 38 38 DEFAULT_SERIAL_DEVICE = '/dev/ttyACM0' 39 40 DEFAULT_WHEELCHAIR_SPEED = 1 41 DEFAULT_WHEELCHAIR_COMMAND = 'stop' 42 39 43 ARDUINO_INITIALIZATION_TIME = 2 40 44 COMMAND_CHARACTER = 'x' 45 GUI_SLEEP_TIMER = 1 * 100 # 100ms 41 46 42 47 WHEELCHAIR_COMMANDS = { 43 'stop': '00110011', 44 'speed0': { 45 'stop': '00110011', 46 }, 47 'speed1': { 48 1: { # speed 48 49 'forward': '00110001', 49 50 'reverse': '00111011', 50 51 'left': '10110011', 51 'right': '00010011' 52 'right': '00010011', 53 'stop': '00110011', 52 54 }, 53 'speed2': {55 2: { # speed 54 56 'forward': '00110010', 55 57 'reverse': '00110111', 56 58 'left': '01110011', 57 'right': '00100011' 59 'right': '00100011', 60 'stop': '00110011', 58 61 }, 59 'speed3': {62 3: { # speed 60 63 'forward': '00110000', 61 64 'reverse': '00111111', 62 65 'left': '11110011', 63 'right': '00000011' 66 'right': '00000011', 67 'stop': '00110011', 64 68 }, 65 69 } … … 112 116 self.command = command 113 117 114 self.device = self.initializeSerial() 118 self.wheelchair_speed = DEFAULT_WHEELCHAIR_SPEED 119 self.wheelchair_command = DEFAULT_WHEELCHAIR_COMMAND 120 121 self.device = None 122 self.initializeSerial() 123 124 self.keep_running = True 115 125 116 126 … … 173 183 init_rts_cts_flow_control = 0 174 184 175 device = serial.Serial(port = self.device_address, \185 self.device = serial.Serial(port = self.device_address, \ 176 186 baudrate = baudrate, \ 177 187 bytesize = init_byte_size, \ … … 182 192 timeout = timeout) 183 193 184 device.write('%s%s' % (COMMAND_CHARACTER, WHEELCHAIR_COMMANDS['stop'])) 194 195 self.send_command(self.wheelchair_speed, self.wheelchair_command) 196 197 time.sleep(ARDUINO_INITIALIZATION_TIME) 198 199 return(device) 200 201 202 ################################################################## 203 204 def send_command(self, speed, command): 205 206 self.device.write('%s%s' % (COMMAND_CHARACTER, \ 207 WHEELCHAIR_COMMANDS[speed][command])) 208 185 209 if self.DEBUG: 186 print "--> Wheelchair Command:", 187 print 'stop' 188 189 time.sleep(ARDUINO_INITIALIZATION_TIME) 190 191 return(device) 192 193 194 ################################################################## 195 196 def processCommand(self): 197 198 if (self.command == 'console'): 199 self.console_control() 200 201 #elif (self.command == 'neutral'): 202 #self.mode = 'write' 203 #self.neutral() 210 print "--> Wheelchair Command: %s [Speed %i]" % \ 211 (command, speed) 212 213 self.wheelchair_speed = speed 214 self.wheelchair_command = command 204 215 205 216 … … 254 265 def console_control(self): 255 266 256 #device = self.initializeSerial() 257 267 if (sys.platform == 'win32'): 268 if self.DEBUG: 269 print "---> Wheelchair Control: Console mode unavailable under Windows" 270 271 self.exitThread() 272 273 258 274 MYGETCH = Getch() 259 275 260 276 #initAlarm() 261 277 262 278 self.stopBot() 263 264 speed = 1279 280 speed = DEFAULT_WHEELCHAIR_SPEED 265 281 while True: 266 282 cmd = MYGETCH() … … 281 297 ################################################################## 282 298 299 #def gui_control(self): 300 301 #while self.keep_running: 302 303 #QtCore.QThread.msleep(GUI_SLEEP_TIMER) 304 305 306 ################################################################## 307 308 def processCommand(self): 309 310 if (self.command == 'console'): 311 self.console_control() 312 313 #elif (self.command == 'gui'): 314 #self.gui_control() 315 316 317 ################################################################## 318 283 319 def run(self): 284 320
Note: See TracChangeset
for help on using the changeset viewer.