Skip to main content
Materials Required:
Quantity Materials Needed
1

VEX IQ Super Kit

1

VEXcode IQ

1

Engineering Notebook

1

Clawbot (Drivetrain) Template

The Clawbot arm is ready to move up and down!

This activity will give you the tools to program your robot with conditional behaviors.
The [If then else] block is the main focus within the activity but other Sensing, Control, and Operator blocks are also used.

You can use the Help information inside of VEXcode IQ to learn about the blocks. For guidance in using the Help feature, see the Using Help tutorial.

Step 1: Programming to move the arm down.

In the previous page, you programmed the Clawbot's arm to spin up when the Brain Up button was pressed. But, what about also lowering the arm? Let's first revisit the previous ArmUp2 project.

Would it be possible to use the same [If then] block for spinning the arm up to also spin the arm down? Let's try it! Build the project below by editing your already existing ArmUp2 project.

  • Save the project as ArmUpDown. If students need help saving the project, refer to the Naming and Saving tutorial.

  • Check to make sure the project name ArmUpDown is now in the window in the center of the toolbar.

  • Predict what the project will have the Clawbot do in your engineering notebook. Explain both the user's and the Clawbot's behaviors.

  • Test to see if your prediction of what the project has the Clawbot do is correct.

    • Download the project to Slot 3 on the Clawbot, and then run it.

    • For help downloading and running a project, see the tutorial in VEXcode IQ that explains how to Download and Run a Project.
      Download and Run a Project Tutorial

  • Check your explanations of the project and add notes to correct them as needed.

Step 2: Understanding the project flow.

In the previous step, the project did raise and lower the arm. However, since the condition of the Brain Up button begin pressed is first, if the Brain Up button is held down and then the Brain Down is also pressed, the arm will continue to spin up since that action will not stop until the Brain Up button is released. View the following flowchart that explains the project flow.

Thus, the project can replace the [If then] blocks with [If then else] blocks so that only one instance can be true at any time.

View the following tutorial video on [If then else] blocks:

Start by watching the If-Then-Else Tutorial video in VEXcode IQ.

If-Then-Else Tutorial

Using [If then else] blocks will also get rid of the need for the [Wait until] blocks because the arm will continue to spin up until the Brain Up button is released. This occurs because the "else" part of the [If then else] is never reached until the Brain Up button condition is false (released).

The [Forever] block allows the first condition to be continuously checked.

Let's explore changing the project by adding [If then else] blocks. The Arm Motor will now continue to spin until the Brain Up button is no longer pressed (released). Due to the [Forever] block, this condition will continue to be checked until it is false.

Once the condition of the Brain Up button is false, the project will continue to the next block, which is to check the condition if the Brain Down button is pressed. If the condition of the Brain Down button being pressed is true, then the arm will spin up. Again, due to the [Forever] block, this condition will continue to be checked until it is false.

Once the condition of the Brain Up button is false, the project will continue to the next block, which is the [Stop motor] block. Thus, the Arm Motor will only stop when both conditions are false (neither button is pressed).

Step 3: Programming with [If then else] blocks.

Let's use the [If then else] blocks:

  • Add the [If then else] blocks to your ArmUpDown project so that your project looks like the following:

  • Save the project as ArmUpDown2. If students need help saving the project, refer to the Naming and Saving tutorial.

  • Download the project to Slot 4 on the Clawbot, and then run it.

  • For help downloading and running a project, see the tutorial in VEXcode IQ that explains how to Download and Run a Project.
    Download and Run a Project Tutorial

  • Test to see if the arm will now spin up when the Brain Up button is pressed and spin down when the Brain Down button is pressed.

  • Verify that when the Brain Up and Down buttons are not pressed (released) that the Arm Motor stops.

  • Write your observations of how the Clawbot behaved before and after adding the if then else blocks to your project in your engineering notebook.

Step 4: Programming the Claw.

In the previous step, the project was optimized to run more efficiently by using [If then else] blocks. In the previous example, the arm was manipulated using the Brain Up and Down buttons.

Using the exact same project outline, the Claw can also be manipulated.

  • Review the ArmUpDown2 project and change the [Spin] blocks to ClawMotor instead of ArmMotor by using the dropdown menu.

    Ensure that the Brain Up button spins the Claw "open" and that the Brain Down button spins the Claw "close" by using the dropdown menus.

  • Save the project as ClawUpDown. If students need help saving the project, refer to the Naming and Saving tutorial.

  • Download the project to Slot 1 on the Clawbot, and then run it.

  • For help downloading and running a project, see the tutorial in VEXcode IQ that explains how to Download and Run a Project.
    Download and Run a Project Tutorial

  • Test to see if the Claw will now spin open when the Brain Up button is pressed and spin closed when the Brain Down button is pressed.

  • Verify that when the Brain Up and Down buttons are not pressed (released) that the Claw Motor stops.

  • Write your observations of how the Clawbot behaved before and after adding the if then else blocks to your project in your engineering notebook.