Пример #1
0
def handleCommand(command, keyPosition):

    global lastCommand

    print("handling command")

    if command == 'L':
        move(100, -100, 0, .20, 0)
    elif command == 'R':
        move(-100, 100, 0, .20, 0)
    elif command == 'F':
        move(100, 100, .09, .40, .18)
    elif command == 'B':
        move(-100, -100, .09, .40, .18)

    robot_util.handleSoundCommand(command, keyPosition)
def handleCommand(command, keyPosition, price=0):

    global movementSystemActive
    global pingPongNumActive
    global freePongActive

    if keyPosition != "down":
        return

    d = 255

    motorA.setSpeed(speed1)
    motorB.setSpeed(speed1)

    robot_util.handleSoundCommand(command, keyPosition, price)

    if command == 'F':
        if movementSystemActive:
            print("skip")
        else:
            drivingSpeed = d
            for motorIndex in range(4):
                runMotor(motorIndex, forward[motorIndex])
            movementSystemActive = True
            time.sleep(straightDelay)
            turnOffMotors()
            movementSystemActive = False

    if command == 'B':
        if movementSystemActive:
            print("skip")
        else:
            drivingSpeed = d
            for motorIndex in range(4):
                runMotor(motorIndex, backward[motorIndex])
            movementSystemActive = True
            time.sleep(straightDelay)
            turnOffMotors()
            movementSystemActive = False

    if command == 'L':
        if movementSystemActive:
            print("skip")
        else:
            drivingSpeed = turningSpeedActuallyUsed
            for motorIndex in range(4):
                runMotor(motorIndex, left[motorIndex])
            movementSystemActive = True
            print("starting")
            time.sleep(commandArgs.turn_delay)
            print("finished")
            turnOffMotors()
            movementSystemActive = False

    if command == 'R':
        if movementSystemActive:
            print("skip")
        else:
            drivingSpeed = turningSpeedActuallyUsed
            for motorIndex in range(4):
                runMotor(motorIndex, right[motorIndex])
            movementSystemActive = True
            time.sleep(commandArgs.turn_delay)
            turnOffMotors()
            movementSystemActive = False

    if command == 'U':
        #mhArm.getMotor(1).setSpeed(127)
        #mhArm.getMotor(1).run(Adafruit_MotorHAT.BACKWARD)
        incrementArmServo(1, 10)
        time.sleep(0.05)

    if command == 'D':
        #mhArm.getMotor(1).setSpeed(127)
        #mhArm.getMotor(1).run(Adafruit_MotorHAT.FORWARD)
        incrementArmServo(1, -10)
        time.sleep(0.05)
    if command == 'O':
        #mhArm.getMotor(2).setSpeed(127)
        #mhArm.getMotor(2).run(Adafruit_MotorHAT.BACKWARD)
        incrementArmServo(2, -10)
        time.sleep(0.05)

    if command == 'C':
        #mhArm.getMotor(2).setSpeed(127)
        #mhArm.getMotor(2).run(Adafruit_MotorHAT.FORWARD)
        incrementArmServo(2, 10)
        time.sleep(0.05)

    if command == 'FIRE':
        print("processing fire")
        if pingPongEnabled:
            print("fire was enabled")
            pingPongNumActive += 1
            print("ping pong number active", pingPongNumActive)
            pingPongMotor = mhPingPong.getMotor(1)
            pingPongMotor.setSpeed(255)
            pingPongMotor.run(Adafruit_MotorHAT.FORWARD)
            time.sleep(3.1)
            pingPongNumActive -= 1
            print("ping pong number active", pingPongNumActive)

            # if nobody has the cannon active anymore, release
            if pingPongNumActive == 0:
                pingPongMotor.run(Adafruit_MotorHAT.RELEASE)
        else:
            print("ping pong not enabled")
    if command == 'FREE_FIRE':
        return
        print("processing fire")
        if not freePongActive:
            freePongActive = True
            print("free pong fire was enabled")
            pingPongMotor = mhPingPong.getMotor(1)
            pingPongMotor.setSpeed(255)
            pingPongMotor.run(Adafruit_MotorHAT.FORWARD)
            time.sleep(2.8)
            print("free ping pong", freePongActive)
            pingPongMotor.run(Adafruit_MotorHAT.RELEASE)
            time.sleep(180)
            freePongActive = False
        else:
            print("ping pong not enabled")

    if command == 'FIRE_ALL':
        print("processing fire")
        if pingPongEnabled:
            print("fire was enabled")
            pingPongNumActive += 1
            print("ping pong number active", pingPongNumActive)
            pingPongMotor = mhPingPong.getMotor(1)
            pingPongMotor.setSpeed(255)
            pingPongMotor.run(Adafruit_MotorHAT.FORWARD)
            time.sleep(50)
            pingPongNumActive -= 1
            print("ping pong number active", pingPongNumActive)

            # if nobody has the cannon active anymore, release
            if pingPongNumActive == 0:
                pingPongMotor.run(Adafruit_MotorHAT.RELEASE)
        else:
            print("ping pong not enabled")

    if command == 'VIBRATE':
        vibrate.vibrate(mh, forward)
