예제 #1
0
def speak(msg, override=False):
    global previousMsg
    if (audioOn and msg != previousMsg) or override:
        robot.speak(msg)
    elif msg != previousMsg:
        robot.makeToast(msg)
    outputToOperator(msg)
    previousMsg = msg
예제 #2
0
def initializeBluetooth():
    robot.toggleBluetoothState(True)
    if bluetoothAddress:
        robot.bluetoothConnect(
            '00001101-0000-1000-8000-00805F9B34FB',
            bluetoothAddress)  #this is a magic UUID for serial BT devices
    robot.makeToast("Initializing Bluetooth connection")
    time.sleep(3)
예제 #3
0
def speak(msg,override=False):
  global previousMsg
  if (audioOn and msg != previousMsg) or override:
    robot.speak(msg)
  elif msg != previousMsg:
    robot.makeToast(msg)
  outputToOperator(msg)
  previousMsg=msg
예제 #4
0
def main():
  outputToOperator("Send the letter 'q' or say 'quit' to exit the program.\n")
  robot.startSensing()
  robot.startLocating()
  if outputMethod == "outputBluetooth":
    initializeBluetooth()
    readerThread = bluetoothReader()
    #TEMP REM THIS OUT UNTIL ASE FIXES BLUETOOTH HANDLING readerThread.start()
  else:
    serialReader.lifeline = re.compile(r"(\d) received")
    readerThread = serialReader()
    readerThread.start()
  global currentSpeed
  if microcontroller == "arduino":
    commandOut(str(currentSpeed))
  robot.makeToast("Initiating input method...\n")
  globals()[inputMethod]()
예제 #5
0
def main():
    outputToOperator(
        "Send the letter 'q' or say 'quit' to exit the program.\n")
    robot.startSensing()
    robot.startLocating()
    if outputMethod == "outputBluetooth":
        initializeBluetooth()
        readerThread = bluetoothReader()
        #TEMP REM THIS OUT UNTIL ASE FIXES BLUETOOTH HANDLING readerThread.start()
    else:
        serialReader.lifeline = re.compile(r"(\d) received")
        readerThread = serialReader()
        readerThread.start()
    global currentSpeed
    if microcontroller == "arduino":
        commandOut(str(currentSpeed))
    robot.makeToast("Initiating input method...\n")
    globals()[inputMethod]()
