We’re moving to a new home! Our website is currently in test mode while we update and transfer our content. Some pages and resources may be temporarily unavailable. We’ll be back with all resources shortly. Thank you for your patience.

VEX V5 PYTHON | 01.3 DRIVETRAIN GROUPS

Guide objective

Organise verified motors into left and right sides for two-, four- and six-motor drivetrains. Use a consistent Python interface to test both sides together.

01 | A DRIVETRAIN HAS TWO SIDES

A differential-drive robot steers by changing the motion of its left and right sides. Each side might use one, two or three motors. Your code should express what each side needs to do rather than repeat every motor command throughout the program.

Complete the port, cartridge and direction checks from 01.2 Motor Configuration first. A group cannot repair an incorrect motor setting.

02 | COMPARE THE THREE LAYOUTS

The total includes both sides
Total drive motorsLeft sideRight sidePython approach
TwoOne motorOne motorUse individual Motor objects
FourTwo motorsTwo motorsOne MotorGroup for each side
SixThree motorsThree motorsOne MotorGroup for each side

Four motors means two per side, not four per side. Six means three per side. Additional motors can increase available drive effort when the build supports it, but do not automatically increase top speed: cartridges, external gearing, wheels, load and traction still matter.

A motor’s side is determined by the wheels it drives, not just where its casing sits on the chassis.

03 | CHOOSE A CLEAR CONFIGURATION STRUCTURE

For the examples below, declare the motor ports explicitly in your own code. This lets you see the physical wiring, cartridge setting and reversal flag directly above the groups.

Use one configuration method for each device. Start with a blank text project, keeping its generated VEX import and Brain setup intact. Do not add these same drive motors in the Devices panel. If they are already there, remove their entries using that panel before adding the manual definitions.

Put all team comments, manual motor declarations, groups, settings and functions below # Begin project code. Never put them inside the generated region. The Brain is already defined there, so do not create it again.

The port numbers and reversal flags below are examples. They use your suggested four-motor layout: left ports 3 and 4, right ports 1 and 2. Match the wiring and cartridges to your robot before running any code.

04 | TWO-MOTOR DRIVETRAIN

# =============================================================================
# TEAM [MY TEAM NAME / NUMBER]
# =============================================================================
#
# ROBOT CONFIGURATION
# - TWO-motor drivetrain:
#       Left  = Ports 3
#       Right = Ports 1
# - Example drive cartridges: blue, 6:1, nominal 600 rpm
# - Example reversal: left False, right True
#   VERIFY these settings against your robot.
#
# Put this below # Begin project code, outside the generated region.
# These drive motors must NOT also be defined in the Devices panel.

# =============================================================================
# TWO-MOTOR DRIVETRAIN
# =============================================================================
left_motor_1 = Motor(Ports.PORT3, GearSetting.RATIO_6_1, False)
right_motor_1 = Motor(Ports.PORT1, GearSetting.RATIO_6_1, True)

# =============================================================================
# LEFT AND RIGHT DRIVE INTERFACE
# =============================================================================
left_drive = left_motor_1
right_drive = right_motor_1

With one motor per side, left_drive and right_drive are aliases for the existing motor objects.

05 | FOUR-MOTOR DRIVETRAIN

# =============================================================================
# TEAM [MY TEAM NAME / NUMBER]
# =============================================================================
#
# ROBOT CONFIGURATION
# - FOUR-motor drivetrain:
#       Left  = Ports 3, 4
#       Right = Ports 1, 2
# - Example drive cartridges: blue, 6:1, nominal 600 rpm
# - Example reversal: left False, right True
#   VERIFY these settings against your robot.
#
# Put this below # Begin project code, outside the generated region.
# These drive motors must NOT also be defined in the Devices panel.

# =============================================================================
# FOUR-MOTOR DRIVETRAIN
# =============================================================================
left_motor_1 = Motor(Ports.PORT3, GearSetting.RATIO_6_1, False)
left_motor_2 = Motor(Ports.PORT4, GearSetting.RATIO_6_1, False)
right_motor_1 = Motor(Ports.PORT1, GearSetting.RATIO_6_1, True)
right_motor_2 = Motor(Ports.PORT2, GearSetting.RATIO_6_1, True)

