Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. """Sample Webots controller for the square path benchmark."""
  2.  
  3. from controller import Robot
  4.  
  5. # Get pointer to the robot.
  6. robot = Robot()
  7.  
  8. # Get pointer to each wheel of our robot.
  9. leftWheel = robot.getMotor('left wheel')
  10. rightWheel = robot.getMotor('right wheel')
  11.  
  12. # Repeat the following 4 times (once for each side).
  13. for i in range(0, 4):
  14.     leftWheel.setPosition(float('inf'))
  15.     rightWheel.setPosition(float('inf'))
  16.     leftWheel.setVelocity(5.24)
  17.     rightWheel.setVelocity(5.24)
  18.     # Wait for the robot to reach a corner.
  19.     if i == 0:
  20.         robot.step(3900)
  21.     if i == 1:
  22.         robot.step(3950)
  23.     if i == 2:
  24.         robot.step(3960)
  25.     if i == 3:
  26.         robot.step(3960)
  27.  
  28.     leftWheel.setVelocity(5.24)
  29.     rightWheel.setVelocity(-5.01)
  30.     # Wait until the robot has turned 90 degrees clockwise.
  31.     robot.step(480)
  32.  
  33. # Stop the robot when path is completed, as the robot performance
  34. # is only computed when the robot has stopped.
  35. leftWheel.setVelocity(0)
  36. rightWheel.setVelocity(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement