This example shows how to use Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller to implement both Autonomous mode and Driver mode in the same Simulink model. Autonomous mode, Driver mode and the switch between the two is a format that applies only to the VEX Robotics Competition. This model should be used only in a VEX Competition field where a VEX field controller controls the modes of the VEX Robot.(you can also use a VEX Competition Switch that simulates a VEX field controller for match practice )
VEX Robotics Competition Starstruck is played on a 12’x12’ square field configured as seen above. Two alliances – one “red” and one “blue” – composed of two teams each, compete in matches consisting of a fifteen second autonomous period followed by one minute and forty-five seconds of driver-controlled play.
Introduction
Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller enables you to create and run Simulink models on a VEX microcontroller.
VEX Robotics Competition Nothing But Net is played on a 12’x12’ square field configured as seen above. Two alliances – one “red” and one “blue” – composed of two teams each, compete in matches consisting of a fifteen second autonomous period followed by one minute and forty-five seconds of driver-controlled play. The Tool Kit contains all of the tools you will need to build with VEX V5. The Open End Wrench fits VEX V5 nuts and standoffs, while the Hex Keys fit screws and shaft collars. The Performance Tool Kit contains tools that make working on your VEX V5 robot easier. If you’re using Star Drive screws or couplers, don’t forget to pick up Star Drive Keys or Screwdrivers to go along with them!
In this example you will learn how to program both Autonomous mode and Driver mode in the same Simulink model. The Driver mode will driver a DC motor mapped to the VEX gamepad, and the autonomous mode will driver a DC motor at maximum speed.
Prerequisites
If you are new to Simulink, we recommend watching the Simulink Quick Start video.
We recommend completing Getting Started with VEX Microcontroller Support Package.
Required Hardware
To run this example you will need the following hardware:
ARM Cortex-based VEX Microcontroller
VEXnet Gamepad and VEXnet keys
Standard DC Motor and Motor Controller
7.2V Battery
USB type A-Male to A-Male cable
VEXnet Competition Switch(or the VEX field controller used in the actual VEX Robotics Competition )
Task 1 - Hardware Connections
1. Connect the VEX Microcontroller to your computer with a USB cable.
2. Connect the DC motor to the motor pin3. Use the Motor Controller 29 cables to establish the connection between the motors leads and the pins on VEX Microcontroller.
3. Connect the battery supply to the VEX Microcontroller.
4. Connect the VEXnet Competition Switch to the Competition port on the VEXnet Gamepad using an Ethernet cable. On the VEXnet Competition Switch, set the Enable/Disable switch to Disable state and the Driver/Autonomous switch to Autonomous state.
Task 2 - Create a VEX Robotics Competition template model
1. In MATLAB, select HOME > New > Simulink Model > Blank Model > Create Model.
2. Click on the Library Browser to open the Simulink Library.
3. Select Simulink > Ports & Subsystems > Enabled Subsystem, drag and drop twice into your Simulink model. Rename the Enabled Subsystems Autonomous and Driver respectively.
4. Open vexarmcortexlib, drag and drop the Competition Switch block from the Gamepad library into your Simulink model.
5. Connect the Auto port of the Competition Switch to the Autonomous Enabled Subsystem, and the Driver port of the Competition Switch to the Driver Enabled Subsystem.
Task 3 - Implement Autonomous mode logic and Driver mode logic
1. Double click and open the Autonomous Enabled Subsystem. In the Autonomous Enabled Subsystem, delete the Inport, Outport and the connection between them.
2. Drag the Constant block from the Utilities in the VEX Microcontroller library. Set the value of the Constant block to 127.
3. Drag the DC Motor block from the Actuators library within the VEX Microcontroller library to your model. Rename it to SetMotor. Set the value of the Motor Channel to 3. Motor Channel is the pin to which the DC motor is connected.
4. Connect the Constant block to the input of the SetMotor block.
5. Click the Up to Parent button to return to the top level of the model.
6. Double click and open the Driver Enabled Subsystem. In the Driver Enabled Subsystem, delete the Inport, Outport and the connection between them.
7. Drag the DC Motor block from the Actuators library and the Gamepad Joystick block from the Gamepad library within the VEX Microcontroller library into your Simulink model.
8. Set the value of the Motor Channel to 3.
9. Connect the output of the Gamepad Joystick to the input of the DC Motor.
10. Save your model.
Task 4 - Build and Download the Simulink model
In this task you will open the Simulink model created in Task 2 and Task 3, build and download it to the VEX microcontroller.
1. Make sure to connect the VEX Microcontroller to your computer with a USB A-Male to A-Male cable.
2. Open the model created in task 2 and task 3 or, open the pre-configured model included for your convenience.
3. In the Simulink model, click on the Configuration Parameters button.
4. When the Configuration Parameters page opens up, navigate to the Hardware Implementation pane.
Set the Hardware board to ARM Cortex-based VEX Microcontroller.
In the Target Hardware Resources section, set the Build options to Build, load and run to automatically download the generated binary file on to the connected VEX microcontroller.
5. In the Configuration Parameters page, navigate to Solver pane and set the Solver to discrete (no continuous states).
6. Click OK.
7. In your Simulink model, click the Build Model button on the toolbar. The model will now be deployed to the VEX microcontroller.
Task 5- Use the VEXnet Competition Switch to set the model in Autonomous mode or Driver mode
In this task you will learn how to set the Example model in Autonomous mode or Driver mode.
1. Disconnect the USB cable from the PC, and connect the VEX Microcontroller to the VEX gamepad using VEXnet keys. Also ensure that the VEXnet Competition Switch is connected to the VEX Gamepad via an Ethernet cable.
2. Turn on the VEX microcontroller and the VEXnet gamepad.
3. Set the Enable/Disable switch to Enable state (the Driver/Autonomous switch is already set to Autonomous state in Task 1). Now the model is in Autonomous mode. You will observe that the motor rotates at Maximum speed.
4. Set the Driver/Autonomous switch to Driver state. Now the model is in Driver mode. The motor stops rotating at maximum speed. You can control the motor through joystick horizontal axis 1 on the VEX Gamepad.
Drivers Vex Robotics Others Try
5. Set the Enable/Disable to Disable state. This will disable the robot. All the actuators (motors) will be inactive in this state.
Summary
This example introduced the workflow for implementing Autonomous mode and Driver mode with the Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller
VEX GO Teacher Resources
Find Lab summaries, content, standards, and more.
VEX GO Cumulative Pacing Guide
A cumulative pacing guide for all VEX GO units.
VEX GO Activities
Bring Coding and STEM to life with these fun and easy to use VEX GO activities.
Select a Unit below to view the STEM Labs available inside.
Intro to Building
- Grades 3+
- Ages 8+
- 240 min
- 6 Labs
Explore the VEX GO Kit to learn the names and functions of key pieces by building structures to take on a voyage to Mars.
Essential Questions
- How do we manipulate materials when building?
- How can a design be affected by a constraint on materials?
- How can we communicate our design ideas and use the design process when working with a group?
Physical Science
- Grades 3+
- Ages 8+
- 240 min
- 5 Labs
Build and modify the Super Car to explore predicting an object's continued motion, change in motion, or stability.
Essential Questions
- How can we use patterns of change to predict an object’s continued motion, change in motion, or stability?
- How does force affect motion?
Simple Machines
Drivers Vex Robotics Others Learn
- Grades 3+
- Ages 8+
- 160 min
- 4 Labs
Build and test simple machines in order to examine how they change the direction or strength of a force in order to make work easier.
Essential Questions
- How can we conduct an investigation to observe cause and effect relationships?
- How do simple machines make work easier?
Parade Float
- Grades 3+
- Ages 8+
- 120 min
- 3 Labs
Design, build, and code a float for a parade using the VEX GO Kit.
Essential Questions

