Robotics with C++

Build an autonomous mobile robot in C++, the language of real robotics: kinematics, sensors, PID control, line following, mapping, path planning, and full autonomous navigation.

10 projects, 250 hands-on levels, run in your browser.

Syllabus

  • C++ Foundations: The Robot's Brain: C++ is the language of real robotics: it runs the control loops, perception, and planning on everything from hobby rovers to Mars landers, and it is the core of ROS, the Robot Operating System. Start at the foundations: numeric types, functions, control flow, and output, learned by computing the quantities a mobile robot actually needs (radians, wheel travel, encoder ticks, velocities). Your code is compiled with g++ on the server, the same kind of toolchain that builds real robot firmware. By the end you will simulate a robot driving a maneuver and report how far it traveled.
  • 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.
  • Kinematics and Coordinate Frames: A robot lives in two worlds at once: its own body frame (where 'forward' means straight ahead) and the fixed world frame (where positions are absolute). Converting between them is the math of robotics. This project builds 2D vectors, rotation matrices, and coordinate transforms, then uses them to implement odometry: estimating the robot's world position by integrating its wheel motion, the dead-reckoning every mobile robot relies on. The capstone is a working odometry tracker.
  • 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.
  • Feedback Control: PID: Sensing tells a robot where it is; control makes it go where it should. Feedback control measures the error between desired and actual, and commands an action to shrink it. This project builds the PID controller from scratch: proportional, integral, and derivative terms, each fixing a weakness of the last, wrapped into a reusable PID class with output limiting and anti-windup. The capstone uses it to drive a robot to a target distance and hold a heading.
  • 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.
  • Reactive Behaviors and State Machines: Not every robot follows a line; many must react to whatever they encounter. Reactive behaviors map sensor readings directly to actions, with no map and no plan, yet produce surprisingly capable navigation. This project builds them with C++ enums and state machines: obstacle detection, reactive avoidance, an enum-based finite state machine, wall following (the bug-style algorithm), and a complete reactive navigator that wanders a cluttered space without getting stuck.
  • 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.
  • 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.
  • Capstone: Autonomous Navigation: The grand capstone of the track: assemble everything into a complete autonomous navigator. The robot maintains its pose with odometry, perceives obstacles with sensors, plans a path with A*, follows the path with PID control, and reactively avoids unexpected obstacles, replanning when blocked. This project integrates all nine prior projects into a robot that drives itself from a start to a goal through a real environment, the full sense-plan-act stack in C++.

Key concepts

  • A* search: An optimal, goal-directed path planner that expands cells by cost-so-far plus an admissible heuristic (f = g + h), finding shortest paths fast.
  • Coordinate frame: A reference for measuring position: the world frame (fixed) vs the body frame (relative to the robot). Transforms convert between them.
  • Differential drive: A two-wheel robot that steers by driving its wheels at different speeds; forward speed is their average, turn rate their difference over the wheel base.
  • Finite state machine: Organizing behavior into named modes (cruise, avoid, stop) with transitions, so a robot does the right thing for each situation.
  • Line following: Steering to keep a sensed line centered, typically with proportional or PID control on the line-position error, the classic first autonomous behavior.
  • Occupancy grid: A 2D grid of cells, each holding the probability it is occupied; built from sensor rays and used for planning. Often stored in log-odds.
  • Odometry: Estimating the robot's pose by integrating its wheel motion over time (dead reckoning). Cheap and smooth but drifts without correction.
  • PID controller: A feedback controller commanding an action from the error: proportional (now), integral (accumulated, removes offset), derivative (trend, damps overshoot).
  • Pose: A robot's position and orientation: (x, y, heading) in 2D. The fundamental state a mobile robot tracks.
  • Reactive navigation: Mapping current sensor readings directly to motion (no map), e.g., turn toward the most open direction when blocked.