Erste Schritte mit LEGO
# Initialize the gripper. First rotate the motor until it stalls.
# Stalling means that it cannot move any further. This position
# corresponds to the closed position. Then rotate the motor
# by 90 degrees such that the gripper is open.
gripper_motor.run_until_stalled(200, Stop.COAST, 50)
gripper_motor.reset_angle(0)
gripper_motor.run_target(200, -90)
def
robot_pick(position):
# This function makes the robot base rotate to the indicated
# position. There it lowers the elbow, closes the gripper, and
# raises the elbow to pick up the object.
# Rotate to the pick-up position.
base_motor.run_target(60, position, Stop.HOLD)
# Lower the arm.
elbow_motor.run_target(60, -40)
# Close the gripper to grab the wheel stack.
gripper_motor.run_until_stalled(200, Stop.HOLD, 50)
# Raise the arm to lift the wheel stack.
elbow_motor.run_target(60, 0, Stop.HOLD)
def
robot_release(position):
# This function makes the robot base rotate to the indicated
# position. There it lowers the elbow, opens the gripper to
# release the object. Then it raises its arm again.
# Rotate to the drop-off position.
base_motor.run_target(60, position, Stop.HOLD)
# Lower the arm to put the wheel stack on the ground.
elbow_motor.run_target(60, -40)
# Open the gripper to release the wheel stack.
gripper_motor.run_target(200, -90)
# Raise the arm.
elbow_motor.run_target(60, 0, Stop.HOLD)
# Play three beeps to indicate that the initialization is complete.
brick.sound.beeps(3)
# Define the three destinations for picking up and moving the wheel stacks.
LEFT =
160
MIDDLE =
100
RIGHT =
40
# This is the main part of the program. It is a loop that repeats endlessly.
#
# First, the robot moves the object on the left towards the middle.
# Second, the robot moves the object on the right towards the left.
# Finally, the robot moves the object that is now in the middle, to the right.
#
# Now we have a wheel stack on the left and on the right as before, but they
# have switched places. Then the loop repeats to do this over and over.
while True:
MINDSTORMS
®
®
LEGO, the LEGO logo and MINDSTORMS are trademarks of the LEGO Group.
©2019 The LEGO Group.
Education EV3 MicroPython
Version 1.0.0
(Fortsetzung von der vorherigen Seite)
(Fortsetzung auf der nächsten Seite)
51