You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CozmoDrive.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import cozmo
  2. import time
  3. from cozmo.util import degrees, distance_mm, speed_mmps
  4. def cozmo_program(robot: cozmo.robot.Robot):
  5. # robot.say_text("Hi Martina").wait_for_completed()
  6. # Drive forwards for 150 millimeters at 50 millimeters-per-second.
  7. # robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
  8. # Turn 90 degrees to the left.
  9. # Note: To turn to the right, just use a negative number.
  10. # robot.turn_in_place(degrees(90)).wait_for_completed()
  11. print("fov_x ", robot.camera.config.fov_x)
  12. print("fov_y ", robot.camera.config.fov_y)
  13. print("focal_length ", robot.camera.config.focal_length)
  14. cozmo = CozmoDriver(robot)
  15. cozmo.updateLift()
  16. cozmo.drive()
  17. turn_speed = 30
  18. forward_speed = 50
  19. l_wheel_speed = (0 * forward_speed) + (turn_speed * 1)
  20. r_wheel_speed = (0 * forward_speed) - (turn_speed * 1)
  21. robot.drive_wheels(l_wheel_speed,r_wheel_speed,l_wheel_speed *4,r_wheel_speed *4)
  22. time.sleep(9.5)
  23. class CozmoDriver:
  24. """ Contains all functions that will be used to move cozmo
  25. """
  26. def __init__(self, robot: cozmo.robot.Robot):
  27. self.speed = 50
  28. self.turnSpeed = 30
  29. self.robot = robot
  30. self.initializeDriver()
  31. def initializeDriver(self):
  32. """ Set Cozmo in the starting position
  33. """
  34. self.updateLift()
  35. self.updateHead()
  36. def drive(self):
  37. """ Start driving
  38. """
  39. self.robot.drive_wheel_motors(self.speed, self.speed)
  40. def driveLeft(self):
  41. """ Drive to left
  42. """
  43. self.robot.drive_wheel_motors(self.speed - 15, self.speed)
  44. def driveRight(self):
  45. """ Drive to right
  46. """
  47. self.robot.drive_wheel_motors(self.speed, self.speed - 15)
  48. def updateLift(self):
  49. """ Set Lift to maximum height
  50. """
  51. self.robot.set_lift_height(1).wait_for_completed()
  52. def updateHead(self):
  53. """ Set Head to minimum angle
  54. """
  55. self.robot.set_head_angle(cozmo.robot.MIN_HEAD_ANGLE).wait_for_completed()
  56. cozmo.run_program(cozmo_program)