This works after a fashion but it seems the only way I can control the turning is to do a slow short duration turn then stop the wheels while ping rechecks the distances.
If the idea is that a turn to the right is needed because the way forward is blocked, turn for a period of time, then go forward, rather then stopping.
I think that using nested ifs can result in clearer code than so many ands, especially when conditions in the if and else if statements are the same.
if(chkDistanceFwd > dangerThresh)
{
if(chkDistanceFwd <= rightDistance && chkDistanceFwd <= leftDistance)
{
// Do something. What isn't really clear...
}
else if( /* some other stuff */ )
{
}
}