Category: Self Study Courses

  • Python 3 for Robotics – Foundations

    Course Description

    Welcome, future roboticist! This 16-week course is your gateway into the fascinating world of robotics using Python 3—one of the most versatile and beginner-friendly programming languages available. Starting from the fundamentals, you’ll gradually build confidence and skills until you’re commanding hardware, interpreting sensor data, and enabling your creations to make intelligent decisions. Designed for curious minds with zero prior experience, this course guides you from lighting up an LED to building a fully functional, obstacle-avoiding robot. Get ready to bring your ideas to life!

    Primary Learning Objectives

    By the end of this course, you’ll be able to:

    • Master Python fundamentals, including variables, control flow, functions, and data structures.
    • Apply Object-Oriented Programming (OOP) to develop clean, scalable robotics software.
    • Interface with hardware components such as LEDs, buttons, sensors, and motors via Raspberry Pi or similar platforms.
    • Interpret sensor data to help your robot perceive and respond to its environment.
    • Implement foundational robotics algorithms for movement, control, and basic navigation.
    • Grasp computer vision essentials and apply them in practical robotics scenarios.
    • Design and execute a complete robotics project from start to finish.

    Prerequisites & Materials

    Software (Free):

    • Python 3: The latest version of Python 3 will be used throughout the course.
    • Visual Studio Code (VS Code): A free, powerful code editor with strong Python support.
    • Git & GitHub Account: Essential for learning version control practices.
    • A Single-Board Computer: A Raspberry Pi 4 (or newer) is strongly recommended. Arduino can also be used, particularly in Week 11.
    • A Robotics Starter Kit: Various kits are available online. Look for one that includes:
      • A breadboard and jumper wires
      • LEDs and resistors
      • Push buttons
      • An ultrasonic distance sensor (such as the HC-SR04)
      • A servo motor and a DC motor with a motor driver (like the L298N)
      • A simple robot chassis with wheels
      • A portable power source for the Raspberry Pi/motors.

    Course Structure

    The course spans 14 weekly lessons followed by a 2-week final project. Each session builds on the previous one, guiding you from software basics to real-world hardware integration.


    Part 1: Python Fundamentals (Weeks 1–4)

    Lesson 1: Introduction to Python and Your Robotics Lab Setup

    • Learning Objectives:
      1. Understand why Python is ideal for robotics.
      2. Set up your complete development environment (Python and VS Code).
      3. Write and run your first Python script: “Hello, World!”
    • Key Vocabulary:
      • Python: A readable, interpreted language known for simplicity and rich libraries.
      • Interpreter: Executes instructions line-by-line in a programming language.
      • IDE (Integrated Development Environment): Tools like VS Code offer coding assistance and debugging.
      • Syntax: Rules governing valid code structure in a language.
    • Lesson Content:

      Why Python? Because it’s human-readable, fast to prototype with, and backed by a thriving community. It bridges abstract logic and tangible robotics seamlessly.

      Your First Steps:

      1. Install Python 3: Visit python.org, download the appropriate version, and ensure “Add Python to PATH” is checked during installation.
      2. Install VS Code: Download from code.visualstudio.com. Install the official Microsoft Python extension for enhanced functionality.

      Create a file named hello.py and enter:

      # This is my first Python program!
      # The print() function displays text on the screen.
      print("Hello, Robot World!")
      

      In VS Code, open the terminal (View → Terminal), type python hello.py, and hit Enter. If you see the greeting printed, congratulations—you’re now a Python programmer! 🎉

    • Practical Hands-on Example:

      Modify hello.py to simulate a robot introduction dialogue. Use multiple print() statements for personality:

      print("--- Booting sequence initiated ---")
      print("Hello! My name is PR-01.")
      print("My mission is to learn and explore.")
      print("--- System ready ---")
      

    Lesson 2: Variables, Data Types, and Basic Math

    • Learning Objectives:
      1. Understand and use variables to store information.
      2. Differentiate between core data types: integers, floats, strings, and booleans.
      3. Perform mathematical operations in Python to manipulate data.
    • Key Vocabulary:
      • Variable: A label pointing to a stored value.
      • Data Type: Defines what kind of data a variable holds and how it behaves.
      • Integer (int): Whole numbers like 10 or -5.
      • Float (float): Decimal numbers like 3.14 or -0.001.
      • String (str): Text enclosed in quotes, e.g., “robot”.
      • Boolean (bool): True or False values representing states.
    • Lesson Content:

      Robots need memory—to recall speed, distance, or identity. In Python, we use variables to store and retrieve data dynamically.

      Main Data Types:

      • Integers (int): Counters, like number of wheels. number_of_wheels = 4
      • Floats (float): Precise measurements, like voltage. battery_voltage = 11.8
      • Strings (str): Names or messages. robot_name = "Bumblebee"
      • Booleans (bool): States like grip activation. obstacle_detected = False

      Mathematical operations are vital for robotics:

      # Calculate robot speed
      distance_cm = 100
      time_seconds = 5.5
      speed_cm_per_second = distance_cm / time_seconds
      
      print("Calculating robot speed...")
      print(f"The robot's speed is: {speed_cm_per_second} cm/s")
      print(f"Data type: {type(speed_cm_per_second)}")
      
    • Practical Hands-on Example:

      Create a script battery_calc.py:

      1. Set max_voltage = 12.6 and current_voltage = 11.2.
      2. Calculate battery percentage using percentage = (current_voltage / max_voltage) * 100.
      3. Print formatted output: "Battery level: 88.88% remaining." (use round(..., 2) for formatting).

    Lesson 3: Control Flow – Conditionals and Loops

    • Learning Objectives:
      1. Make decisions using if, elif, and else statements.
      2. Repeat actions using for and while loops.
      3. Combine conditionals and loops for logical behavior.
    • Key Vocabulary:
      • Control Flow: Determines the execution order of statements.
      • Conditional Statement: Executes different paths based on conditions.
      • Loop: Repeats a block of code under certain conditions.
      • for loop: Iterates over sequences or ranges.
      • while loop: Runs while a condition remains true.
    • Lesson Content:

      Smart robots adapt—they decide when to move, stop, or react. That’s where control flow shines.

      Making Decisions:

      distance_to_wall_cm = 25
      
      if distance_to_wall_cm < 20:
          print("Obstacle detected! Stopping motors.")
      elif distance_to_wall_cm < 50:
          print("Caution, object nearby. Slowing down.")
      else:
          print("Path is clear. Full speed ahead!")
      

      Repeating Actions:

      for i in range(5):
          print(f"Picking up block number {i + 1}...")
      print("All blocks collected!")
      
      battery_charge = 100
      while battery_charge > 20:
          print(f"Robot is active. Battery at {battery_charge}%.")
          battery_charge = battery_charge - 10
      
      print("Battery low! Returning to charging station.")
      
    • Practical Hands-on Example:

      Write sensor_check.py:

      1. Assign core_temp = 85.
      2. Check temperature levels using if/elif/else.
      3. Add a countdown loop inside the warning case using for.

    Lesson 4: Functions and Modules – Building Reusable Code

    • Learning Objectives:
      1. Define and call custom functions to organize code.
      2. Understand parameters and return values.
      3. Import and utilize external modules like math and time.
    • Key Vocabulary:
      • Function: A reusable block of code performing a specific task.
      • Parameter: Inputs passed into a function.
      • Return Value: Output returned by a function.
      • Module: A file containing related definitions and code.
      • Import: Bringing code from one module into another.
    • Lesson Content:

      Functions eliminate repetition and improve clarity. For example:

      def convert_ultrasonic_reading_to_cm(reading):
          distance = reading * 0.343
          return distance
      
      sensor_value_1 = 50
      distance_1 = convert_ultrasonic_reading_to_cm(sensor_value_1)
      print(f"Sensor reading {sensor_value_1} corresponds to {distance_1} cm.")
      

      External modules extend capabilities:

      import math
      import time
      
      sqrt_number = math.sqrt(64)
      print(f"Square root of 64 is {sqrt_number}.")
      
      print("Moving forward...")
      time.sleep(2)
      print("...and stopped.")
      
    • Practical Hands-on Example:

      Create motor_control.py:

      1. Define calculate_motor_speed(desired_speed_percent, max_rpm).
      2. Return calculated RPM using target_rpm = max_rpm * (desired_speed_percent / 100).
      3. Call function with 75% and 150 RPM, then print result.