Apr-04-2018, 06:41 PM
I have coded a robot that runs modules containing the commands necessary to carry out a specific process. As of now, the user inputs the desired command, my code uses an if statement to determine what command they entered, and it runs the appropriate command. However, the command must be finished before the user can input another command.
Now I would like to do the following: have the user input a command, start the command, and, while the command is running, rerun the command to get the users input. For example, the user inputs move forward, the robot starts moving, then the user changes the command to move backward midway through the robot moving forward, and the robot resets and starts moving backward in response.
Below is the code of the while loop that runs the modules and asks for user input. Let me know if you have any ideas on how I can achieve this or if you need any clarification. I am a high schooler who is still learning how to code, so any help would be greatly appreciated.
Thanks in advance.
Best,
Christopher
Now I would like to do the following: have the user input a command, start the command, and, while the command is running, rerun the command to get the users input. For example, the user inputs move forward, the robot starts moving, then the user changes the command to move backward midway through the robot moving forward, and the robot resets and starts moving backward in response.
Below is the code of the while loop that runs the modules and asks for user input. Let me know if you have any ideas on how I can achieve this or if you need any clarification. I am a high schooler who is still learning how to code, so any help would be greatly appreciated.
Thanks in advance.
Best,
Christopher
#runs all the modules and gets user input while True: defultPosition() command = raw_input("Enter move forward, move backward, turn or cancel: ") defultPosition() if command == "cancel": break if command == ("move forward") or (command == "move backward"): speedInput = input("Enter the desired speed: ") distanceInput = input("Enter the number of inches you wish the robot to move (must be a factor of 5): ") if command == "turn": speedInput = input("Enter the desired speed: ") degrees = input("Enter the number of degrees for the robot to move: ") print ("\nINPUTED COMMAND: %s \n" % command) if command == "move forward": #run the moveForward module print "Initiating command\n" moveForward(speedInput, distanceInput) print "Finished command; restarting and waiting for another input \n" if command == "move backward": #run the moveBackward module print "Initiating command\n" moveBackward(speedInput, distanceInput) print "Finished command; restarting and waiting for another input \n" if command == "turn": #runs the turn module print "Initiating command\n" turnCounterClockwise(speedInput, degrees) print "Finished command; restarting and waiting for another input \n"