Skip to main content

Lesson 11 · Python Final Project

Module 1 · Learning to Drive

Lesson 11 · Python Final Project

Multi-dayPhase C · Transition to PythonCapstone
👩‍🏫

Teacher mode is on. Toggle it off (bottom-right) to preview the student view.

This is it — the capstone of Module 1. You'll design and build your own complete Python program for the XRP, pulling together everything you've learned: loops, functions, parameters, motor control, and geometric thinking. It's both a real project and your proof of mastery.

Learning Objectives

By the end of this project you will be able to:

  • Design a complete program from a problem statement to a working robot
  • Combine loops, functions, and parameters in one purposeful program
  • Test and debug systematically, and document your code so others can read it
  • Present your work and reflect on what you learned

Activity · Pick your project

Choose one path (or pitch your own to your teacher):

Option A

Polygon artist

Use a polygon function to compose a geometric art piece — nested shapes, a star, a repeating pattern. A great fit if you liked Lesson 5.

Option B

Precision navigation

Build a delivery robot: functions for each course segment, hit waypoints accurately, and return home.

Option C

Sensor behavior

(Stretch) Use the rangefinder or reflectance sensors so the robot reacts to its world — avoid an obstacle, follow a line.

Option D

Your own idea

Anything that shows off Module 1 skills — a race timer, a robot dance, a maze runner. Clear it with your teacher first.

Activity · Plan before you code

Professionals design before they build. On paper first:

  1. Problem statement — one or two sentences: what will your robot do?
  2. Function inventory — list the functions you'll need, with their parameters (e.g. polygon(sides, side_length), navigate_segment(distance, angle)).
  3. Pseudocode — the flow in plain English, not Python:
Main:
set up the robot
for each shape in my design:
draw the shape
move to the next spot
announce "done"
Knowledge Check

You're about to build a 60-block-worth Python program. What's the smartest way to start?

A clean program structure

Good Python programs have a shape: a docstring at the top, helper functions, a main(), and one line that runs it. Use this as your skeleton:

"""
Module 1 Final Project: <your project name>
Team: <names>
Description: <two-sentence overview>
"""

from XRPLib.differential_drive import DifferentialDrive
import time

drivetrain = DifferentialDrive.get_default_differential_drive()

# ===== HELPER FUNCTIONS =====
def calculate_angle(sides):
"""Return the exterior angle of a regular polygon."""
return 360 / sides

# ===== MAIN FUNCTIONS =====
def polygon(sides, side_length):
"""Draw one regular polygon."""
angle = calculate_angle(sides)
for i in range(sides):
drivetrain.straight(side_length)
drivetrain.turn(angle)

def main():
"""Run the project."""
print("Starting...")
polygon(4, 30)
time.sleep(1)
polygon(6, 25)
print("Done!")

# ===== RUN =====
if __name__ == "__main__":
main()

That last block (if __name__ == "__main__":) is the professional way to say "run main() when this file is the program." You'll see it in real Python everywhere.

Activity · Build, test, and polish

Work the same loop engineers use:

  1. Build one function; test it on its own with a few inputs.
  2. Integrate — call it from main() alongside the others; test the flow.
  3. Instrument — sprinkle print() messages so you can see what's happening.
  4. Polish — add a one-line docstring to each function, remove leftover debug prints, and make your names clear.
Knowledge Check

Your program runs but the robot behaves differently each time on the same code. Most likely cause?

Activity · Show it and reflect

Wrap up by demoing your robot and writing a short reflection:

  • What did you build, and what does it do?
  • Which Module 1 concepts did you use, and why?
  • What was the hardest bug, and how did you crack it?
  • If you had more time, what would you add?

You made it 🎉

Look how far you've come: you started Module 1 dragging a single Drive block, and you're finishing it designing complete Python programs. The loops, functions, and parameters you now know are exactly the tools real robotics engineers use every day — and they carry straight into the next module.

Resources