Lesson 14: miniAuto Obstacle Avoidance

Intelligent obstacle detection and avoidance with autonomous navigation

🚧 Smart navigation - avoiding obstacles autonomously

🎯 Learning Objectives

Obstacle Avoidance Goals:

  • Implement real-time obstacle detection systems
  • Create intelligent avoidance algorithms
  • Combine multiple sensors for robust navigation
  • Develop autonomous exploration behaviors

Advanced Skills:

  • Design reactive navigation systems
  • Implement multi-sensor data fusion
  • Create adaptive behavior algorithms
  • Optimize autonomous exploration patterns

🚗 Section 1: miniAuto Platform Overview (20 minutes)

miniAuto Hardware Components

The miniAuto platform integrates all the sensors and actuators we've learned about into a cohesive robotic system:

  • Microcontroller: Arduino-compatible brain for processing
  • Motor Driver: H-bridge for controlling DC motors
  • Ultrasonic Sensor: For distance measurement and obstacle detection
  • IMU (Inertial Measurement Unit): For orientation and movement tracking
  • Camera Module: For vision-based navigation
  • Communication Module: WiFi/Bluetooth for remote control

Software Architecture

miniAuto programming follows a modular approach with distinct layers:

  • Hardware Abstraction Layer: Low-level sensor and actuator control
  • Control Layer: Motion planning and execution
  • Behavior Layer: High-level autonomous behaviors
  • Application Layer: User-defined tasks and missions

💡 Key Insight

The miniAuto platform demonstrates how individual components work together to create intelligent, autonomous behavior - the same principles used in full-scale autonomous vehicles!

🎮 Section 2: Basic Motion Control (20 minutes)

Fundamental Movement Commands

miniAuto provides high-level functions for basic movements:

#include <miniAuto.h>

miniAuto robot;

void setup() {
  robot.begin();
  Serial.begin(9600);
  Serial.println("miniAuto Ready!");
}

void loop() {
  // Basic movement commands
  robot.moveForward(100);    // Move forward at speed 100
  delay(1000);               // Move for 1 second
  
  robot.turnRight(90);       // Turn right 90 degrees
  delay(500);                // Wait for turn to complete
  
  robot.moveBackward(50);    // Move backward at speed 50
  delay(1000);
  
  robot.turnLeft(180);       // Turn left 180 degrees
  delay(1000);
  
  robot.stop();              // Stop all movement
  delay(2000);               // Wait 2 seconds before repeating
}
                

Speed and Direction Control

Fine-tune movement with precise speed and direction control:

// Differential drive control
void moveWithDifferentialSpeed(int leftSpeed, int rightSpeed) {
  robot.setMotorSpeeds(leftSpeed, rightSpeed);
}

// Smooth acceleration and deceleration
void smoothMove(int targetSpeed, int duration) {
  int currentSpeed = 0;
  int steps = 20;
  int speedIncrement = targetSpeed / steps;
  
  // Accelerate
  for (int i = 0; i < steps; i++) {
    currentSpeed += speedIncrement;
    robot.moveForward(currentSpeed);
    delay(duration / (steps * 2));
  }
  
  // Decelerate
  for (int i = steps; i > 0; i--) {
    currentSpeed -= speedIncrement;
    robot.moveForward(currentSpeed);
    delay(duration / (steps * 2));
  }
  
  robot.stop();
}
                

⚠️ Safety Note

Always test movement commands in a safe, open area. Start with low speeds and gradually increase as you become familiar with the robot's behavior.

📡 Section 3: Sensor Integration (20 minutes)

Reading Sensor Data

Access sensor information to make intelligent decisions:

void readAllSensors() {
  // Ultrasonic distance measurement
  float distance = robot.getDistance();
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  
  // IMU orientation data
  float heading = robot.getHeading();
  Serial.print("Heading: ");
  Serial.print(heading);
  Serial.println(" degrees");
  
  // Battery voltage monitoring
  float voltage = robot.getBatteryVoltage();
  Serial.print("Battery: ");
  Serial.print(voltage);
  Serial.println(" V");
  
  // Light sensor readings
  int lightLevel = robot.getLightLevel();
  Serial.print("Light Level: ");
  Serial.println(lightLevel);
}
                

Sensor-Based Decision Making

Use sensor data to control robot behavior:

