 # Drive for Distance

Hello! I am here to talk about Drive for Distance. I have created a previous thread about the most accurate turning and going forward. I seem to need some help. How do you calculate these variables, they are copied and pasted and I am very confused. I code with VEXCODE text so please only use this to help me. Also if you already know I would love to get the info on all this with normal omi wheels and normal grip wheels. I am pretty sure the degreestoroatate is how far but what does this mean and is it in CM so it will go how far CM i say?

``````// wheelDiameter is the measurement of a wheel from edge to edge in centimeters.
double wheelDiameterCM  = 10.16;

// travelTarget will define how far we want the robot to move in centimeters.
double travelTargetCM = 20;

// Calculate wheel circumference: circumference = (wheelDiameter)(PI)
double circumference = wheelDiameterCM * 3.141592;

// Now we know the robot will travel the Circumference per 360 degrees of rotation or (circumference / 360 degrees).
// We also know that are target distance is defined as travelTargetCM, but we do not know the degrees to of rotation. (traveTargetCM / ?)
// Using propotional reasoning we know (circumference / 360) = (travelTarget / degreesToRotate).
// Solving for our unkown (degreesToRotate) we get: degreesToRotate = (360 / travelTargetCM) / circumference
double degreesToRotate = (360 * travelTargetCM) / circumference;``````

The code you posted doesn’t include anything that would actually make the robot move, so i’ll assume its just a snippet. In this example:

• wheelDiameterCM is the diameter of the wheel that the encoder is mounted to (for example, if you have 4in omnis, this variable should be set to ‘4’
• travelTargetCM is the distance you want the robot to travel

You don’t need to change the last two variables (degreesToRotate & circumference). The first will calculate the circumference of the diameter you entered for the program to use for the next variable. The last one just translates the desired distance from cm to encoder ticks (something which the robot can actually use).

Alright lets say I would want to measure in inches is that possible if so how. Also yes I did snippet because I understand how to make it move but not the varibles

You can just use inches instead of cm, as the math remains true as long as you use the same units throughout the function. Make sure you change the names of the variables though.

1 Like

Example? I dont understand

Sorry I am a bit new to vexcode it self I used to use VCS but I understand there the same kinda but never used this type of code yet I used the normal go foward but looking for better accuracy.

Ok, so the math of this function uses 2 user defined variables (wheel diameter and distance to travel). These need to be in the same units to work properly. You can use whatever unit of distance you want: miles, yards, planck units, whatever.

1 Like

ok so making sure, the degress thing is a function that makes the robot turn a specific amount of degrees, but what im confused about is (if i am correct) the travelTarget defined is a constant (which you have set to 20) so how can u put in different degrees to turn if at is a constant?>

there are no functions, degreesToRotate is a variable, which becomes equal to the degrees the wheel/motor needs to rotate for the wheel to move 20 cm. 20 cm is also a constant predetermined value they want to use as a target. You could condense this into a function to allow for any target though.