How to make a program using time?


#1

Hi,

How can you tell the robot to move forward during 3 seconds and then turn to the right?
Is there any option to cotrol blocks using a time factor?

Thanks


#2

There is a wait block in the Control palette that will make the program wait for the specified number of seconds before continuing. This is a blocking call, so nothing else will occur until the wait ends (motors will continue running in the direction they were set for). You can also do this in a somewhat less blocking fashion by using the timer block in the Robots palette to set a time variable and use another variable that is the start time from the timer plus the seconds you wish to wait. You can use a repeat until loop to check if the time has been exceeded or you can use an if (or if-else block) to take some action if the time has been exceeded. It depends on what you want to do. For what you’ve asked, the pseudocode would be:

[run forward] at [speed]
wait [3] seconds
[turn right] at [speed]
wait [nn] seconds

where nn is the time it takes to make the desired turn.


#3