Skip to main content

Now that we have coded the arm to pick up and sort the red disk using the Optical Sensor, we will now code the arm to pick up and sort both the red disk and the blue disk using the Optical Sensor. Both disks will begin in the pick up location at the same time. Because of this, we need to consider how the z-axis will change while the project is being run:

  • The starting z-coordinate for Point 2 will now be higher, because the project is starting with two disks in the pick up location.
  • After the arm sorts the first colored disk, it will need to move further down along the z-axis to pick up the second disk, because the second disk will be further down in the pick up location.

To account for this change in the z-axis, you will create a variable. This variable will be used to change the z-coordinate of Point 2 each time the arm sorts a disk. 

In VEXcode V5, follow the steps in this video to create the zHeight variable and add a [Set variable] block to the project.

The [Set variable] block will be used to set the initial z-value for Point 2. It is set to '2' because that is the z-value height when two disks are in the pick up location.

Follow the steps in this video to add the zHeight variable into the z-value for Point 2 and add a [Change variable] block to the project.

The [Change variable] block will be used to change the z-value by -0.5 each time the arm sorts a disk. Each disk is about 0.5 inches tall, so the project will change the z-value of Point 2 by roughly one disk's height.

Follow the steps in this video to duplicate the blocks from the red drop off location for the blue drop off location. Enter the coordinates for Point 5 into the [Joint move] block. 

These blocks will code the arm to drop the disk into the blue drop off location.

Use your coordinates for Point 5, and not the ones shown in this image.

Place the red and blue disks into the pick up location (the order does not matter) and then download and run the project. Press the Brain's screen to trigger the arm's movement. The arm will pick up and sort the the first colored disk.

After the first disk has been sorted, press the Brain's screen again to trigger the arm's movement. The arm will then pick up and sort the second colored disk.

If your arm did not sort the red and blue disks, notify your teacher. 

Download and runSort two disks

Once you have finished coding the arm to pick up and sort the red and blue disks using the Optical Sensor, stop the project.

Stop the Project