Try This: Condense the Input

Let’s try reducing the input to int line count from six to three.

  • Save terminal_controlled_bot_tethered_intro as terminal_controlled_bot_tethered_try_this.  
  • Replace these six lines:
        text = input("Enter left speed: ")
        vL = int(text)

        text = input("Enter right speed: ")
        vR = int(text)

        text = input("Enter ms to run: ")
        ms = int(text)

    …with these three lines:

        vL = int(input("Enter left speed: "))
        vR = int(input("Enter right speed: "))
        ms = int(input("Enter ms to run: "))
  • Check your modified script, it should resemble the example below.
  • Flash the modified script, and repeat the tests you did with the intro version of the program.  It should run the same modified as it did before.

Example script: terminal_controlled_bot_tethered_try_this

# terminal_controlled_bot_tethered_try_this

from cyberbot import *

sleep(1000)

print("\nSpeeds are -100 to 100\n")

while(True):
    vL = int(input("Enter left speed: "))
    vR = int(input("Enter right speed: "))
    ms = int(input("Enter ms to run: "))

    bot(18).servo_speed(vL)
    bot(19).servo_speed(-vR)
    sleep(ms)
    bot(18).servo_speed(None)
    bot(19).servo_speed(None)

    print()