0

I am using while loop in order to do a function for a specific ammount of time. I use Webots and I use the getTime() function to get the simulation clock time. The problem is that the program does not go into the loop function at all and when I revert it it crashes. the while loop is as follows:

     tim=float(robot.getTime())
     tim2=float(robot.getTime())
     while tim2-tim<0.581:
         right(5.211,5.211)
         tim2=float(robot.getTime())

Can someone help me understand why it doesnt work?

  • Well if the loop is skipped: could it be that `tim2-tim` is not smaller than 0.581 ... have you tried different values for this threshold? – meissner_ Jul 20 '18 at 12:46
  • I have tried many different threshold values and the same thing happens again. + tim and tim2 are assigned one after another which is far less than 0.581 seconds. – George Tsoufis Jul 20 '18 at 12:55
  • Sure it looks as if the difference in time is minimal but since we don't know the values nor the implementation ... and the operator precedence in your condition seems to be correct. – meissner_ Jul 20 '18 at 13:24
  • well, the function "right" causes the robot to rotate right. the only commands it has in it is the motors speed assign.the desired function of this block is to rotate the robot right for 0.581 seconds. – George Tsoufis Jul 20 '18 at 13:44

1 Answers1

2

You need to insert a call to robot.step() inside your while loop otherwise, the Webots simulation won't progress and the time will remain the same.

Olivier Michel
  • 755
  • 6
  • 10