How to calculate drive train distance Vex IQ 2nd gen brain

Hey everyone

We need help to calculate the distance travelled.
We are trying to get our robot to drive more accurately during autonomous and are trying to write our own function but need to know to calculate the distanced travelled. We are using a gen 2 brain. Looks like only thing we can calculate is the rotation and heading for the drivetrain. If anyone could help that would be awesome! :sunglasses:

Assuming that you’re using 200mm wheels (omni or travel wheels), it goes something like this:

1 wheel rotation = 200mm or 7.874in and 1 motor rotation = 360 degrees

So, in a robot with no gears or a 1:1 gear ration, 1 motor rotation/spinning a motor for 360 degrees = 200mm/7.874in of travel.

If you have a gear ratio for speed, that becomes a multiplier to distance. So, if you have a 1 (motor rotation):2 (tire rotation) ratio (like a 48:24 tooth or 24:12 tooth setup), 1 motor rotation/360 degrees * 2 = 400mm/15.748in of travel for every full motor rotation.

Adjust this as necessary for your robot’s setup

1 Like

Thank you for your response.

How can we get that value in the Vex IQ code blocks and set it to a variable called distance?

I don’t see a way to calculate that in the drivetrain blocks. I see rotation and heading only.

I want to use it as part of a function to calculate the distance traveled.

I’m not sure I’m following what you’re trying to get to. If you’re using the drivetrain setup, then you would already know the distance traveled, because it should be what you commanded it to drive with a “drive forward/backward for X mm/in” command. It doesn’t look like VexCode allows you to read back any of the motor information that would otherwise be required to calculate that.

For the level of control you seem to be looking for, you need to move away from the drivetrain setup and go to individual motor control, incorporating things like Caution Tape Robotics’ Drive Straight and Precise Turn code to start.

1 Like

I’m not quite sure what you are asking. EngineerMike pretty much told you how to calculate the number of degrees to turn the motors, given the distance in inches. It seems as if you are trying to get a value from the motor for the number of degrees that it has turned? I don’t think that value is provided for drivetrain. It is available for individual motors. You might look at some of the YouTube videos for Vex IQ PID or “DriveStraight.”

1 Like

I think this is what you mean, this function will calulate how much degrees you need to turn.
This would be a function that returns how many degrees needed to turn.
int degreesNeeded(double wheelDiameter,double desired){
double circumfrance = (wheelDiameter/2)*(wheelDiameter/2)*M_PI;
double inchesPerDegree = circumfrance/360;

return Round(desired/inchesPerDegree);

}
or in math terms
d = degrees needed
w = wheel diameter
t = target
d(w,t) =360t /( (w/2)*(w/2)*pi)

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