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.
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?
Does it need to be a Smartdrive, or can it be a drivetrain to read the encoder value?
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.