Skip to main content

Lesson 1: What is an Algorithm?

In this Lesson, you will learn what an algorithm is and how using algorithms in VEXcode VR enables you to create VEXcode VR projects with more diverse behaviors. Algorithmic projects instruct the VR Robot to respond to its environment, which will be necessary to solve the Dynamic Castle Crasher Challenge.

Learning Outcomes

  • Identify that algorithms are made up of sequence, selection, and loops.
  • Identify that algorithms are precise sequences of instructions, implemented using programming languages, for processes to be carried out by a VR Robot.

Algorithms

Algorithms are precise sequences of instructions, implemented using programming languages, like VEXcode VR, for processes to be carried out by a VR Robot.

The basic elements of an algorithm are sequence, selection, and iteration.

  • Sequence - the order in which behaviors and commands are combined in a project in order to produce a desired result.     
  • Selection - is the use of conditional statements in a project. Conditional statements such as [If then], or [If then else] affect the project flow of a VEXcode VR project.   
  • Iteration - algorithms often use repetition to execute steps a certain number of times, or until a certain condition is met. This is also known as "looping." Iteration can change the project flow by repeating a behavior a specified number of times or until a condition is met.  

This example project from the Unit 8 challenge is an example of an algorithm. It includes a combination of loops, sensor data, and commands put together in a sequence to solve the Disk Mover Challenge.

The project uses iteration or “loops” to repeat actions and check reported sensor values.

A diagram of the project flow of a sample solution for the Disk Mover Challenge focused on identifying the different loops at play. The inner loops, with Repeat Until blocks, are identified as 'Loops to check sensor values' while the outer loops, with Repeat blocks, are identified as 'Loops to repeat actions'.

The way commands are sequenced and combined determines the behaviors of the VR Robot.  This project also includes selection which determines the parts of the project that are run based on the sensor condition.

The same sample solution for the Disk Mover Challenge, with the inner loop sections of the code connected to selection. The first inner loop, featuring a Repeat until block with the Down Eye near object parameter is labeled as 'Selection of which commands will be run is based on the sensor values reported by the Eye Sensor. If no object is detected, the VR Robot will drive forward. If an object is detected, then the VR Robot will stop'. The second inner loop, with a Repeat until block with a Distance Sensor value as a parameter is labeled 'Here selection is based on Distance Sensor values. If distance is greater than 200mm the robot will drive forward. If distance reported is less than 200 mm the VR robot will stop and energize the electromagnet.

Questions

Please select a link below to access the lesson quiz.

Google Doc / .docx / .pdf