ADM Project 1.2.3

Stacking Objects

Use loops, variables, and a magnetic end effector to stack objects in a planned layout.

Lesson Overview

In this project, you will apply robotic movement, sequencing, variables, loops, and spatial planning to stack objects accurately and repeatably. The example uses a magnetic end effector to pick up cubes, move them into rows, build additional layers, and adjust placement height.

Notes

  • This project extends palletizing by stacking objects in multiple layers.
  • The magnetic end effector must be set before pickup and placement begins.
  • Variables such as z, yPos, and xPos control height and placement locations.
  • Repeated pickup and drop-off patterns are handled with loops.
  • Final submissions should include comments that clearly explain each row, layer, height change, and final placement.
Code example

1.2.3: Stacking Objects

Review the code, copy it when needed, and add comments before submitting your final version.

VEXcode Python Example
Code examples may be incomplete or missing comments. Comments are required for code submissions.
def main():
    arm.set_end_effector_type(Arm.MAGNET)
    arm.set_speed(100)

    cubes = 2
    yPos = 185
    z = 60
    arm.move_to(180, 0, 180)
    #place cubes in back row
    for x in range(cubes):
        #move to pick up cube

        arm.move_to(48, 152, 30)
        arm.move_to(48, 152, 25)
        arm.set_end_effector_magnet(True)
        #move to drop off cube
        arm.move_to(48, 152, z)
        arm.move_to(200, yPos, z-15)
        arm.move_to(200, yPos, z-19)
        arm.set_end_effector_magnet(False)
        arm.move_to(168, 160, 100)
        yPos = yPos - 50
    xPos = 135

    #front row cubes
    for x in range(cubes):
       #move to pickup cubes
        arm.move_to(48, 152, 30)
        arm.move_to(48, 152, 25)
        arm.set_end_effector_magnet(True)
        #move to drop off cubes
        arm.move_to(48, 152, z)
        arm.move_to(150, xPos, z-15)
        arm.move_to(150, xPos, z-19)
        arm.set_end_effector_magnet(False)
        arm.move_to(168, 160, 100)
        xPos = xPos + 50

    stacks = 2
    z = 90
    yPos = 185
    for x in range(stacks):
        #move to pick up cube

        arm.move_to(48, 152, 30)
        arm.move_to(48, 152, 25)
        arm.set_end_effector_magnet(True)
        #move to drop off cube
        arm.move_to(48, 152, z)
        arm.move_to(200, yPos, z-15)
        arm.move_to(200, yPos, z-19)
        arm.set_end_effector_magnet(False)
        arm.move_to(168, 160, 100)
        yPos = yPos - 50
    xPos = 135

    #front row cubes
    for x in range(stacks):
       #move to pickup cubes
        arm.move_to(48, 152, 30)
        arm.move_to(48, 152, 25)
        arm.set_end_effector_magnet(True)
        #move to drop off cubes
        arm.move_to(48, 152, z)
        arm.move_to(150, xPos, z-15)
        arm.move_to(150, xPos, z-19)
        arm.set_end_effector_magnet(False)
        arm.move_to(168, 160, 100)
        xPos = xPos + 50
#increase height
    z = 130
    arm.move_to(48, 152, 30)
    arm.move_to(48, 152, 25)
    arm.set_end_effector_magnet(True)
    #move to drop off cubes
    arm.move_to(48, 152, 100)
    arm.move_to(145, 140, 90)
    arm.move_to(145, 140, 88)
    arm.set_end_effector_magnet(False)
    arm.move_to(168, 160, 100)