Main Content

Getting Started with VEX V5 Distance Sensor

This example shows how to use the Simulink® Coder™ Support Package for VEX® V5 Robot Brain to run a Simulink model with Distance Sensor block on a VEX V5 Robot Brain. This example helps you to determine the distance, velocity, and relative size of object using distance sensor.

Prerequisites

Required Hardware

To run this example, you need the following hardware:

  • VEX EDR V5 Robot Brain

  • V5 distance sensor

  • V5 robot battery

  • Smart cables and USB A to Micro cable

Connecting the Hardware

1. Connect the V5 robot battery to the VEX EDR V5 Robot Brain.

2. Connect the V5 distance sensor to port 1 using smart cable.

Model

Open the vexv5_distanceSensor preconfigured Simulink model containing distance sensor.

The model illustrates the following:

  • Detect if an obstacle is in range using confidence readings.

  • If an obstacle is in range, classify the object either as small or large based on the size readings.

  • Display the results on VEX V5 Touch screen.

The output of Distance sensor can seen in scope block (Tune and Monitor the Model Running on VEX EDR V5 Robot Brain) or in VEX V5 touch screen (Creating Touch Screen Controls and Displays for VEX V5 Robot Brain).

The Object detection and size classification logic is modeled inside Print status on V5 Brain > Stateflow chart.

Build and Download the Simulink Model

Open the preconfigured model or create a Simulink model, build the model, and download it to the VEX EDR V5 Robot Brain.

1. Connect the V5 Robot Brain to your computer using the USB cable.

2. Open the Simulink model. If you are using the preconfigured model, go to step 5.

3. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box.

4. In the Configuration Parameters dialog box, navigate to the Hardware Implementation pane.

  • Set the Hardware board to VEX V5 Robot Brain.

  • In the Target Hardware Resources section, set the Build options to Build, load and run to automatically download the binary file on to the connected V5 Robot Brain.

Open the Hardware tab and click Build, Deploy & Start. The model is deployed to the V5 Robot Brain. This action builds, downloads, and runs the model as a standalone application on the VEX V5 Robot Brain device. A sample screen is shown below.

See Also

Distance Sensor