Пример #3
0
def handleCommand(command, keyPosition, price=0):
    #fblr

    print("\n\n\n")

    if keyPosition != "down":
        return

    robot_util.handleSoundCommand(command, keyPosition, price)

    if command == 'F':
        print("onforward")
        os.system("cd v4l2scripts ; ./onforward.sh")

    if command == 'B':
        print("onback")
        os.system("cd v4l2scripts; ./onback.sh")

    if command == 'L':
        print("onleft")
        os.system("cd v4l2scripts; ./onleft.sh")

    if command == 'R':
        print("onright")
        os.system("cd v4l2scripts; ./onright.sh")

    if command == 'focus+':
        print("onfocus+")
        os.system("cd v4l2scripts; ./onfocus+.sh")

    if command == 'focus-':
        print("onfocus-")
        os.system("cd v4l2scripts; ./onfocus-.sh")

    if command == 'foc+':
        print("onfocus+")
        os.system("cd v4l2scripts; ./onfocus+.sh")

    if command == 'foc-':
        print("onfocus-")
        os.system("cd v4l2scripts; ./onfocus-.sh")

    if command == 'zoom+':
        print("onzoom+")
        os.system("cd v4l2scripts; ./onzoom+.sh")

    if command == 'zoom-':
        print("onzoom-")
        os.system("cd v4l2scripts; ./onzoom-.sh")

    if command == 'brt+':
        print("onbrt+")
        os.system("cd v4l2scripts; ./onbrt+.sh")

    if command == 'brt-':
        print("onbrt-")
        os.system("cd v4l2scripts; ./onbrt-.sh")

    if command == 'con+':
        print("oncon+")
        os.system("cd v4l2scripts; ./oncon+.sh")

    if command == 'con-':
        print("oncon-")
        os.system("cd v4l2scripts; ./oncon-.sh")

    if command == 'sat+':
        print("onsat+")
        os.system("cd v4l2scripts; ./onsat+.sh")

    if command == 'sat-':
        print("onsat-")
        os.system("cd v4l2scripts; ./onsat-.sh")

    if command == 'gain+':
        print("ongain+")
        os.system("cd v4l2scripts; ./ongain+.sh")

    if command == 'gain-':
        print("ongain-")
        os.system("cd v4l2scripts; ./ongain-.sh")

    if command == 'temp+':
        print("ontemp+")
        os.system("cd v4l2scripts; ./ontemp+.sh")

    if command == 'temp-':
        print("ontemp-")
        os.system("cd v4l2scripts; ./ontemp-.sh")

    if command == 'sharp+':
        print("onsharp+")
        os.system("cd v4l2scripts; ./onsharp+.sh")

    if command == 'sharp-':
        print("onsharp-")
        os.system("cd v4l2scripts; ./onsharp-.sh")

    if command == 'exp+':
        print("onexp+")
        os.system("cd v4l2scripts; ./onexp+.sh")

    if command == 'exp-':
        print("onexp-")
        os.system("cd v4l2scripts; ./onexp-.sh")

    if command == 'pan+':
        print("onpan+")
        os.system("cd v4l2scripts; ./onpan+.sh")

    if command == 'pan-':
        print("onpan-")
        os.system("cd v4l2scripts; ./onpan-.sh")

    if command == 'tilt+':
        print("ontilt+")
        os.system("cd v4l2scripts; ./ontilt+.sh")

    if command == 'tilt-':
        print("onexp-")
        os.system("cd v4l2scripts; ./ontilt-.sh")

    if command == 'atemp':
        print("onatemp")
        os.system("cd v4l2scripts; ./onatemp.sh")

    if command == 'backlight':
        print("onbaclight")
        os.system("cd v4l2scripts; ./onbacklight.sh")

    if command == 'aexp':
        print("onaexp")
        os.system("cd v4l2scripts; ./onaexp.sh")

    if command == 'aexppri':
        print("onaexppri")
        os.system("cd v4l2scripts; ./onaexppri.sh")

    if command == 'afoc':
        print("onafoc")
        os.system("cd v4l2scripts; ./onafoc.sh")