예제 #6
0
def commandParse(input):
    # Split the incoing string into a command and up to two values
    try:
        commandList = shlex.split(input)
    except:
        commandList = []
        outputToOperator("Could not parse command")
    try:
        command = commandList[0].lower()
    except IndexError:
        command = ""
    try:
        commandValue = commandList[1]
    except IndexError:
        commandValue = ""
    try:
        commandValue2 = commandList[2]
    except IndexError:
        commandValue2 = ""

    # Process known commands
    if command in ["a", "audio", "record"]:
        global audioRecordingOn
        audioRecordingOn = not audioRecordingOn
        fileName = time.strftime("/sdcard/cellbot_%Y-%m-%d_%H-%M-%S.3gp")
        if audioRecordingOn:
            outputToOperator("Starting audio recording")
            robot.makeToast("Starting audio recording")
            robot.startAudioRecording(fileName)
        else:
            robot.stopAudioRecording()
            robot.makeToast("Stopping audio recording")
            outputToOperator(
                "Stopped audio recording. Audio file located at '%s'" %
                fileName)
    elif command in ["b", "back", "backward", "backwards"]:
        speak("Moving backward")
        cmd = "w %s %s" % (currentSpeed * -10, currentSpeed * -10)
        commandOut(cmd)
    elif command in ["compass", "heading"]:
        orientToAzimuth(int(commandValue[:3]))
    elif command in ["d", "date"]:
        speak(time.strftime("Current time is %_I %M %p on %A, %B %_e, %Y"))
    elif command in ["f", "forward", "forwards", "scoot"]:
        speak("Moving forward")
        cmd = "w %s %s" % (currentSpeed * 10, currentSpeed * 10)
        commandOut(cmd)
    elif command in ["h", "hi", "hello"]:
        speak("Hello. Let's play.")
    elif command in ["l", "left"]:
        speak("Moving left")
        cmd = "w %s %s" % (currentSpeed * -10, currentSpeed * 10)
        commandOut(cmd)
    elif command in ["m", "mute", "silence"]:
        global audioOn
        audioOn = not audioOn
        speak("Audio mute toggled")
    elif command in ["p", "point", "pointe", "face", "facing"]:
        msg = "Orienting %s" % cardinals[commandValue[:1].lower()][0]
        speak(msg)
        try:
            orientToAzimuth(int(cardinals[commandValue[:1].lower()][1]))
        except:
            outputToOperator("Could not orient towards " + commandValue)
    elif command in ["q", "quit", "exit"]:
        speak("Bye bye!")
        exitCellbot("Exiting program after receiving 'q' command.")
    elif command in ["r", "right"]:
        speak("Moving right")
        cmd = "w %s %s" % (currentSpeed * 10, currentSpeed * -10)
        commandOut(cmd)
    elif command in ["s", "stop"]:
        commandOut('w 0 0')
        outputToOperator("Stopping")
    elif command in ["t", "talk", "speak", "say"]:
        msg = robot.replaceInsensitive(input, command, '').strip()
        speak(msg, True)
    elif command in ["v", "voice", "listen", "speech"]:
        robot.makeToast("Launching voice recognition")
        outputToOperator("Launching voice recognition")
        commandByVoice("onceOnly")
    elif command in ["x", "location", "gps"]:
        try:
            robot.startLocating()
            location = robot.readLocation().result
            addresses = robot.geocode(location['latitude'],
                                      location['longitude']).result
            firstAddr = addresses[0]
            msg = 'You are in %(locality)s, %(admin_area)s' % firstAddr
        except:
            msg = "Failed to find location."
        speak(msg)
    elif command == "speed":
        if commandValue in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
            changeSpeed(commandValue)
        else:
            outputToOperator("Invalid speed setting: '%s'" % command)
    elif command in ["faster", "hurry", "fast", "quicker"]:
        changeSpeed(currentSpeed + 1)
    elif command in ["slower", "slow", "chill"]:
        changeSpeed(currentSpeed - 1)
    # Prefixes that we ignore and then process the following word
    elif command in ["move", "go", "turn", "take"]:
        commandParse(commandValue)
    elif command in ["send", "pass"]:
        commandOut(commandValue)
        print "Passing %s" % commandValue
    elif command in ["range", "distance", "dist", "z"]:
        commandOut("fr")
        outputToOperator("Checking distance")
        #ReaderThread thread will handle the response.
    elif command in ["c", "config", "calibrate"]:
        commandOut("c" + commandValue + " " + commandValue2)
        msg = "Calibrating servos to center at %s and %s" % (commandValue,
                                                             commandValue2)
        outputToOperator(msg)
    elif command in ["w", "wheel"]:
        if microcontroller == "arduino":
            commandOut("w" + commandValue + " " + commandValue2)
        elif microcontroller == "serialservo":
            serialServoDrive(commandValue, commandValue2)
        elif microcontroller == "AVR_Stepper":
            AVR_Stepper_Controll(commandValue, commandValue2)
        else:
            msg = "Unknown microcontroller type: " + microcontroller
            outputToOperator(msg)
        addToWhiteboard("w", commandValue + " " + commandValue2)
    elif command in ["i", "infinite"]:
        commandOut("i")
        outputToOperator("Toggled infinite rotation mode on robot")
    elif command in ["picture", "takepicture"]:
        fileName = time.strftime("/sdcard/cellbot_%Y-%m-%d_%H-%M-%S.jpg")
        robot.cameraTakePicture(fileName)
        outputToOperator("Took picture. Image file located at '%s'" % fileName)
        addToWhiteboard("Picture", fileName)
    elif command in ["whiteboard", "whiteboardfull"]:
        if command == "whiteboardfull":
            outputToOperator(WhiteboardToString(True))
        else:
            outputToOperator(WhiteboardToString())
    elif command in ["reset"]:
        commandOut("reset")
        outputToOperator("Reset hardwares settings to default")
    elif command in ["pair", "pairing"]:
        commandOut("p")
        outputToOperator("Asking Bluetooth module to go into pairing")
    else:
        outputToOperator("Unknown command: '%s'" % command)
