Error in Robot Mesh Studio V5 Python code for Section 5: Drivetrain

Hello,

One of our students today (14 OCT 2020) had issues using V5 python in Robot Mesh Studio where code for moving the drivetrain would compile without error or warning but would not function. The issue is that two fold:

A). The solution code is in error (looks like might be copy paste to EDR instead of V5?)
B). The hint code in the DOCs page does not match what is required for section 5 to work.

Specifically, the reference to drivetrain in the solution code is wrong because it is missing
import drivetrain
and because the module call is to vex not drivetrain.

Below is the working solution code for 5.2. It looks like all the 5.x code has not been tested on V5 as it all failed.

# VEX V5 Python Project
import sys
import vex
from vex import *
import drivetrain

#region config
brain             = vex.Brain();
motor_right       = vex.Motor(vex.Ports.PORT1, vex.GearSetting.RATIO18_1, True)
motor_left        = vex.Motor(vex.Ports.PORT2, vex.GearSetting.RATIO18_1, False)
bumper_front      = vex.Bumper(brain.three_wire_port.a)
sonar_c           = vex.Sonar(brain.three_wire_port.c)
digital_out_red   = vex.DigitalOut(brain.three_wire_port.e)
digital_out_green = vex.DigitalOut(brain.three_wire_port.f)
dt                = drivetrain.Drivetrain(motor_left, motor_right, 319.1764, 292.1, vex.DistanceUnits.MM)
#endregion config


#Example 2 - Using a drivetrain to make the robot move forwards and backwards
dt.drive_for(vex.DirectionType.FWD, 100, vex.DistanceUnits.CM)
dt.stop(vex.BrakeType.BRAKE)
sys.sleep(2)
dt.drive_for(vex.DirectionType.REV, 100, vex.DistanceUnits.CM)
dt.stop(vex.BrakeType.HOLD)

One last point: In python it is generally discouraged to add a line like
from vex import *
because it adds a large number of globals. Most python experts suggest you import only the elements that you specifically need as the footprint of the code is often much smaller and will often execute faster.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.