My python script to scan for obstacles and find a path

This little app does an ultrasonic sensor scan with the servo. I only do the even degrees and limit the range from 30 degrees to 130 since that’s what’s directly in front of the bot. It saves the data to a list. If there are twenty results in a row that are of a safe distance, it turns towards that. If it’s all clear, it trots on forward. If there’s no path, it asks the user if it should turn around or quit.

It’s a work in progress and I’d love some feedback. Here’s the script on GitHub

I’ll be posting a blog post about it soon on my project’s website.

I want to figure out how to post this information to a website and move past the console to control it. I’m also working to be a lot more precise with finding a safe angle (my current solution is very crude).

Hey, really great project! Please let us know how it goes!

I have a quick question. On line 116:

while voltcheck():

I’m just curious (I think it’s clever!), but why did you do this? What was the motivation? I’m only curious, not criticizing; if you were having trouble with the power, this is a clever way to handle it!

Hi John,

I tried running the GPG off of a low voltage power supply and noticed sluggish movement. That’s what motivated me to install that check. But I’ve also been concerned with inconsistencies about stop commands being ignored (which is why I have loops on all stop commands) and variable responses to turns. So I thought it might be smart to have a power check. Oh, I also was concerned about a power spike if a wheel got caught or the like.

Having a lot of fun with the GPG and considering it for my classroom.


Hi Dan,
Can I get you to trade an email with me?

I also have an alternative to the 2 bots your looking at. I do not mean to take from what you are doing, but just briefly discuss options down the road, I’m learning this as well.

Mike spiked3 at gmail com


That’s great, thanks for the explanation! That’s a great way to implement that protection. Thanks!