예제 #7
0
def commandParse(input):
  # Split the incoing string into a command and up to two values
  try:
    commandList = shlex.split(input)
  except:
    commandList = []
    outputToOperator("Could not parse command")
  try:
    command = commandList[0].lower()
  except IndexError:
    command = ""
  try:
    commandValue = commandList[1]
  except IndexError:
    commandValue = ""
  try:
    commandValue2 = commandList[2]
  except IndexError:
    commandValue2 = ""

  # Process known commands
  if command in ["a", "audio", "record"]:
    global audioRecordingOn
    audioRecordingOn = not audioRecordingOn
    fileName=time.strftime("/sdcard/cellbot_%Y-%m-%d_%H-%M-%S.3gp")
    if audioRecordingOn:
      outputToOperator("Starting audio recording")
      robot.makeToast("Starting audio recording")
      robot.startAudioRecording(fileName)
    else:
      robot.stopAudioRecording()
      robot.makeToast("Stopping audio recording")
      outputToOperator("Stopped audio recording. Audio file located at '%s'" % fileName)
  elif command  in ["b", "back", "backward", "backwards"]:
    speak("Moving backward")
    cmd = "w %s %s" % (currentSpeed * -10, currentSpeed * -10)
    commandOut(cmd)
  elif command in ["compass", "heading"]:
    orientToAzimuth(int(commandValue[:3]))
  elif command in ["d", "date"]:
    speak(time.strftime("Current time is %_I %M %p on %A, %B %_e, %Y"))
  elif command in ["f", "forward", "forwards", "scoot"]:
    speak("Moving forward")
    cmd = "w %s %s" % (currentSpeed * 10, currentSpeed * 10)
    commandOut(cmd)
  elif command in ["h", "hi", "hello"]:
    speak("Hello. Let's play.")
  elif command in ["l", "left"]:
    speak("Moving left")
    cmd = "w %s %s" % (currentSpeed * -10, currentSpeed * 10)
    commandOut(cmd)
  elif command in ["m", "mute", "silence"]:
    global audioOn
    audioOn = not audioOn
    speak("Audio mute toggled")
  elif command in ["p", "point", "pointe", "face", "facing"]:
    msg = "Orienting %s" % cardinals[commandValue[:1].lower()][0]
    speak(msg)
    try:
      orientToAzimuth(int(cardinals[commandValue[:1].lower()][1]))
    except:
      outputToOperator("Could not orient towards " + commandValue)
  elif command in ["q", "quit", "exit"]:
    speak("Bye bye!")
    exitCellbot("Exiting program after receiving 'q' command.")
  elif command in ["r", "right"]:
    speak("Moving right")
    cmd = "w %s %s" % (currentSpeed * 10, currentSpeed * -10)
    commandOut(cmd)
  elif command in ["s", "stop"]:
    commandOut('w 0 0')
    outputToOperator("Stopping")
  elif command in ["t", "talk", "speak", "say"]:
    msg = robot.replaceInsensitive(input, command, '').strip()
    speak(msg,True)
  elif command in ["v", "voice", "listen", "speech"]:
    robot.makeToast("Launching voice recognition")
    outputToOperator("Launching voice recognition")
    commandByVoice("onceOnly")
  elif command in ["x", "location", "gps"]:
    try:
      robot.startLocating()
      location = robot.readLocation().result
      addresses = robot.geocode(location['latitude'], location['longitude']).result
      firstAddr = addresses[0]
      msg = 'You are in %(locality)s, %(admin_area)s' % firstAddr
    except:
      msg = "Failed to find location."
    speak(msg)
  elif command == "speed":
    if commandValue in ["0","1","2","3","4","5","6","7","8","9"]:
      changeSpeed(commandValue)
    else:
      outputToOperator("Invalid speed setting: '%s'" % command)
  elif command in ["faster", "hurry", "fast", "quicker"]:
    changeSpeed(currentSpeed + 1)
  elif command in ["slower", "slow", "chill"]:
    changeSpeed(currentSpeed - 1)
  # Prefixes that we ignore and then process the following word
  elif command in ["move", "go", "turn", "take"]:
    commandParse(commandValue)
  elif command in ["send", "pass"]:
    commandOut(commandValue)
    print "Passing %s" % commandValue
  elif command in ["range", "distance", "dist", "z"]:
    commandOut("fr")
    outputToOperator("Checking distance")    
    #ReaderThread thread will handle the response.
  elif command in ["c", "config", "calibrate"]:
    commandOut("c" + commandValue + " " + commandValue2)
    msg = "Calibrating servos to center at %s and %s" % (commandValue, commandValue2)
    outputToOperator(msg)
  elif command in ["w", "wheel"]:
    if microcontroller == "arduino":
      commandOut("w" + commandValue + " " + commandValue2)
    elif microcontroller == "serialservo":
      serialServoDrive(commandValue, commandValue2)
    elif microcontroller == "AVR_Stepper":
      AVR_Stepper_Controll(commandValue, commandValue2)
    else:
      msg = "Unknown microcontroller type: " + microcontroller
      outputToOperator(msg)
    addToWhiteboard("w", commandValue + " " + commandValue2)
  elif command in ["i", "infinite"]:
    commandOut("i")
    outputToOperator("Toggled infinite rotation mode on robot")
  elif command in ["picture", "takepicture"]:
    fileName=time.strftime("/sdcard/cellbot_%Y-%m-%d_%H-%M-%S.jpg")
    robot.cameraTakePicture(fileName)
    outputToOperator("Took picture. Image file located at '%s'" % fileName)
    addToWhiteboard("Picture", fileName)
  elif command in ["whiteboard", "whiteboardfull"]:
    if command == "whiteboardfull":
      outputToOperator(WhiteboardToString(True))
    else:
      outputToOperator(WhiteboardToString())
  elif command in ["reset"]:
    commandOut("reset")
    outputToOperator("Reset hardwares settings to default")
  elif command in ["pair", "pairing"]:
    commandOut("p")
    outputToOperator("Asking Bluetooth module to go into pairing")
  else:
    outputToOperator("Unknown command: '%s'" % command)
예제 #8
0
def initializeBluetooth():
  robot.toggleBluetoothState(True)
  if bluetoothAddress:
    robot.bluetoothConnect('00001101-0000-1000-8000-00805F9B34FB', bluetoothAddress) #this is a magic UUID for serial BT devices
  robot.makeToast("Initializing Bluetooth connection")
  time.sleep(3)