void sensorBasedNavigation() {
  float distance = robot.getDistance();
  
  if (distance > 30) {
    // Path is clear - move forward
    robot.moveForward(80);
    Serial.println("Moving forward - path clear");
  }
  else if (distance > 15) {
    // Obstacle detected - slow down
    robot.moveForward(30);
    Serial.println("Slowing down - obstacle ahead");
  }
  else {
    // Obstacle too close - stop and turn
    robot.stop();
    delay(500);
    robot.turnRight(45);
    delay(1000);
    Serial.println("Turning to avoid obstacle");
  }
}
                

🎯 Pro Tip

Combine multiple sensors for more robust navigation. For example, use both ultrasonic and IMU data to maintain straight-line movement while avoiding obstacles.

🤖 Section 4: First Autonomous Program (20 minutes)

Simple Obstacle Avoidance

Create your first fully autonomous program that navigates around obstacles:

#include <miniAuto.h>

miniAuto robot;

// Autonomous navigation parameters
const int SAFE_DISTANCE = 25;
const int SLOW_DISTANCE = 40;
const int NORMAL_SPEED = 70;
const int SLOW_SPEED = 30;

void setup() {
  robot.begin();
  Serial.begin(9600);
  Serial.println("Autonomous Navigation Started!");
  
  // Initial sensor calibration
  robot.calibrateSensors();
  delay(2000);
}

void loop() {
  autonomousNavigation();
  delay(100);  // Small delay for stability
}

void autonomousNavigation() {
  float frontDistance = robot.getDistance();
  
  // Display current sensor reading
  Serial.print("Distance: ");
  Serial.print(frontDistance);
  Serial.print(" cm - ");
  
  if (frontDistance > SLOW_DISTANCE) {
    // Clear path - move at normal speed
    robot.moveForward(NORMAL_SPEED);
    Serial.println("Normal speed forward");
  }
  else if (frontDistance > SAFE_DISTANCE) {
    // Obstacle detected - reduce speed
    robot.moveForward(SLOW_SPEED);
    Serial.println("Reduced speed forward");
  }
  else {
    // Obstacle too close - execute avoidance maneuver
    avoidObstacle();
  }
}

void avoidObstacle() {
  Serial.println("Obstacle avoidance activated!");
  
  // Stop immediately
  robot.stop();
  delay(500);
  
  // Check left and right distances
  robot.turnLeft(45);
  delay(800);
  float leftDistance = robot.getDistance();
  
  robot.turnRight(90);
  delay(800);
  float rightDistance = robot.getDistance();
  
  // Return to center
  robot.turnLeft(45);
  delay(800);
  
  // Choose best direction
  if (leftDistance > rightDistance && leftDistance > SAFE_DISTANCE) {
    Serial.println("Turning left to avoid obstacle");
    robot.turnLeft(90);
    delay(1000);
  }
  else if (rightDistance > SAFE_DISTANCE) {
    Serial.println("Turning right to avoid obstacle");
    robot.turnRight(90);
    delay(1000);
  }
  else {
    Serial.println("No clear path - backing up");
    robot.moveBackward(50);
    delay(1000);
    robot.turnRight(180);
    delay(2000);
  }
}
                

Program Structure Analysis

This autonomous program demonstrates key robotics concepts:

🛠️ Hands-On Activity: miniAuto Navigation Challenge (25 minutes)

Project: Autonomous Room Explorer

Program your miniAuto to autonomously explore a room while avoiding obstacles and mapping its environment.

Requirements:

Implementation Steps

  1. Set up the miniAuto hardware and test basic movements
  2. Implement the obstacle avoidance algorithm
  3. Add exploration behavior (wall following or random walk)
  4. Include data logging for movement analysis
  5. Test and refine the navigation algorithm
  6. Document performance and areas for improvement

🏆 Challenge Extensions

📝 Assessment & Homework

📊 Quick Assessment

  • Demonstrate basic miniAuto movements
  • Explain sensor integration concepts
  • Show autonomous navigation program
  • Analyze robot behavior and performance

🏠 Homework Assignment

  • Research advanced navigation algorithms
  • Design improvements to obstacle avoidance
  • Plan a complex autonomous mission
  • Study real-world autonomous vehicle systems
← Previous: Assembly 📚 Semester Overview 📝 Take Lesson 14 Quiz Next: Lesson 15 →