Skip to main content

Section 4.2 Distance Sensor Arrays and Local Obstacle Avoidance

While a single front-facing sensor can tell a robot when to stop, it cannot tell the robot which way to turn to avoid a collision. Most small mobile robots utilize a multi-sensor arrayβ€”such as three distance sensors positioned on the Left, Front, and Right of the chassisβ€”to construct a 180-degree local perception field.
Picture the robot’s chassis as a small circle with three sensors mounted around its forward half: one pointing straight ahead (Front), one angled out to the left (Left), and one angled out to the right (Right), together sweeping a 180-degree arc in front of the robot.
Figure 4.2.1. A multi-sensor array expands local perception and provides directional information for choosing a clear path around obstacles.

Subsection 4.2.1 Real-World & VEX Robotics Applications

  • Real-World Example (Autonomous Vehicles & Robotic Lawn Mowers): Self-driving cars use arrayed Time-of-Flight (ToF) sensors and ultrasonic transducers along their front and side bumpers. If a vehicle detects a stalled car directly ahead (front_dist < safe_threshold), it uses its side-looking sensors to determine whether the left lane or right shoulder has enough clearance to perform a lane change without striking a guardrail or neighboring vehicle.
  • VEX Robotics Example (VEX V5 Distance Sensors & Ultrasonic Range Finders): In VEX robotics competitions, equipping your drivetrain with a trio of VEX V5 Distance Sensors (or VEX Ultrasonic Range Finders) gives your robot continuous spatial awareness. During autonomous routines or maze navigation labs, if the front sensor detects an arena perimeter wall or an opponent’s robot, the robot can inspect the left and right sensor values to automatically turn toward whichever side has more open room, avoiding dynamic collisions during high-stakes matches.

Subsection 4.2.2 Intuitive Sensor Rule Logic

By evaluating relative distances across all three sensors simultaneously, the robot can make clear steering decisions using simple conditional logic:
  • Clear Path Ahead: If front_dist > safe_threshold, the path is wide openβ€”drive straight ahead at normal speed.
  • Obstacle Ahead (Right Side is Clearer): If front_dist < safe_threshold and right_dist > left_dist, the obstacle is blocking the front-leftβ€”steer Right into open space.
  • Obstacle Ahead (Left Side is Clearer): If front_dist < safe_threshold and left_dist > right_dist, the obstacle is blocking the front-rightβ€”steer Left into open space.
  • Trapped (Obstacles on All Sides): If all three distance readings fall below the safety threshold, the robot is boxed inβ€”execute an emergency stop, reverse backward, or pivot 180 degrees in place.

Subsection 4.2.3 Section 4.2 Interactive Exercises

Subsubsection 4.2.3.1 Exercise 4.2.1: Parsons Problem β€” Sensor Array Decision Logic

Reorder the Python code blocks to construct the steering decision logic for a 3-sensor array (left_dist, front_dist, right_dist).

Checkpoint 4.2.2.

Arrange the blocks to form a complete function choose_steering_action that drives straight when the front is clear, and otherwise steers toward whichever side has more open space.

Subsubsection 4.2.3.2 Exercise 4.2.2: Virtual Roomba Sensor Loop Challenge

Implement the conditional logic for a virtual roomba driving through a hallway.
Task: Complete the steer_roomba function using if/elif/else statements.
  • If front_dist >= 0.6, return "FORWARD".
  • Otherwise, if left_dist > right_dist, return "TURN_LEFT".
  • Otherwise, return "TURN_RIGHT".
You have attempted of activities on this page.