# =============================================================================
# LEFT AND RIGHT DRIVE INTERFACE
# =============================================================================
left_drive = MotorGroup(left_motor_1, left_motor_2)
right_drive = MotorGroup(right_motor_1, right_motor_2)

The Motor declarations identify the individual ports. MotorGroup then combines the existing objects on each side; it does not create additional motors.

06 | SIX-MOTOR DRIVETRAIN

# =============================================================================
# TEAM [MY TEAM NAME / NUMBER]
# =============================================================================
#
# ROBOT CONFIGURATION
# - SIX-motor drivetrain:
#       Left  = Ports 3, 4, 5
#       Right = Ports 1, 2, 8
# - Example drive cartridges: blue, 6:1, nominal 600 rpm
# - Example reversal: left False, right True
#   VERIFY these settings against your robot.
#
# Put this below # Begin project code, outside the generated region.
# These drive motors must NOT also be defined in the Devices panel.

# =============================================================================
# SIX-MOTOR DRIVETRAIN
# =============================================================================
left_motor_1 = Motor(Ports.PORT3, GearSetting.RATIO_6_1, False)
left_motor_2 = Motor(Ports.PORT4, GearSetting.RATIO_6_1, False)
left_motor_3 = Motor(Ports.PORT5, GearSetting.RATIO_6_1, False)
right_motor_1 = Motor(Ports.PORT1, GearSetting.RATIO_6_1, True)
right_motor_2 = Motor(Ports.PORT2, GearSetting.RATIO_6_1, True)
right_motor_3 = Motor(Ports.PORT8, GearSetting.RATIO_6_1, True)

# =============================================================================
# LEFT AND RIGHT DRIVE INTERFACE
# =============================================================================
left_drive = MotorGroup(left_motor_1, left_motor_2, left_motor_3)
right_drive = MotorGroup(right_motor_1, right_motor_2, right_motor_3)

The Motor declarations identify the individual ports. MotorGroup then combines the existing objects on each side; it does not create additional motors.

READ THE MOTOR DECLARATION

left_motor_1 = Motor(Ports.PORT3, GearSetting.RATIO_6_1, False)

left_motor_1 is the name you choose. Ports.PORT3 identifies the actual Brain socket. GearSetting.RATIO_6_1 matches a physically installed blue cartridge. False keeps normal motor direction; True reverses it.

Use RATIO_18_1 for a green cartridge or RATIO_36_1 for a red one. A software setting does not physically change gears. Mirrored mounting often requires different reversal flags, but the example’s left/right flags are not universal.

07 | KEEP THE MOVEMENT INTERFACE CONSISTENT

All three layouts now use left_drive and right_drive. A movement helper can use those names without needing to know how many motors are on each side.

Choose one grouping example matching your robot. Declare each Motor before its MotorGroup. Define the groups before helper functions are called. Keep one copy of each declaration and one startup call.

A MotorGroup controls one collection of motors. It is not itself a complete Drivetrain object: it does not know wheel diameter, robot width or how many millimetres the robot has travelled. The next guide introduces geometry.

STRUCTURE YOUR TEAM PROJECT

Use descriptive comment banners to keep a growing file readable. Comments document the robot; the Motor declarations are what actually configure it. Update both when wiring changes.

# =============================================================================
# TEAM [MY TEAM NAME / NUMBER]
# =============================================================================
# ROBOT CONFIGURATION
# - FOUR-motor drivetrain:
#       Left  = Ports 3 and 4
#       Right = Ports 1 and 2
# - Two-stage intake: Ports 7 and 6
# - Record the actual cartridge and reversal for every motor.

# =============================================================================
# FOUR-MOTOR DRIVETRAIN
# =============================================================================
# Declare drive motors here.

# =============================================================================
# LEFT AND RIGHT DRIVE GROUPS
# =============================================================================
# Create left_drive and right_drive here.

# =============================================================================
# INTAKE AND OTHER MECHANISMS
# =============================================================================
# Declare only devices physically present on your robot.
# Keep intake motors OUT of left_drive and right_drive.

# =============================================================================
# TEST SETTINGS
# =============================================================================
TEST_SPEED = 15
TEST_TIME_MS = 300

# =============================================================================
# MOVEMENT HELPER FUNCTIONS
# =============================================================================
# Define stop_drive() and forward_test() here.

