Reactive behaviour
Responds directly to a current measurement, such as slowing when an obstacle is close. It can be fast and simple, but may lack memory or a wider plan.
A robot becomes autonomous when it can interpret sensor information, estimate where it is, choose an action and check the result. Explore the ideas behind obstacle-aware mobile robots, from a single distance sensor to navigation systems.
An autonomous robot repeatedly measures its environment and internal state, interprets those measurements, selects an action and observes what happened. Autonomy is not a single sensor or clever algorithm. It is a complete loop with defined limits and recovery behaviour.
A simplified sense–estimate–plan–act loop. Real systems also monitor faults, timing, confidence and communication.
Responds directly to a current measurement, such as slowing when an obstacle is close. It can be fast and simple, but may lack memory or a wider plan.
Uses a representation of goals, routes or the environment to choose actions. Planning can improve task performance but needs computation and reliable information.
Combines a planner with fast reactive rules. For example, follow a planned route while a protective local controller stops for an unexpected obstacle.
Estimates distance from the travel time of an acoustic pulse and its echo. Soft, angled or narrow objects can return weak echoes; nearby objects may fall inside the minimum range.
Reflective IR sensors can detect surfaces or nearby objects. Optical time-of-flight modules estimate distance from reflected light, but sunlight, target reflectivity and field of view matter.
Encoders estimate wheel rotation. Gyroscopes measure angular rate and accelerometers measure specific force. Neither gives perfect position by itself.
Cameras provide rich visual information, lidar measures ranges across directions, and GNSS can provide global position outdoors. Cost, environment, compute and update rate influence suitability.
Compare range, field of view, update rate, resolution, latency, noise, environmental sensitivity, interface, voltage levels, power consumption, mounting and cost. Read the exact module datasheet; similarly named breakout boards may have different electrical requirements.
Sensor fusion combines information from multiple sources to estimate a quantity or state. A simple weighted average is useful for learning, but a real estimator must consider units, uncertainty, timing, correlation, outliers and sensor failure.
Enter two measurements of the same stationary target, and assign each a relative weight. Higher weight means the reading contributes more to this simplified estimate. The weights are not automatically calibrated sensor accuracy values.
Illustrative weighted average only. Check that both sensors observe the same target at nearly the same time.
Formula: estimate = (A × weight A + B × weight B) ÷ (weight A + weight B). A zero total weight is invalid.
Store measurement timestamps and status alongside values. Check range limits, update age, sudden jumps and consistency with other sensors. If confidence is low, slow down, stop, request assistance or switch to a defined fallback behaviour.
Localisation estimates the robot's pose: position and orientation. Mapping represents relevant features of the environment. A robot may know its movement relative to a starting point without knowing its global location.
Pose is commonly represented by x position, y position and heading angle θ in a two-dimensional mobile robot.
Integrates measured motion from a known starting pose. Wheel odometry is simple but accumulates error from slip, wheel diameter mismatch, missed counts and floor irregularities.
Known visual markers, beacons, GNSS or mapped features can correct accumulated drift when detected reliably.
Represent space as cells with estimated occupied/free likelihood. Resolution, map size, sensor uncertainty and update rate affect usefulness.
Simultaneous localisation and mapping estimates robot pose while building or updating a map. It is a family of methods, not one sensor or a guaranteed accurate result.
Path planning selects a route through a known or represented environment. Local obstacle avoidance reacts to nearby changes. A planned path is not a promise that the route remains clear.
Conceptual grid only. A real planner needs map coordinates, robot footprint, obstacle inflation, route costs and sensor updates.
A robot needs enough distance to detect, decide and stop. A simplified physical estimate is braking distance = speed² ÷ (2 × deceleration). The robot also travels during sensor and control latency. The calculator below is an ideal estimate, not a certified safety limit.
Real stopping distance varies with surface, load, battery, tyres, driver behaviour and control delays.
Extend the differential-drive rover from Module 20 with a forward-facing distance sensor. The goal is to detect a nearby object, stop, perform a controlled scan or turn, and continue only when the path appears clear. This is a learning exercise, not a collision-prevention product.
This compact example illustrates a reactive policy. It assumes the motor helper functions from your driver setup are adapted to the actual breakout and that a valid distance reading is returned in centimetres. Start with wheels lifted and verify the stop behaviour before a slow floor test.
// Arduino Uno-compatible board + TB6612FNG-style driver.
// Verify breakout pin labels, motor polarity and supply ratings first.
const byte PWMA = 5, AIN1 = 7, AIN2 = 8;
const byte PWMB = 6, BIN1 = 9, BIN2 = 10, STBY = 4;
const byte TRIG_PIN = 2, ECHO_PIN = 3;
const float STOP_DISTANCE_CM = 25.0;
const unsigned long ECHO_TIMEOUT_US = 25000UL;
float readDistanceCm() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(3);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
unsigned long duration = pulseIn(ECHO_PIN, HIGH, ECHO_TIMEOUT_US);
if (duration == 0) return -1.0; // no valid echo
return duration * 0.0343f / 2.0f;
}
void setMotor(byte in1, byte in2, byte pwmPin, int command) {
command = constrain(command, -255, 255);
digitalWrite(in1, command >= 0 ? HIGH : LOW);
digitalWrite(in2, command >= 0 ? LOW : HIGH);
analogWrite(pwmPin, abs(command));
}
void stopMotors() {
analogWrite(PWMA, 0); analogWrite(PWMB, 0);
digitalWrite(AIN1, LOW); digitalWrite(AIN2, LOW);
digitalWrite(BIN1, LOW); digitalWrite(BIN2, LOW);
}
void driveForward(int pwm) {
setMotor(AIN1, AIN2, PWMA, pwm);
setMotor(BIN1, BIN2, PWMB, pwm);
}
void turnRight(int pwm) {
setMotor(AIN1, AIN2, PWMA, pwm);
setMotor(BIN1, BIN2, PWMB, -pwm);
}
void setup() {
pinMode(PWMA, OUTPUT); pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT); pinMode(BIN1, OUTPUT); pinMode(BIN2, OUTPUT);
pinMode(STBY, OUTPUT); digitalWrite(STBY, HIGH);
pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT);
stopMotors();
}
void loop() {
float distance = readDistanceCm();
if (distance < 0 || distance <= STOP_DISTANCE_CM) {
stopMotors(); // stop on invalid or near reading
delay(150);
turnRight(90); // short, supervised manoeuvre
delay(300);
stopMotors();
delay(100);
} else {
driveForward(90); // begin slowly; tune for the actual chassis
}
}
This is a deliberately simple blocking teaching sketch. Confirm that the driver input polarity matches your motors; reverse the relevant motor command if needed. A fixed timed turn is not localisation-aware and may not clear the obstacle. A more robust controller needs non-blocking timing, repeated valid measurements, sensor plausibility checks, motor feedback, bounded retries and an explicit fault state.
DRIVE, STOP, SCAN, TURN and FAULT states.For deeper learning, build the basic rover first, record what it does, then add one autonomy capability at a time. For project-specific design reviews, troubleshooting or guided robotics training, EazyLife offers personalised paid support.
Explore these open lessons at your own pace. For personalised explanations, project-specific troubleshooting, guided practical training or masterclasses, EazyLife offers paid support tailored to your learning goals.
Free or sponsored lesson referrals may be available through active programmes; they are not guaranteed.