Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am building an autonomous 4WD vehicle for a project at school. I have already written the code (using Python 2) to operate it, and it takes commands through raw input. Everything works great as far as the robot itself is concerned, but now I am trying to incorporate an ultra-sonic sensor on the front of it so it will stop when it comes within 20 cm of an obstacle. The sensor is wired correctly and gives me distance feedback when using sample code I found online. The sample code gave me a function which gives me distance feedback every second and prints it out. The problem I am having is, how do I incorporate this into the code I have already written? How do I have the sensor constantly pinging for distance while also running the while loop for my robot commands? Can I use a while loop within another while loop? I am only somewhat competent with python so any help or suggestions would be greatly appreciated.

What I have tried:

I have tried using a while loop in another while loop. I cannot think of what else can be done.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900