Skip to main content

Programming Loops in VEXcode IQ

The Builder in each group should get the hardware required. The Recorder should get the group's engineering notebook. The Programmer should open VEXcode IQ.

Materials Required:
Quantity Materials Needed
1

VEX IQ Super Kit

1

VEXcode IQ

1

Engineering Notebook

1

Using Loops (Tutorial)

1

Repeating Actions example project

This activity will give you the tools to program your robot with repeating behaviors. 

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: Preparing for the activity

Before you begin the activity, do you have each of these items ready? The Builder should check each of the following:

Step 2: Let's start programming with loops.

Start by watching the Using Loops Tutorial video in VEXcode IQ. Tutorial video icon reads Using Loops at the bottom and shows the outline of a loop structure in blocks.

VEXcode IQ contains many different example projects. You’ll use one of them in this exploration. For help and tips on using example projects, check out the Using Examples and Templates tutorial.Tutorial video icon reads Use Example Project and Templates at the bottom and shows a cursor hovering over an icon.

Then, open the Repeating Actions example project. VEXcode IQ Toolbar with the File menu open, and Open Examples selected with a red box. 'Open Examples' is the fourth item in the menu.

The Programmer should complete the following steps: 

  • Open the File menu.
  • Select Open Examples
  • Use the filter bar at the top of the application and select 'Control'. Example project selection window with the Repeating Actions icon highlighted with a red box. The Control filter is selected at the top.
  • Select and open the Repeating Actions example project.Example project icon reads Repeating Actions at the bottom and shows a robot icon with an arrow wrapping around it and reads "times 4" to indicate repetition.
  • Save your project as 'Repeating Actions'. Project name dialog box in the VEXcode IQ Toolbar. Slot 1 is selected and the project name reads Repeating Action.
  • Check to make sure the project name 'Repeating Actions' is now in the window in the center of the Toolbar. 

What is this project actually doing? Example project in the VEXcode IQ Workspace. To the left, the project has a When started block with a Repeat block attached, with the parameter set to 4. Within the loop is a Drive for block set to forward for 300mm and a Turn for block set to right for 90 degrees. To the left a note reads "This program drives a robot in a 300x300mm square by repeating the drive forward and turn commands 4 times."

Do the following in your engineering notebook: 

Predict what the project will have the Clawbot do. Explain each and every action that the robot will complete. 

Step 3: What is the difference between [Forever] and [Repeat]?

Two code snippets side by side showing the difference in use case between a forever loop (to the left) and a repeat loop (to the right). To the left there is a Comment that reads "use sensor input to determine when to turn" with a forever block with an if then block inside. If the Bumper is pressed the robot will turn right 90 degrees, else it will drive forward. To the right the comment reads "Use a fixed distance to determine when to turn" with a repeat loop set to 4 to drive the robot in a 300mm square.

  • Look over the Repeating Actions example project again. It's also the stack of blocks shown on the right above.
    Notice that the [Repeat] block only has the movements repeating 4 times. Repetitive movements rarely need to repeat forever so a [Repeat] block is used when only a certain number of repetitions is needed.

    If the [Repeat] block was replaced with the [Forever] block, the robot would just repeat in a square forever.
  • A [Forever] block is often used with a conditional statement in order to continuously check to see if the condition is true. In the stack of blocks above attached to the [Forever] block, notice how the robot will drive forward until it meets the condition of bumping into something with the bumper switch. If the bumper switch is pressed, the robot will turn. Otherwise, it will continue driving forward.

    This is a practical use-case of the [Forever] block. Imagine a self-driving sweeper that continues to drive forward until it runs into something, then it turns.

Step 4: The Stop and Go Challenge!

Sketched path of the movement of the robot showing a green square with arrows indicating moving counterclockwise in a square. At each corner there is a doublesided orange arrow indicating a motion at this point in the path.

  • Have your Clawbot drive in a square. 
  • Before each turn: 
    • The claw must be opened and closed.
    • The arm must be raised and lowered.
    • The Touch LED must show at least one color. 
    • At least one sound must play. 
  • The Clawbot cannot drive along a side of the square more than once. 
  • You can use the Repeating Actions example project as a starting point but save it as StopAndGo before making any changes.Project name dialog box in the VEXcode IQ Toolbar. Slot 1 is selected and the project name reads Stop and Go.

In your engineering notebook, plan the following:

  • Have the Driver and Recorder plan out your solution and predict what each block in your project will have the Clawbot do.
  • Have the Programmer Download and run your project to test it before submitting it.
  • Have the Builder make changes to the project as needed and communicate with the Recorder to take notes about what was changed during testing.