warming up your workspace

Robotics with C++

Learn C++ by building mobile-robot simulations: kinematics, sensor models, PID control, line following, occupancy mapping, path planning and an assembled navigation loop.

11 projects, 275 hands-on levels, run in your browser.

Syllabus

  • Foundations: code through robotics: Never written code before? Start here. You will learn the basics of C++, functions, variables, types, decisions, loops, and arrays, with simple robotics examples. By the end you are ready for Project 1.
  • 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.
  • 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: 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.
  • 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: 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.
  • 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: 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.
  • 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: 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.

Key concepts

  • A* search: A graph search ordered by f=g+h, the known route cost plus estimated cost to the goal. For nonnegative costs, admissibility and correct reopening support optim…
  • 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 motion model with body speed (left+right)/2 and counterclockwise turn rate (right-left)/wheel_base. The ideal model assumes rolling without lateral…
  • Finite state machine: A finite set of named modes, with explicit transition conditions and actions. Storing the current mode makes behavior depend on both observations and history.
  • 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 grid storing occupancy belief, often as log-odds. Zero log-odds means probability 0.5; a separate observed flag can distinguish an unseen cell from one whose…
  • 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 that sums proportional error, accumulated error and error rate. Gains, sampling, output limits and anti-windup affect stability; integral…
  • Pose: A robot's position and orientation: (x, y, heading) in 2D. The fundamental state a mobile robot tracks.
  • Reactive navigation: Choosing motion from local sensor observations, optionally with state and timers, without searching a global route. Local rules can respond quickly but can als…