Vex V5 SmartMotor Encoder L/R Wheel Reading with a Drivetrain

How do you read the Vex V5 smart motor built in encoder for the left and right wheel separately when using a drivetrain? I believe you read the encoder value by using [motor].rotation(degrees). My Drivetrain has a left and right motor.

  1. If I use Drivetrain.rotation(degrees), what encoder value am I getting, the left or right wheel encoder value?
    2 How do I get the encoder value for the left and right motor individually?
  2. Does it need to be a Smartdrive, or can it be a drivetrain to read the encoder value?

I’m using the VexCode Pro software.
Thanks

Assuming you are using graphical configuration.
Check what VEXcode has called the motors by looking in robot-config.cpp, add them as extern in main.cpp (I don’t know why they are not added by default in the headers). Then just use them as follows.

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Drivetrain           drivetrain    1, 10           
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

extern motor LeftDriveSmart;
extern motor RightDriveSmart;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  
  while(1) {
    Brain.Screen.printAt( 10, 40, "%d", LeftDriveSmart.rotation(rotationUnits::deg) );
    Brain.Screen.printAt( 10, 60, "%d", RightDriveSmart.rotation(rotationUnits::deg) );
    this_thread::sleep_for(50);
  }
}

drivetrain.rotation is available if you have a gyro/IMU attached to the drive, rotation is the angle returned by that device.

6 Likes

That worked perfectly. Thank you very much. I appreciate it.

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