You are viewing a single comment's thread from:

RE: Part IV of Build Electronics: The Final Project

in #electronics7 years ago

This is very easy to follow @buildingrobotics! I never used an ultrasonic sensor before; encouraged me to look into how it works.

So do you just adjust that if condition for distance up if you want the robot to turn before bumping into something? Is the sensor that good?

Thanks for sharing!

Sort:  

Glad it was easy to understand and follow - thats my goal :D

By turning 'before' bumping into it, are you asking if the sensor is good enough to detect things soon enough to stop before the robot hits something?

In that case - if you were to adjust the condition up like you said, the robot would turn further away from the object. So for example, my current code makes the robot stop, back up, and turn if an object is detected less than 25 cm away from it. If you were to up this to, say, 50cm - the robot would turn much sooner and much further away.

I guess the only way to make sure it doesn't bump into things is to make sure your stopping within the reaction distance. There is a brief moment in time between object detection and the robot stopping. During this time, the robot is still moving forward for a brief moment, even though an object is close enough to meet the condition for stopping and turning. You have to make sure that the distance the robot travels during this time does not exceed the condition threshold, or else the robot will crash.

That may sound complicated, but let me give an example. Lets say it takes the robot 1 second to stop after detecting an object. During this 1 second, the robot travels 10cm. If your conditional statement that tells the robot to react to the object is less than this, your robot will crash because it doesn't have time to stop - by the time the signal is processed to stop the robot has already hit a wall. So make sure your robot's conditional to stop and turn is a greater distance than that it will travel before it can react.

The sensor is pretty good - and very fun - as long as the connections are good. It is good enough that if you wanted it to turn before hitting something, it could - But as I said, there is a little delay between detection and reaction that you have to account for, and yes, you could account for this by adjusting the if condition.

I hope that answers your question, sorry that must have been a long read :)
But yeah definitely experiment with ultrasonics, its really fun and has a lot of practicality.