Asynchronous hardware sensor

Not sure if Asynchronous is the right term. My project is a tank with two joysticks controlling the motors for each track. So far it is working well but I am having trouble implementing a “crash sensor” The sensor is an ultrasonic distance sensor which calculates distance and compares with a preset distance to put the motors in reverse. This works but the way I have implemented it has in my mind an odd side effect.

The tank move pretty quickly so I need to update the distance measured frequently in to reverse the motors in time. At present the main loop looks like this but I appreciate that you should not add additional conde to this loop.

[Unformatted code removed by moderator]

@sjgc please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code, so that it displays correctly.
Triple backticks look like this:

Copy and paste these characters if you can’t find the correct character on your keyboard.