- How can anything be engineered to solve an authentic problem?
- How can the iterative process be used to create a sequence of movements for the float to accomplish in the parade?
Super Car
- Grades 3+
- Ages 8+
- 120 min
- 3 Labs
Investigate the variables that affect the movement of the Super Car.
Essential Questions
- What affects how the Super Car moves?
Ocean Emergency
- Grades 3+
- Ages 8+
- 120 min
- 3 Labs
Apply coding skills to help clean up the ocean using Code Base and VEXcode GO.
Essential Questions
- What is code?
- How can I make my robot move?
- How can I solve a problem using my robot?
Helping Hand
- Grades 3+
- Ages 8+
- 80 min
- 2 Labs
Investigate and modify the Adaptation Claw to help solve authentic problems.
Essential Questions
- How can I use tools to help solve authentic problems?
- How are mechanisms used in everyday life and work?
Robot Jobs
- Grades 3+
- Ages 8+
- 160 min
- 4 Labs
Build and code a Code Base robot to perform a job that is dull, dirty or dangerous.
Essential Questions
- How do I solve a challenge with the Code Base robot and VEXcode GO?
Fun Frogs
- Grades 3+
- Ages 8+
- 80 min
- 2 Labs
Investigate the different phases of the frog life cycle.
Essential Questions
- How do organisms change over their life cycle in relation to their environments?
- How can writing be used as a tool by scientists and other jobs?
Pendulum Game
- Grades 3+
- Ages 8+
- 80 min
- 2 Labs
Build and engineer a game using the motion and force of the pendulum to knock over objects.
Essential Questions
- How can I design a pendulum solve an authentic problem?
- How can I use the iterative process to continue to design and learn from my mistakes?
Fractions
- Grades 3+
- Ages 8+
- 40 min
- 1 Lab
Explore equivalent fractions using the Fractions build and your VEX GO Kit pieces to compare fractions by size.
Essential Questions
- What do the numerator and denominator of a fraction tell you?
- What patterns or relationships are there between equivalent fractions?
Robot Arm
- Grades 3+
- Ages 8+
- 200 min
- 5 Labs
Work with the Robot Arm, and its adaptations to learn what robotic arms can do and how they work!
Essential Questions
- What is a robot arm?
- How does a robot arm work?
Code Base
- Grades 3+
- Ages 8+
- 160 min
- 4 Labs
Use the Code Base and its sensor iterations to explore robot behaviors, controls, commands, and sensors through navigation challenges.
Essential Questions
- How can I use VEXcode GO with my robot?
Magnet Car
- Grades 3+
- Ages 8+
- 40 min
- 1 Lab
Students use the Magnetic Car to investigate the properties of magnetism and magnetic force.
Essential Questions
- How do magnets interact with each other and with other objects?
Look Alike
- Grades 3+
- Ages 8+
- 40 min
- 1 Lab
Explore the characteristics of living things and notice similar and different traits.
Essential Questions
- How do living organisms pass on traits?
Battle Boats
- Grades 3+
- Ages 8+
- 40 min
- 1 Lab
Create the Battle Boats game on a coordinate plane to plot points.
Eye Sensor
- Grades 3+
- Ages 8+
- 120 min
- 3 Labs
Use the Eye Sensor to navigate the Code Base robot.
Shape Shifter
- Grades 3+
- Ages 8+
- 80 min
- 2 Labs
Draw and classify different shapes using the Spirograph and Pantograph.
On the Move!
- Grades 3+
- Ages 8+
- 80 min
- 2 Labs
Investigate and predict patterns of motion.
Topo Map Mania
- Grades 3+
- Ages 8+
- 40 min
- 1 Lab
Explore the concepts of a topographical map.




