I have been experimenting with making accurate autonomous code without external sensors (using only the motor encoder values). I’ve seen multiple calculations and formulas to convert motor degrees to actual inches of movement or degrees of the robot turning. Having not found a formula that worked, I turned to the VEX drivetrain object that takes in the necessary values for motor degree conversion and has inbuilt driving and turning functions.
Below is my code that is incredibly inaccurate (the drive function massively overshoots and the turn functions spins well over 360 degrees for a 90 degree turn).
motor_group leftDriveMotors = motor_group(leftFront, leftBack);
motor_group rightDriveMotors = motor_group(rightFront, rightBack);
drivetrain robotDrive = drivetrain(leftDriveMotors, rightDriveMotors, 220, 317.5, 317.5, vex::distanceUnits::mm, 0.75);
//NON FUNCTIONAL AUTON
void drive(int inches, std::string direction){
if(direction == "fwd"){
robotDrive.driveFor(vex::directionType::fwd, inches, vex::distanceUnits::in);
}
else{
robotDrive.driveFor(vex::directionType::rev, inches, vex::distanceUnits::in);
}
}
void turn(int degrees, std::string direction){
if(direction == "left"){
robotDrive.turnFor(vex::turnType::left, degrees, vex::rotationUnits::deg);
}
else{
robotDrive.turnFor(vex::turnType::right, degrees, vex::rotationUnits::deg);
}
}
This is the constructor: vex::drivetrain::drivetrain(motor_group &l, motor_group &r, double wheelTravel=320, double trackWidth=320, double wheelBase=130, distanceUnits unit=distanceUnits::mm, double externalGearRatio=1.0)
The wheel travel comes from VEX’s website (2.75 inch wheels); the trackWidth and wheelBase were all measured in inches (then converted to millimeters); and our gear ratio is 48teeth gear motor powered and 36teeth gear on the wheel (thus a 36/48 or 0.75 gear ratio).
Any ideas what I’m doing wrong? Or any ideas on how to use another approach? Last year I just used a trial and error approach that was accurate enough for driving but pretty inaccurate for turning, so I want a more consistent approach (again no sensors).
Let me know if you need more details (I recorded a video of it failing but the forum won’t let me upload videos here).