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!
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.
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.
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.â
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)