I need help writing som obstacle avoidance codes


#1

Hello, im trying to code these:

  1. Straight-line collision prevention:

o Using the Mbot and block programming, create a program that would
move the robot in a straight line until an obstacle is sensed. Once an
obstacle is detected in front of the robot, it should stop and wait until
the obstacle is removed. Once the obstacle is removed, the robot
should continue its mission of moving forward. Congrats, you just
prevented a collision!
o The robot should be able to exhibit this collision-prevention behavior
multiple times in a row, in a single take. Demonstrate that the collision
prevention feature works when the obstacle is introduced and removed
multiple times.
o Questions:
:black_small_square: What is the unit of the ultrasonic sensor readings?
:black_small_square: What was the stopping distance threshold you used in your
code?
:black_small_square: When you look at your robot’s actual stopping distance from the
obstacle: is it more, less, or the same from your distance
threshold? Why?

  1. “Robot in a box”:

● Place the robot in an environment fully surrounded by obstacles.
Create a program that would move the robot inside this “box”
indefinitely. When an obstacle is detected, it should turn around and
move in a pseudo-random and obstacle-free direction. The robot
should not hit any obstacles at any time.

I tried a few trials and error and couldnt get the mbot to complete the task-i programmed the ultrasonic sensor distance to be less than 10 but it seems like the mbot just dont stop when obstacle is being detected. How should i approach the block codings? Do anyone have a sample code i can try using?


#2

Hello @yuuxire! I’m on a trip so I have to keep this short. But here are some tips for you.

  • The ultrasonic sensor readings are in centimeters.
  • A good obstacle detection distance is 30 cm.
  • The robot will usually drift past the stopping distance before it detects the obstacle.

For the robot in a box, just make a simple obstacle avoidance code or use an example one. Ask @CommandeR for help with that.

Good luck!