Robotics
Learn C++ by modelling a robot and its decisions. Develop coordinate transforms, sensor processing, feedback control, and path planning towards an autonomous navigation project.
What helps
Basic algebra and geometry help with coordinates and movement. The early projects introduce C++ before the later control and navigation problems.
C++ pathway
Programming Foundations / Practice rooms / Track curriculum and enrollment
C++ Foundations: The Robot's Brain
Learn C++ numeric types, functions, branching, loops and strings through the quantities a wheeled robot uses: radians, wheel travel, encoder ticks and velocities. Combine them into a discrete motion simulation, then distinguish path length from distance to the starting point. The exercises run CPU models rather than controlling physical motors.
- Numbers and Types: 5 lessons
- Functions: 5 lessons
- Control Flow: 5 lessons
- Output and Telemetry: 5 lessons
- Capstone: The Robot Tick: 5 lessons
Structs and Classes: Modeling the Robot
Loose variables do not scale. A robot has many related pieces of state (position, heading, wheel speeds) that belong together and behave as a unit. This project introduces C++'s tools for modeling things: structs to group data, then classes to bundle data with the methods that act on it, with encapsulation, constructors, and member functions. You will turn the loose pose variables of project 1 into a proper Robot class with differential-drive kinematics, and command it to drive a square.
- Structs: Grouping Data: 5 lessons
- Classes and Encapsulation: 5 lessons
- Constructors and Methods: 5 lessons
- Differential Drive as Methods: 5 lessons
- Capstone: Drive a Square: 5 lessons
Kinematics and Coordinate Frames
Describe points in a moving robot frame and a fixed world frame. Build vector operations, rotations and inverse transforms, then integrate wheel motion into an estimated pose. The odometry tracker keeps state across updates; its ideal wheel model does not measure or correct real wheel slip.
- 2D Vectors: 5 lessons
- Rotation: 5 lessons
- Coordinate Frames: 5 lessons
- Odometry Building Blocks: 5 lessons
- Capstone: An Odometry Tracker: 5 lessons
Sensors and the STL
A robot that only tracks its own motion is blind. Sensors let it perceive the world, and a stream of sensor readings is naturally a list. This project introduces the C++ Standard Template Library (the STL): std::vector for collections of readings, the standard algorithms that process them, and inheritance with virtual functions so different sensor types share one interface. You will model range sensors, filter their noise, and build a multi-sensor robot that reports the clearest direction to drive.
- Collections with std::vector: 5 lessons
- Modeling Range Sensors: 5 lessons
- Inheritance and Polymorphism: 5 lessons
- Filtering Noisy Readings: 5 lessons
- Capstone: A Perceptive Robot: 5 lessons
Feedback Control: PID
Build proportional, integral and derivative terms from an error signal and package them in a reusable controller with output limits and anti-windup. Compare the state-update conventions explicitly. Finish by using persistent distance and heading controllers to move a simulated robot toward a target point and inspect its motion trace.
- Error and Proportional Control: 5 lessons
- The Integral Term: 5 lessons
- The Derivative Term: 5 lessons
- The PID Controller Class: 5 lessons
- Capstone: Closed-Loop Robot Control: 5 lessons
Line Following
Line following is the classic first autonomous robot behavior: a robot reads a line sensor array, figures out where the line is relative to its center, and steers to stay on it. This project builds it end to end, the sensor array, the weighted line-position estimate, bang-bang control, then smooth PID line following, junction handling, and a full simulated track run. It is where sensing (project 4) and control (project 5) finally drive the robot autonomously.
- The Line Sensor Array: 5 lessons
- Estimating the Line Position: 5 lessons
- Bang-Bang Control: 5 lessons
- Smooth PID Line Following: 5 lessons
- Capstone: Follow a Track: 5 lessons
Reactive Behaviors and State Machines
Turn local obstacle observations into actions using conditions, enums and a state machine. Add mode timing, an escape turn and wall-following rules. Assemble a bounded reactive simulation with point probes and a separate geometric movement guard; inspect mode counts and stopped runs. Local reactions alone do not guarantee progress through every obstacle field.
- Reactive Rules: 5 lessons
- Enums and Modes: 5 lessons
- The Behavior State Machine: 5 lessons
- Wall Following: 5 lessons
- Capstone: A Reactive Navigator: 5 lessons
Mapping: Occupancy Grids
To navigate purposefully, a robot must remember its environment. The occupancy grid is the workhorse representation: a 2D grid of cells, each holding the probability that it is occupied. This project builds it in C++: a grid of cells (vector of vectors), world-to-grid coordinate conversion, ray casting to mark free and occupied cells from a sensor reading, log-odds probability updates, and a complete mapping pass that builds a map from a robot's scans.
- The Occupancy Grid: 5 lessons
- World and Grid Coordinates: 5 lessons
- Ray Casting: 5 lessons
- The Log-Odds Representation: 5 lessons
- Capstone: Build a Map: 5 lessons
Path Planning
With a map, the robot can plan: find a path from start to goal through the free cells. This project builds graph search on the occupancy grid, the foundation of deliberative navigation. Treat the grid as a graph, build the queues and priority queues the STL provides, then implement breadth-first search, Dijkstra's algorithm, and A* with a heuristic, culminating in a maze solver that finds the shortest path through a grid.
- The Grid as a Graph: 5 lessons
- Breadth-First Search: 5 lessons
- Dijkstra's Algorithm: 5 lessons
- A* Search: 5 lessons
- Capstone: Solve a Maze: 5 lessons
Capstone: Autonomous Navigation
Assemble a CPU navigation model from pose state, local obstacle observations, a binary map, A* routes, waypoint following, persistent PID steering and wheel odometry. Record observations, replans, commands and poses so each step can be inspected. The simulation distinguishes arrival, no route, blocked movement and timeout; ideal sensing and geometric collision checks are model assumptions, not physical robot validation.
- The Navigator's State: 5 lessons
- Planning the Route: 5 lessons
- Following the Path: 5 lessons
- Reactive Safety: 5 lessons
- Capstone: The Autonomous Navigator: 5 lessons