# =============================================================================
# MAIN TEST
# =============================================================================
# Define main() here.

# =============================================================================
# PROGRAM START
# =============================================================================
# Call main() once here, after all definitions.

This is a layout guide, not a complete running program. The two-stage intake is included as a documentation example: add its real declarations only when those motors are fitted, and keep them separate from the drive groups.

For this lesson’s runnable test, use your chosen complete two-, four- or six-motor declaration block, then the short both-sides test below. The generated imports and Brain configuration remain above your user code.

08 | A SHORT BOTH-SIDES TEST

Start with the robot securely supported and its wheels clear of the floor. Keep hands and cables clear, and be ready to stop the program. Once directions are verified, repeat in a clear floor area if appropriate.

Paste the following after your chosen grouping example, below the project-code marker. Replace earlier test functions and their startup call so only this test runs.

# FIRST: choose ONE complete motor-declaration example above.
# SECOND: match its ports, cartridges and reversal flags to your robot.
# Put all user code BELOW # Begin project code.

TEST_SPEED = 15
TEST_TIME_MS = 300

def stop_drive():
    left_drive.stop(BRAKE)
    right_drive.stop(BRAKE)

def forward_test():
    left_drive.spin(FORWARD, TEST_SPEED, PERCENT)
    right_drive.spin(FORWARD, TEST_SPEED, PERCENT)
    wait(TEST_TIME_MS, MSEC)
    stop_drive()

def main():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Forward test")
    forward_test()
    brain.screen.set_cursor(2, 1)
    brain.screen.print("Stopped")

main()

The spin commands start each side without waiting for a distance target. Both therefore run during the same 300 ms pause, before the helper stops both. Their starts are close together, not guaranteed simultaneous to the same instant.

The test duration is a motor-direction check, not a calibrated distance command. Low power may not overcome a heavy load; inspect the mechanism if it stalls rather than immediately increasing speed.

09 | UNDERSTAND FORWARD, REVERSE AND TURNING

Assumes each side’s positive direction has been verified
Intended robot actionLeft sideRight side
ForwardFORWARDFORWARD
ReverseREVERSEREVERSE
Turn on the spot to the rightFORWARDREVERSE
Turn on the spot to the leftREVERSEFORWARD

The turn examples describe a standard differential-drive layout viewed from above. They give a direction, not a turn angle. Wheel slip and geometry affect how far the robot turns.

Do not put left and right motors in a single group if you need to steer them independently. Keep intake, lift and other mechanisms out of the drivetrain groups.

10 | COMMON GROUPING MISTAKES

  • Robot spins during a forward test: revisit individual motor direction and which side each motor drives.
  • Motors strain against each other: stop and check reversal and mechanical connections. Never use more power to make fighting motors cooperate.
  • NameError: compare spelling with your manual Motor declarations and check definition order.
  • One side has an extra motor: inspect group membership against your port map.
  • Left moves, then right moves: check for blocking movement calls. Position commands can wait by default, so sequential calls may not move both sides together.
  • Robot drifts on the floor: matching commands do not guarantee identical physical motion. Check wheels, gearing, drag, traction and load before adding correction code.

CHALLENGES | VERIFY THE WHOLE DRIVETRAIN

  1. Map the layout: write the TEAM and ROBOT CONFIGURATION comment sections. List every drive motor under left or right with its port, cartridge and verified direction.
  2. Create the interface: use the matching complete two-, four- or six-motor declaration block. Confirm its ports match your wiring and those motors are not duplicated in the Devices panel.
  3. Supported-wheel test: run the short forward test and record each wheel’s observed direction.
  4. Reverse test: change both direction arguments to REVERSE, download again and verify the opposite motion.
  5. Turning test: with adequate clearance, test one side forward and the other reverse using a short duration. Record the resulting turn direction.
  6. Explain the abstraction: show how the same forward_test function can use any of the three grouping layouts.
  7. Prepare for geometry: record wheel diameter and any external gear or sprocket ratio for the next guide.
Success evidence

A saved project with one correct left/right interface, a labelled drive-motor map and a test log for forward, reverse and turning. All user code remains outside the generated region.

OFFICIAL REFERENCES

This is an independent learning resource. VEX and VEXcode are trademarks of their respective owners.