How do I store, recall, and print the distance travelled by the robot?

Hello everyone, I’m trying to have my robot go an unknown distance where it will stop, and I need to store the distance travelled by the robot because I have to map it out on the screen. I’m not telling it to go a certain distance, but I am telling it to drive forward. Is there a way to store the distance travelled when a certain condition has been met?

I’m not sure which programming language you are using but here is some pseudocode to help you:

drive_motors.spin(forward);

while (not condition):
   wait

drive_motors.stop();

distance = drive_motors.rotation()/(wheel_size*pi);

I don’t entirely understand what the project is supposed to do, but if you need it to move multiple times you could append distance to a list/vector, maybe use PID to increase accuracy (probably overkill), maybe make this into a function to make it easier to use multiple times, or whatever.

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