Example #1
0
 def topic_key_callback(msg):
     d = msg.data        
     if d == C.MOVE_DOWN:
         pici.drive_straight(ser,-VELOCITYCHANGE);
     if d == C.MOVE_UP:
         pici.drive_straight(ser,VELOCITYCHANGE);
     if d == C.MOVE_LEFT:
         pici.turn(ser,ANGULARCHANGE,cw=False)
     if d == C.MOVE_RIGHT:
         pici.turn(ser,ANGULARCHANGE,cw=True)
     if d == C.FULL:
         cmd_full(ser);
         # print "full mode"
     if d == C.SONG:
         pici.playSongStart(ser)
         pici.playSongStop(ser)            
     if d == C.PASSIVE:
         cmd_passive(ser)
         # print "passive mode"
     if d == C.STOP:
         pici.stop(ser);
 def topic_key_callback(msg):
     d = msg.data        
     if d == C.MOVE_DOWN:
         pici.drive_straight(ser,-VELOCITYCHANGE);
     if d == C.MOVE_UP:
         pici.drive_straight(ser,VELOCITYCHANGE);
     if d == C.MOVE_LEFT:
         pici.turn(ser,ANGULARCHANGE,cw=False)
     if d == C.MOVE_RIGHT:
         pici.turn(ser,ANGULARCHANGE,cw=True)
     if d == C.FULL:
         cmd_full(ser);
         print "full mode"
     if d == C.SONG:
         pici.playSongStart(ser)
         pici.playSongStop(ser)            
     if d == C.PASSIVE:
         cmd_passive(ser)
         print "passive mode"
     if d == C.STOP:
         pici.stop(ser);
         print "now stop"
sBaud = 9600  # wireless
#sBaud = 57600  # wired, Create default
ser = serial.Serial(sPort, sBaud, timeout=1.0)

# Start - start, full mode, lights and song
pici.start(ser)

# Loop for some amount of time
t0 = time.time()
tEnd = 1800
while ((time.time() - t0) < tEnd):
    sensorDict = pici.getSensorsAll(ser)
    print sensorDict
    if not sensorDict:
        print "Error!  Appears that the Create is off?"
    else:
        # If we hit a bump - backup and turn for some time
        if (sensorDict['bump_left'] or sensorDict['bump_right']
                or sensorDict['virtual_wall']):
            print "Bump!"
            pici.drive(ser, -200, -200)
            sleep(1.0)

    pici.drive_straight(ser, 500)
    sleep(0.1)

# stop driving, play stop song, turn off play light
pici.stop(ser)

ser.close()
pici.start(ser)

# Loop for some amount of time
t0 = time.time()
tEnd = 1800
while ( (time.time()-t0) < tEnd):
    sensorDict = pici.getSensorsAll(ser)
    print sensorDict
    if not sensorDict:
        print "Error!  Appears that the Create is off?"
    else:
        # If we hit a bump - backup and turn for some time
        if (sensorDict['bump_left'] or 
            sensorDict['bump_right'] or
            sensorDict['virtual_wall']):
            print "Bump!"
            pici.drive(ser,-200,-200)
            sleep(1.0)

    pici.drive_straight(ser,500)
    sleep(0.1)

# stop driving, play stop song, turn off play light
pici.stop(ser)

ser.close()