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.

Sample blocks from the VEXcode IQ Toolbox - Brain button pressed, not operator, wait until, if then, and if then else blocks.

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.

VEXcode IQ Toolbar with the Tutorials icon called out in a red box, to the right of the File menu.

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.

hi

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.

Arm Up 2 project with an additional If then block added beneath the first, within the forever loop. The second If then block reads If Brain Down button pressed, then spin arm motor down, wait until not Brain Down Button pressed. Then the stop arm motor block is beneath the If then.

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

    Project name dialog box in the VEXcode IQ Toolbar. Slot 3 is shown and the project name reads Arm Up Down.

  • 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.
      Tutorial icon reads Download and Run a project with a download icon and an arrow above.
  • 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.

Project flow image showing how the project is executed to make a decision. The If brain up button pressed is labeled as the condition, if it is pressed/True, then the blocks beneath will run in order until the next condition. If it is not pressed/false, a red line indicates the blocks are skipped and the project moves to check the second condition. The same branching occur for the second condition - if the brain down button is pressed.

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.

Tutorial icon reads If then else blocks at the bottom and shows the outline of blocks at the top.

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.

VEXcode IQ project with a forever loop attached to the When started block. Inside the Forever loop is an if then else block. The If branch reads If Brain Up button pressed, then spin arm motor up. The else branch contains another if then else block, reading if brain Down button pressed then spin arm motor down, else, stop arm motor.

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).

Project flow image showing how the project is executed to make a decision. First the condition of If Brain up button pressed is checked, if it is true the project moves to spin the arm motor up and goes back to the beginning. If the condition is false, the second condition of Brain down button pressed is checked. If the brain down button is pressed/true, spin arm motor down runs and then goes back to the beginning. If it is not pressed false, the stop arm motor block runs.

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:

    VEXcode IQ project with a Forever block attached to the When started block. Inside the forever block is an If then else block. The if branch reads if brain up button pressed, spin arm motor up. The else branch contains another if then else block that reads if brain down button pressed then spin arm motor down, else stop arm motor.

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

    Project name dialog box in the VEXcode IQ Toolbar. Slot 4 is selected and the project name reads Arm Up Down 2.

  • 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.
    Tutorial icon reads Download and run a project at the bottom with a download icon and an arrow above.
  • 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.

    Arm Up Down 2 project with the spin motor blocks set to Claw motor. The stop motor block has the parameter selection open with Arm motor selected.

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

    Project name dialog box in the VEXcode IQ Toolbar. Slot 1 is selected and the project name reads Claw Up Down.

  • 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.
    Tutorial icon reads Download and run a project on the bottom.
  • 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.