VEXcode V5 Assignment -
Programming the V5
Mecanum Drive
Part 1
By: Mr. Gravitt
Programming a Mecanum Drive
The Mecanum Can Move in 6
Different Ways
The Mecanum Program
• There are numerous ways/styles this can be
programmed.
• I/we are going to start with a simple 2-joystick
tank drive & scarfing side to side with 2-buttons.
• Going to set it up so that it either scarfs side to
side or tank drives & NOT both simultaneously.
• It is possible to program it to do that. However,
that is best accomplished using math formulas,
& right know we are going to keep it as simple as
possible.
In Part 2 we can do
this program.
It makes all 6 ways of
movement function &
yes it’s really cool, but
for now lets start out
writing a shorter
program that does 4
ways of movement!
This Mecanum Drive Program
This program
will be able to:
• 4 Motor
2 Joystick
Tank Drive
While
Simultaneously &/or independently be
able to do Strafing Drive with R1 & R2
Buttons.
This Mecanum Drive Program
This program won’t do these 2 drive
motions.
• However, we can come back later & add
them to this program in “Mecanum Part 2.”
PROGRAMS!
IMPORTANT NOTES:
1. You can program a VEX robot
with more than 1 controller.
2. Use Autonomous programs &/or
Remote.
3. Use sensors &/or not.
4. You can program all the different
Joysticks &/or Buttons in many ways.
5. For most robots they can be programmed in so
many different ways that the numbers are just literally
astronomically large!
THEREFORE: I’m going to show you 1 way of programming your robot &
just using one joystick. However, just remember that there is a huge
number of ways that a robot can be programmed!!!
IMPORTANT - #1
2 Different Mecanum Wheels
• There are 2
different
Mecanum
Wheels – a
Right & a Left
that are not
the same.
IMPORTANT #2 - Wheels Pattern
• They must be
placed in an X
pattern in
order to
function.
• &, each must
have it’s own
independent
motor.
Here is 1 Type/Version of
Mecanum Program
The Program
STRAFING
• Started with a “When
R1-RIGHT Started,” a “Forever Loop,”
& a “If () Then, Else”
STRAFING R1 & R2 statement to divide the
program into 2 parts (Tank
STRAFING Drive & Strafing Drive.)
R2-LEFT
• The Strafing Drive program
has 2 “If then statements
2 JOYSTICK
4 MOTOR dividing it into 2 parts,
TANK
DRIVE
either (Drive Left or Drive
Right.)
The VEXcode V5 Software
• Click on the VEXcode
V5 Software Icon
• This version of the
software is the same
on both MAC & PC.
• This version allows you to program using
Blocks &/or a Blocks/Text Hybrid.
Step 1.1 - Open VEXcode V5 Software
• Either click on the VEXcode V5 ICON on
your desktop or search for “VEX” in the
search bar at the bottom of your Windows
screen.
Step 1.2 - Open VEXcode V5 Software
• This is what the software looks like when
opened.
Step 1.3 - Open VEXcode V5 Software
• There are not any Motion Options? They
will appear once we place a motion item.
Step 2 – Lets Name the Program & Save It
• Click here, select where to save it (Server
&/or Flash Drive), name it, & save it.
Step 3.1 Open Devices
• Click on the Devices Icon located here.
Step 3.2 - Opened Devices
• This blue box opens, this is the devices
section..
Step 3.3 - Add a Device
• We need to tell
the software
what devices
(motors, sensors,
&/or controllers)
that we are
plugging into our
robot, what ports
we are plugging
them into, &
name them.
• Click Add a Device.
Step 3.5 - Select
Controller
• We are going to put
each Motor in
individually &
individually Name each
motor.
Step 3.6 – Click Done
• Just going to use 1
controller.
• We are going to
program the controls
manually in the
program code.
• Click Done – It will label
it “Controller1”
automatically.
Step 4.1 - Select Motors
• The Controller1 should be
there.
• Next step we are going to
put each Motor in
individually & we are
going to individually name
each motor.
• Click On - “Add a Device.”
Step 4.2 - Select Motor
• We are going to put each
Motor in individually &
individually Name each
motor.
• NOTE: I like putting
motors in ports 1,10,11,
& 12. Makes neat wire
management, & that’s
what I did here.
However, they can be
put in any port!
• Software asks us Step 4.3 - Select
which PORT we LEFT FRONT MOTOR
have the LEFT
FRONT Motor
plugged into?
• If you plugged it
into a different port
select that port
now.
• I’m Clicking On
PORT1.
• & Then Clicking
Done.
NOTES:
• The software asks
us what color
Gear Cartridge we
have in the
motor?
• You can see the color of cartridge the motor
has in it through this window.
• Red = 36:1 @ 100RPM (High Speed Low Torque)
• Green = 18:1 @ 200RPM (Middle Speed & Torque)
• Blue = 6:1 @ 600RPM (Low Speed High Torque)
Step 4.4 Add Motor • Name Motor –
LFMotor - keeping it
short!
• Select Forward &
Reverse Directions –
won’t know until
debugging whether
or not in needs to be
forward or reversed.
• Select the Green 18:1
200RPM Gear
Cartridge
• Click Done.
Step 4.5 – Motor
• Controller1 & LFMotor
should both be there.
• Click on Add a Device.
• Next Steps: we are going
to add the other 3
motors. I did the motors
in a clockwise pattern,
Starting in the Top Left
of: LFMotor, RFMotor,
RRMotor, & LRMotor.
Motion &
Drivetrain
• Motion &
drivetrain code
blocks options
have populated
since we have
installed at least
controller & at
least 1 motor.
Step 5.1
RFMotor
• We are going to add
the RFMotor.
• Click on Add Motor.
• Software asks us Step 5.2 - Select
which PORT we RIGHT FRONT MOTOR
have the RIGHT
FRONT Motor
plugged into?
• If you plugged it
into a different port
select that port
now.
• I’m Clicking On
PORT10.
• & Then Clicking
Done.
Step 5.3 Adding RFMotor
• Name Motor –
RFMotor - keeping it
short!
• Select Forward &
Reverse Directions –
won’t know until
debugging whether
or not in needs to be
forward or reversed.
• Select the Green
18:1 200RPM Gear
Cartridge
• Click Done.
Step 5.4 Right Front Motor Installed
Should have
• Controller1
• LFMotor –
port1
• & RFMotor
port10
NEXT STEPS:
Again Click On -
Add a device.
Step 6.1
RRMotor
• We are going to
add the RRMotor.
• Click on Add Motor.
• Software asks us Step 6.2 - Select
which PORT we RIGHT REAR MOTOR
have the RIGHT
REAR Motor
plugged into?
• If you plugged it
into a different port
select that port
now.
• I’m Clicking On
PORT20.
• & Then Clicking
Done.
Step 6.3 Adding RRMotor
• Name Motor –
RRMotor - keeping it
short!
• Select Forward &
Reverse Directions –
won’t know until
debugging whether
or not in needs to be
forward or reversed.
• Select the Green
18:1 200RPM Gear
Cartridge
• Click Done.
Step 6.4 Right Rear Motor Installed
Should have
• Controller1
• LFMotor –
port1
• RFMotor -
port10
• RRMotor –
port20
NEXT STEPS:
Again Click On -
Add a device.
Step 7.1
RRMotor
• We are going to add
the LRMotor now.
• Click on Add Motor.
• Software asks us Step 7.2 - Select
which PORT we LEFT REAR MOTOR
have the LEFT REAR
Motor plugged
into?
• If you plugged it
into a different port
select that port
now.
• I’m Clicking On
PORT11.
• & Then Clicking
Done.
Step 6.3 Adding LRMotor
• Name Motor –
LRMotor - keeping it
short!
• Select Forward &
Reverse Directions –
won’t know until
debugging whether
or not in needs to be
forward or reversed.
• Select the Green
18:1 200RPM Gear
Cartridge
• Click Done.
Step 7.4 Right Rear Motor Installed
Should have these
Devices
• Controller1
• LFMotor port1
• RFMotor port10
• RRMotor port20
• LRMotor port11
NOTE: This is manually
entered 4 motor setup
that can & will be used
on many robots.
Step 8.1 Code Viewer
• You click here & here & you can VIEW, BUT
NOT TYPE &/OR EDIT the code of the blocks
program.
Step 8.2 Code in Python
• You click here & here & you can see the
code in Python.
Step 8.3 Code in C++
• You click here & here & you can see the
code in C++.
Step 8.3 Code in Populates Blocks
• You click can see that your blocks are now
populated with dropdowns with your motors.
Step 8.4 Code in TEXT
• You click here to transform from BLOCKS coding
to TEXT coding. NOTE YOU CANNOT CONVERT
BACK TO BLOCKS!!!
Step 8.5 TEXT Project in Python
• You should see the following.
• WARNING: I haven’t found a way to go back to Blocks!!!
Step 8.6 TEXT Project in C++
• You should see the following.
• WARNING: I haven’t found a way to go back to Blocks!!!
Step 8.7 – After Conversion to Text
• You can start typing in code of Python or C++.
• However, it is now a TEXT Project & it will not
convert back to BLOCKS.
Your Ready to Program
• We are ready to start programming by dragging &
placing blocks!
Step 9 – Starting a Program
• We are going to
start out with a
simple “When
Started”
statement.
• NOTE: There are a
number of
different ways of
starting a program.
• You can also have
more than one.
Step 10 – Forever Loop
• We are going to drag
in a simple “Forever
Loop” statement.
• NOTE: There are a
number of different
loops available.
• NOTE 2: You can also
have more than one
loop & loops can be
inside one another.
Step 11 – If () then do () in not do Else()
• We are going to drag in
a “If, () Then do (), Else
do ()” statement into
the forever loop.
• This will divide the
program into 2 parts.
• One part will run all the
time the “Condition”
isn’t met.
• So, when “Then” does
happen it will stop that
part from running.
Step 12 – Set the LFMotor Velocity
• We are going to
drag in “Set Motor
Velocity”
Statement.
• Now we don’t want
it at 50% Change to
100%.
• We are going to
add a condition
into the velocity.
• & that Condition Statement is going to be the #3
Joystick.
Step 13 – Controller Joystick
• Now, we are
ADDING to the
(100% velocity)
with Controller1 &
#3 INPUT.
NOTE: The (100% • #3 is the Left
velocity) is still there
hidden behind the Joystick.
Controller Sensing • You need to use
Statement.
the drop down box
to select the #3
controller position.
Step 14 – Spin the LFMotor Forward
• We are going
to drag in a
simple spin
(motor)
(forward)
direction
block into
the Else
statement.
• Just happened to turned out, after debugging,
that Forward was the correct direction of spin.
• & the robot you built might be different!
Step 15 – Repeat with other 3 Motors
• Add the other 3 motors
the same way as
before.
• LFMotor - 100%
Velocity & FORWARD
• RFMotor - 100%
Velocity & REVERSE
• RRMotor - 100%
Velocity & REVERSE
• LRMotor - 100%
Velocity & FORWARD
NOTE: Your Bots motor directions may differ! You’ll have
to figure that out while debugging your bot.
Step 16 – Repeat with other 3 Controllers
• Add the other 3
Controllers
statements the
same way as before.
• With the LFMotor &
LRMotor to Joystick
#3 the LEFT SIDE
JOYSTICK.
• & the RFMotor &
RRMotor to Joystick
#2 the RIGHT SIDE
JOYSTICK.
This is a 4 Motor Tank Drive Program
If you put this set in a
Forever Loop & a
When Started, this
program is a:
• “Tank Drive
Program”
• Single Controller
• 2-Joystick
• 4-Motor
• 100% Velocity
You can run 4-motor tank drive program & Debug your
bot, check motor positions, & motor directions.
Step 17 – Math Operation of “OR”
• Drag in Math Operation of “OR” into the
“CONDITION” of the “If () Then”.
• We want to have 2 Conditions not just 1 Condition.
Step 18.1 – Controller Sensing Pressed?
• Drag in Controller Sensing Pressed Statement
into one of the Blanks in the “OR” Statement.
• Do it again, & put another one in the other
Blank of the “OR” Statement.
Step 18.2 – Controller Sensing Pressed?
• Use the dropdowns
to select what
Buttons to use.
• I Used R1 & R2
which are the
Trigger Buttons on
the Right Side of the
joystick. I’m right
handed so that
works well for me.
• Although, you can choose any of the buttons.
Step 18.3 – Controller Sensing Pressed?
• Put
another
Controller
statement
in.
• Use the
dropdowns
to select
R2.
Step 18.3 – Controller Sensing Pressed?
Lets read the Statement.
• When Started, Run Forever, If Controller1 R1 is
pressed or Controller1 R2 is pressed then run ().
• So, whatever is inside the [then () else] will run
when either button is pressed.
Step 19.1 – (2) “If () Then” Statements
Into the
“If Controller R1 or R2 Then Else”
• Add 2 “If ()
Then”
statements.
• One for each
button.
• One is for R1.
• & the other
will be for R2.
Step 19.2 –Adding Control Statement
• Add a Controller Sensing Command to the
Condition Statement
• Selected R1
Step 20.1 – Set LFMotor @ 50%
• Set LFMotor Velocity to 50% or maybe even less.
• Strafing doesn’t work well at high speeds, the
wheels spin/slip, so we are going to turn them
down.
Step 20.2 – Spin LFMotor
• Insert a Spin LFMotor
• On my robot it’s forward but on yours it may be
different.
Step 21.1 – Set RFMotor @ 50%
• Set RFMotor Velocity to 50% or maybe even less.
• Strafing doesn’t work well at high speeds, the
wheels spin/slip, so we are going to turn them
down.
Step 21.2 – Spin RFMotor
• Insert a Spin RFMotor
• On my robot it’s forward but on yours it may be
different.
Step 22.1 – Set RRMotor @ 50%
• Set RRMotor
Velocity to 50%
or maybe even
less.
• Strafing doesn’t
work well at
high speeds, the
wheels
spin/slip, so we
are going to
turn them
down.
Step 22.2 – Spin RRMotor
• Insert a Spin RRMotor
Step 22.3 – Spin RFMotor
• On my robot it’s REVERSE, but on yours it may be
different.
Step 23.1 – Set LRMotor @ 50%
• Set LRMotor Velocity to 50% or maybe even less.
• Strafing doesn’t work well at high speeds, the
wheels spin/slip, so we are going to turn them
down.
Step 23.2 – Spin LRMotor
• Insert a Spin LRMotor
Step 23.3 – Spin LFMotor
• On my robot it’s REVERSE, but on yours it may be
different.
So, this does the
Strafing to the
Right & 2 Joystick
Tank Drive
• Top Strafing Right
• Next, we need to
make it do the
Strafing to the Left.
• Bottom is 2 Joystick
Tank Drive Program
Step 24.1 – Strafing Left
• Add a
Controller
Sensing
Command
to the 2nd
Condition
Statement
• Selected
R2 Button
on the
Controller
Step 24.2 – Set LFMotor @ 50%
• Set LFMotor Velocity to 50% or maybe even less.
• Strafing doesn’t work well at high speeds, the
wheels spin/slip, so we are going to turn them
down.
Step 24.3 – Spin LFMotor
• Insert a
Spin
LFMotor
• On my
robot it’s
REVERSE
but on
yours it
may be
different.
Step 25.1 – Set RFMotor @ 50%
• Set RFMotor
Velocity to 50%
or maybe even
less.
• Strafing doesn’t
work well at
high speeds, the
wheels
spin/slip, so we
are going to
turn them
down.
Step 25.2 – Spin RFMotor
• Insert a
Spin
RFMotor
• On my
robot it’s
REVERSE,
but on
yours it
may be
different.
Step 26.1 – Set RRMotor @ 50%
• Set RRMotor
Velocity to 50%
or maybe even
less.
• Strafing doesn’t
work well at
high speeds, the
wheels spin/slip,
so we are going
to turn them
down.
Step 26.2 – Spin RRMotor
• Insert a
Spin
RRMotor
• On my
robot it’s
FORWARD,
but on
yours it
may be
different.
Step 27.1 – Set LRMotor @ 50%
• Set LRMotor
Velocity to 50%
or maybe even
less.
• Strafing doesn’t
work well at
high speeds, the
wheels spin/slip,
so we are going
to turn them
down.
Step 27.2 – Spin LRMotor
• Insert a
Spin
LRMotor
• On my
robot it’s
FORWARD,
but on
yours it
may be
different.
The Program
STRAFING • This is Part 1 of the
R1-RIGHT
Mecanum Drive
STRAFING R1 & R2 Program.
STRAFING
• It will “Strafing”
R2-LEFT
(Crabwalk)
2 JOYSTICK
sideways.
4 MOTOR
TANK
DRIVE
• & 2 Joystick Tank
Drive
Download It To Your Bot
• Download it to your robot & take it for a test
drive.
Download It To Your Bot
• Downloading to your robot, once done take it for
a test drive
• In Part 2 we can add the other 2 motions, spin
around front axles, & diagonal movements to this
project.
End of Assignment
VEXcode V5 Assignment
Programming the V5
Mecanum Drive
Part 1
By: Mr. Gravitt