Ultrasonic Sensor Obstacle Course


#1

When coding, the initial goal was for the Mbot to be at a certain distance of an obstacle, then turn to follow a path of consecutive turns due to other obstacles, would the problem be my code or the Mbot itself?


#2

One thing I see immediately is that you don’t allow any time for your turns. This could be accomplished by inserting wait statements after the turn commands. The way the code is currently constructed would likely result in the robot appearing to always move in a straight line.


#3

we have considered that possibility, but it seems the problem was that the robot couldn’t detect the obstacle. When we tried inverting the operation command to “ultrasonic sensor distance > 20” the robot finally responded and turned but it was simply to far away from the obstacle


#4

I would suggest that you create a custom block to handle detection and test that in isolation before you add in any movement blocks because the obstacle detection is the key element here. It will also shorten your program by eliminating repeated code (which in turn will minimize the number of bugs). Another item to be aware of is that the ultrasonic sensor will return a value of 400 if it does not detect anything. If you get a 400 value, you might want to add a second read after a .1-.2 second pause to verify that you did not get a false reading.


#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.