Heading Control Using VEX V5 Inertial Sensor
This example shows how to use the VEX® V5 Inertial Sensor block for heading control of VEX V5 robot.
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 inertial sensor
V5 robot battery
Two V5 smart motors with 18:1 gear
Smart cables and USB A to Micro cable
This image shows a simple two-wheel robot platform with two V5 smart motors connected to its two wheels. The two motors are controlled by a VEX EDR V5 Robot Brain.
Connecting the Hardware
1. Connect the V5 robot battery to the VEX EDR V5 Robot Brain.
2. Connect the left smart motor to port 3 and right smart motor to port 4 using smart cables.
3. Connect the V5 inertial sensor to port 1 using smart cable.
Model
Simulink Coder™ Support Package for VEX EDR V5 Robot Brain provides a preconfigured model that you can use for heading control using VEX V5 Inertial Sensor.
Open the vexv5_InertialSensor model.
In this model, the logic is modeled inside vexv5_InertialSensor > Stateflow chart.
The Stateflow® chart waits for the user to press the start button.
The robot remains in an idle state until you calibrate it and press the Start button. Then the robot turns 90 degrees and stops.
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. Switch on the V5 Robot Brain.
3. Open the Simulink model. If you are using the preconfigured model, go to step 6.
4. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box.
5. 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.
6. 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.
7. Once deployed, keep the robot steady on a level surface for 2 seconds for V5 inertial sensor to calibrate.
8. Disconnect the USB cable.
9. Once deployed, the user interface of the application contains the Start Button. Keep the model steady and press the Start button. The robot turns by 90 degrees and stops. Pressing the button again turns the robot by another 90 degrees and stops.
Note: If the robot turns in the wrong direction (counterclockwise), change the Direction gain value to -1.