Getting Started with VEX V5 Optical Sensor
This example shows how to use a VEX® V5 Optical sensor with Simulink® Coder™ Support Package for VEX® V5 Robot Brain. It illustrates how to obtain proximity and color readings in HSB scale. It uses a Stateflow® chart to check if a particular color is being detected or not.
Prerequisites
If you are new to Simulink, watch the Simulink Quick Start video.
Complete the Getting Started with Simulink Coder Support Package for VEX EDR V5 Robot Brain example.
Required Hardware
To run this example, you need these hardwares:
VEX EDR V5 Robot Brain
V5 optical 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 optical sensor to port 1 using smart cable.
Model
Open the vexv5_opticalSensor preconfigured Simulink model containing optical sensor.
In this model, the program logic for detecting color is modeled as a flow chart using Stateflow. At first, the proximity value is checked to see if an object is in range. If yes, it checks whether the brightness and saturation values are high enough for proper color detection. If brightness is low, consider increasing brightness of LED. Once these conditions are met, Hue value is checked. If Hue value is around 0, it is detected as Red color and so on. If, no color is detected among Red, Blue, Green and Yellow, the program returns "Unknown color".
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 example model.
3. 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.
4. Observe the readings on the display. The user interface displays the proximity, HSB values and detected color of the object as shown in this scren.
If you are not using the example model and using a Simulink model with Optical sensor block, then perform these steps.
1. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box.
2. 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.