echo "Distance to front object:" . findObject($distance); if (!$carIsRunning) { $temp_command = 'w'; if ($command != $temp_command) { $command = $temp_command; runCar($motors, $command); $carIsRunning = true; } } } else { if ($distance <= $frenoDistance && ($distance != 0 || $carBackwards)) { if ($carIsRunning) { $temp_command = 's'; if ($command != $temp_command) { $command = $temp_command; stopCar($distance, $motors, $command); $carIsRunning = false; } echo "car stopped"; } if ($distance_LEFT >= $distance_RIGHT && $distance_LEFT >= $frenoDistance) { $carBackwards = false; $temp_command = 'a'; if ($command != $temp_command) { $command = $temp_command; turnLEFT($motors, $command); } echo "car turns left"; } else { if ($distance_LEFT < $distance_RIGHT && $distance_RIGHT >= $frenoDistance) { $carBackwards = false;
$temp_command = 's'; $command = $temp_command; brakeCar($motors, $command); $carIsRunning = false; $carBackwards = true; } } } } //else if if ($distance == 0) { if (!$carIsRunning) { $temp_command = 'w'; if ($command != $temp_command) { $command = $temp_command; runCar($motors, $command); } } noObject(); } usleep(100); // greenify } // while stopCar($motors, 'q'); sleep(1); fclose($sensors); fclose($motors); echo "\nCommunation over usb is now closed."; } // motors