VEX Code
How to Program Your Robot
Role of the Programmer
Having a successful robot takes a team effort between humans and machines.
The human’s job:
• identify the task
• plan a solution in small steps
• Explain the steps to the robot
through a
computer program
The robot’s job:
• follow the instructions it is given,
• carry out the plan.
Computer Programming
Because humans and machines do
not speak the same language,
a programming language must be
used to translate the necessary
instructions from human to robot.
Instructions written in programming
languages are called programs, or
code. There are many different types
of programming languages.
Programming
Languages:
There are many different
types of programming
languages.
• Scratch or Block Coding
• Text-based Coding:
• Python
• Html
• C/C++
• Arduino Coding
Path Planning
o Path Planning: the process of
decomposing a project into the
smallest possible behaviors that you
can then attach code to.
o Path planning is a more effective way
to code your robot to solve a challenge
or accomplish a task than guessing
and checking.
Advantages of
Path Planning
It enables you to:
§ Build your project more
effectively and efficiently
§ Troubleshoot your code
more easily
§ Talk through a project
with your team to reach
an agreement
Steps to Path Planning
Identify Break Attach
Identify the task of Break that task Attach code to each
the robot – What is down into the of those behaviors.
it that you want the smallest behaviors
robot to do? you can .
Tips for Path Planning
o Be specific when planning your path – the ‘smallest’
behaviors means driving and turning for specific distances.
o Path planning has many advantages, including that it
enables you to:
ü Build your project more effectively and efficiently
ü Troubleshoot your code more easily
ü Talk through a project with your team to reach
consensus
Path Planning and
Pseudocode
o Before you write any code, you will
want to plan out what you want the
robot to do in English
o This is called pseudocode.
o Break it into simple steps.
o Then you will use the code blocks to
create the code.
Pseudocode Example
Code Your
Robot to Move
o You will use VEX Code IQ
software to control the
movements of your
robot.
o You will do this by
dragging blocks into the
program.
o You can change values in
the blocks.
Types of Blocks
o Hat
o Stack
o Boolean
o Reporter
o C Blocks
Hat Blocks
Start a stack of blocks and are
shaped to attach blocks below
them.
Stack Blocks
o Perform main commands.
They are shaped to attach
above or below other
stack blocks.
o You can change numbers
or click on the arrows to
see choices.
Boolean Blocks
Return a condition as either
true or false and fits inside
any blocks with hexagonal
(six-sided) inputs for other
blocks.
Reporter Blocks
o Report values in the form
of numbers and fits inside
any blocks with oval
inputs for other blocks.
C Blocks
o Loop the block(s) within
them or check if a
condition is true or false.
o They are shaped to attach
stack blocks above,
below, or inside them.
Adding Blocks
§ Every code begins
with the yellow “Get
Started” block.
§ To write code – you
drag blocks from the
left side to connect to
the previous blocks.
Reordering
Blocks
§ The code gets performed
in the order that it is
written.
§ If you make a mistake, you
can reorder the blocks by
moving them.
Deleting Blocks
1. Drag a block to the left.
2. Click on a block and
right click – the chose
delete.
3. Click on a block in hit the
delete key.
Moving Sections to Save
Them Without Deleting
• Only blocks that are connected
will be run by the robot.
• Any blocks on the side, they
are not used (unless you create
a new “function” which we may
learn later.)
Saving
Your File
Downloading the Code
to the Robot
1. Connect the Brain to your programming device using the
USB cable.
2. Press the check mark button on the Brain to turn it on.
3. Once successfully connected, the Brain icon at the top of
the window will turn green.
4. Select the Download button to download your program.
5. Run your program by selecting the Run button. You can
also run programs directly on the robot brain using the
on-screen menu.
Sample Task:
Step 1: Identify the Problem
Step 2:
Describe a series of actions that solves the
problem
Step 3:
Write the plan into a program that the robot
can understand
Step 4: Test and improve.
The program will probably not work on the
first try. Test every part of the program and
make fixes as needed.
Brain Commands
• There is a screen on the brain
that you can use to disply
messages and shapes.
Draw a
Rectangle
• The values inside of the command are called
parameters.
• The parameters to program a rectangle are
set up as: (X, Y, W, H).
X =starting X-position
Y = the starting Y-position
W = the width of the shape
H = the height of the shape.
Filling in a Shapes
Other Things to Send
to Brain
o You can draw other shapes like
circles and lines
o You can send text
o You can change the color of a
single pixel
Help for any
block is
available
Challenge Activity
Use the draw and print blocks for the VEX
IQ Brain to make a display or animated
billboard for everyone to see!
Requirements:
1. Use at least three draw
shape blocks
2. Set each shape with a pen
color or fill color
3. Use at least one wait block to create
an "animation"
4. Write text or a message using
the print block
Advertising Challenge
Activity
Variables
o You can save a value by
creating a variable and
giving it a name.
o Then every time you use
the name it will know the
value.
o Or you can do math with
the variable.
Functions o If you don’t want to continuously repeat
code, you can create a new HAT BLOCK
My Blocks.
o Then you can call your code as needed.