Keeping a proportional command in range

A robot should hold itself 0.25 m from a wall using an ultrasonic sensor. The sensor faces the wall and can report distances up to 2.55 m. Positive Speed drives both wheels toward the wall, and negative Speed drives them away. Both drive motors are already running, and this loop sets their speed commands:


MATLAB
target = 0.25;  Kp = 300;            % percent per metre
while readButton(ev3, 'center') == 0
    d = readDistance(us);            % metres
    mL.Speed = Kp*(d - target);
    mR.Speed = Kp*(d - target);
    pause(0.05);
end


Speed must lie between -100 and 100. When the program starts, the sensor reads 0.80 m. Which change keeps every command within the allowed range while preserving proportional, bidirectional behaviour near the target?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More LEGO Robot Programming with MATLAB Questions: