Section 4.4 ActiveCode Exercise: Reactive Wall Avoidance Steering Logic
This exercise models a reactive controller that uses three distance inputs: left, front, and right. The goal is to return one steering command at each update step: move forward, steer left, or steer right.
Subsection 4.4.1 Controller Rules
Use a clear-path threshold of 1.0 meter and a danger threshold of 0.5 meters.
-
If front distance is under 0.5 meters, turn toward the side with more open space.
-
If left distance is under 0.5 meters, steer right.
-
If right distance is under 0.5 meters, steer left.
-
If none of the danger conditions apply, continue forward.
Subsection 4.4.2 Try It
Run the code below, then edit the
front, left, and right values in test_cases to explore other sensor readings.
Subsection 4.4.3 Test Case Interpretation
Example sensor readings are front = 0.4 m, left = 1.2 m, and right = 0.3 m. Since the front path is blocked and the left side has more clearance than the right side, the expected action is to steer left.
You have attempted of activities on this page.
