class Gelo: def __init__(self): self.hub = InventorHub(top_side=Axis.Z, front_side=-Axis.X) # Configure the leg motors self.front_left_leg_motor = Motor(Port.D) self.front_right_leg_motor = \ Motor(Port.C, Direction.COUNTERCLOCKWISE) self.rear_left_leg_motor = Motor(Port.B) self.rear_right_leg_motor = \ Motor(Port.A, Direction.COUNTERCLOCKWISE) self.leg_motors = [ self.front_left_leg_motor, self.front_right_leg_motor, self.rear_left_leg_motor, self.rear_right_leg_motor ] # Configure the sensors self.color_sensor = ColorSensor(Port.F) self.distance_sensor = UltrasonicSensor(Port.E) def activate_display(self): self.hub.display.orientation(up=Side.TOP) for _ in range(10): self.hub.display.image([[00, 11, 33, 11, 00], [11, 33, 33, 33, 11], [33, 66, 99, 66, 33], [11, 33, 66, 33, 11], [00, 11, 33, 11, 00]]) wait(50) self.hub.display.off() wait(50) def straighten_legs(self): for leg_motor in self.leg_motors: leg_motor.run_target(speed=1000, target_angle=0, wait=False) def walk(self, speed: int, seconds: int): for _ in range(seconds): self.front_left_leg_motor.run_time(speed=speed, time=500, wait=False) self.rear_right_leg_motor.run_time(speed=speed, time=500) self.front_right_leg_motor.run_time(speed=speed, time=500, wait=False) self.rear_left_leg_motor.run_time(speed=speed, time=500)
print("Demo of run") example_motor.run(500) wait(1500) example_motor.stop() wait(1500) # Run at 70% duty cycle ("power") and then stop by coasting. print("Demo of dc") example_motor.dc(50) wait(1500) example_motor.stop() wait(1500) # Run at 500 deg/s for two seconds. print("Demo of run_time") example_motor.run_time(500, 2000) wait(1500) # Run at 500 deg/s for 90 degrees. print("Demo of run_angle") example_motor.run_angle(500, 180) wait(1500) # Run at 500 deg/s back to the 0 angle print("Demo of run_target to 0") example_motor.run_target(500, 0) wait(1500) # Run at 500 deg/s back to the -90 angle print("Demo of run_target to -90") example_motor.run_target(500, -90)
# Component positions FEET = 0 BELLY = 365 HEAD = 128 ARMS = 244 NECK = 521 BASE = 697 # Place all the elements for element in (FEET, BELLY, ARMS, NECK, HEAD): # Go to the element belt.run_target(speed=200, target_angle=element) # Grab the element arm.run_time(speed=300, time=2000) # Lift the element by going back to nearly zero arm.run_target(speed=300, target_angle=55) # Go to the base belt.run_target(speed=200, target_angle=BASE) wait(500) # Put the element down arm.run_time(speed=300, time=2000) # Lift the arm back up arm.run_target(speed=300, target_angle=0) # When we are done, eject the result