Пример #4
0
def handleCommand(command, keyPosition):
    global movementSystemActive
    global tiltPercentage
    global panPercentage

    print("\n\n")

    if keyPosition != "down":
        return

    robot_util.handleSoundCommand(command, keyPosition)

    if command == 'F':
        if movementSystemActive:
            print("skip")
        else:
            print("onforward")
            movementSystemActive = True
            goForward()
            time.sleep(straightDelay)
            releaseMotors()
            movementSystemActive = False

    if command == 'B':
        if movementSystemActive:
            print("skip")
        else:
            print("onback")
            movementSystemActive = True
            goBackward()
            time.sleep(straightDelay)
            releaseMotors()
            movementSystemActive = False

    if command == 'L':
        if movementSystemActive:
            print("skip")
        else:
            print("onleft")
            movementSystemActive = True
            turnLeft()
            time.sleep(turnDelay)
            releaseMotors()
            movementSystemActive = False

    if command == 'R':
        if movementSystemActive:
            print("skip")
        else:
            print("onright")
            movementSystemActive = True
            turnRight()
            time.sleep(turnDelay)
            releaseMotors()
            movementSystemActive = False

    #The m in front of these events differentiates them from the v4l2 commands
    #because it is a mechanical pan and tilt. It is possible to have a robot
    #that responds to v4l2 pan and tilt and mechanical pan and tilt events.
    if command == 'mpan-':
        print("onmpan-")
        panPercentage += panIncrement
        if panPercentage > 100.0:
            panPercentage = 100.0
        setPan(panPercentage)

    if command == 'mpan+':
        print("onmpan+")
        panPercentage -= panIncrement
        if panPercentage < 0.0:
            panPercentage = 0.0
        setPan(panPercentage)

    if command == 'mtilt-':
        print("onmtilt-")
        tiltPercentage += tiltIncrement
        if tiltPercentage > 100.0:
            tiltPercentage = 100.0
        setTilt(tiltPercentage)

    if command == 'mtilt+':
        print("onmtilt+")
        tiltPercentage -= tiltIncrement
        if tiltPercentage < 0.0:
            tiltPercentage = 0.0
        setTilt(tiltPercentage)
Пример #5
0
def handleCommand(command, keyPosition, price=0):
    global turnDelay
    global straightDelay
    global ser
    global movementSystemActive
    global pipwm
    global dildoActive

    print("\n\n")

    if keyPosition != "down":
        return

    robot_util.handleSoundCommand(command, keyPosition, price)

    if command == 'F':
        if movementSystemActive:
            print("skip")
        else:
            print("onforward")
            movementSystemActive=True
            goForward(ser, commandArgs.straight_speed)
            time.sleep(straightDelay)
            stopMotors(ser)
#            time.sleep(stopDelay)
            movementSystemActive=False

    if command == 'B':
        if movementSystemActive:
            print("skip")
        else:
            print("onback")
            movementSystemActive=True
            goBackward(ser, commandArgs.straight_speed)
            time.sleep(straightDelay)
            stopMotors(ser)
#            time.sleep(stopDelay)
            movementSystemActive=False

    if command == 'L':
        if movementSystemActive:
            print("skip")
        else:
            print("onleft")
            movementSystemActive=True
            turnLeft(ser, commandArgs.turn_speed)
            time.sleep(turnDelay)
            stopMotors(ser)
#            time.sleep(stopDelay)
            movementSystemActive=False

    if command == 'R':
        if movementSystemActive:
            print("skip")
        else:
            print("onright")
            movementSystemActive=True
            turnRight(ser, commandArgs.turn_speed)
            time.sleep(turnDelay)
            stopMotors(ser)
#            time.sleep(stopDelay)
            movementSystemActive=False
    if command[0:6] == 'THRUST':
        if dildoActive:
            print('skip')
        else:
            dildoActive=True
            dildoDutyCycle=int(command[6:])
            pipwm.hardware_PWM(18, dildoFreq, dildoDutyCycle*10000)
            time.sleep(dildoDelay)
            pipwm.hardware_PWM(18, dildoFreq, 0)
            dildoActive=False
def handleCommand(command, keyPosition, price=0):

                print("handleCommand", command)
                if keyPosition == 'down':
                    robot_util.handleSoundCommand(command, keyPosition, price)
                    l298n.move(command)