Study · 12 layers ·
Robotics, learned by building one: from motors to machine learning, with the Duckiebot
A robot is a machine that notices the world, decides what to do, and then moves. That sounds simple, but every part of it is its own craft: motors and wheels, batteries and circuit boards, sensors, software, maths for knowing where you are, and now machine learning. The easiest way to understand all of it is to follow one small robot from the ground up. We use the Duckiebot, a little self-driving car from Duckietown, an open education project that started as a class at MIT in 2016. Duckiebots drive around a toy town of roads, signs and rubber ducks, and almost every idea used in real self-driving cars and warehouse robots shows up on them in miniature.
What a robot is
Sense, think, act, over and over, many times a second.
Every robot does three things in a loop. It senses: cameras, switches and other sensors tell it something about the world. It thinks: a computer turns those readings into a decision. It acts: motors turn wheels, joints or grippers. Then it senses again to see what changed. Roboticists call this the sense, plan, act loop.
The loop has to keep up with the world. A robot car that looks at the road only once a second would drift off it between looks. So a big part of robotics is making each step fast enough and reliable enough, and dealing with the fact that sensors are noisy and motors never do exactly what you asked.
Duckietown shows the whole loop in a form you can hold. The Duckiebot is a small two-wheeled car with a camera. Its job is to drive in its lane, stop at red lines, read signs at intersections and not hit the rubber ducks. The project started in a 2016 class at MIT, where students built a fleet of these robots and a town for them to drive in, and it now runs as an open, worldwide education programme with free course materials and code.
- Sense, think, act: every robot, from a robot vacuum to a factory arm, runs this loop.
- Sensors are never perfect and motors never obey exactly; robotics is the art of working well anyway.
- A robot is a system: a weak link anywhere (power, wiring, software) stops the whole thing.
- Duckietown is open source and was built for teaching, which makes it a good map of the whole field.
/ Tools and names to know
/ Quick read
The body
Chassis, motors and wheels, and how two wheels make a robot turn.
The chassis is the robot's skeleton: the frame that holds everything together. On a Duckiebot it is a small set of plates that carry the computer, battery, camera and motors. A good chassis keeps the weight low and balanced so the robot does not tip, and keeps parts where the software expects them to be.
Motors turn electricity into turning. The Duckiebot uses two small DC motors, one for each driving wheel, plus a free-rolling omni-wheel at the back that just keeps it balanced. Other robots use servo motors, which can hold a set angle and are common in robot arms, or stepper motors, which move in tiny fixed steps.
Steering with two wheels is called differential drive. If both wheels turn at the same speed, the robot goes straight. If the right wheel turns faster than the left, the robot curves to the left. If the wheels turn the same speed in opposite directions, it spins on the spot. The robot's forward speed is the average of the two wheel speeds, and how fast it turns depends on the difference between them divided by the distance between the wheels.
Working out how wheel or joint movements become movement of the whole robot is called kinematics. It is the first piece of maths every robot needs, because the software thinks in terms of "go forward and turn a bit", while the motors only understand "left wheel this fast, right wheel that fast".
- Differential drive: two driven wheels, steering by changing their speeds; no steering wheel needed.
- Forward speed = average of the two wheel speeds; turning = their difference.
- DC motors spin fast and freely; servos hold an angle; steppers move in fixed steps.
- Kinematics translates between what the robot should do and what each motor must do.
/ Quick read
- WikiDifferential wheeled robotHow two independently driven wheels steer a robot.en.wikipedia.org
- WikiDC motorHow the simplest electric motor works.en.wikipedia.org
- WikiServomotorMotors that hold a commanded position, used in arms and grippers.en.wikipedia.org
- WikiRobot kinematicsThe maths linking joint or wheel motion to robot motion.en.wikipedia.org
Electronics and power
Batteries, motor drivers and the small computer that runs it all.
A computer chip cannot push enough current to spin a motor. A motor driver sits in between: the computer sends it small signals, and the driver switches the battery's power to the motor. Most drivers use a circuit called an H-bridge, which can send current either way through the motor so it can go forwards or backwards. Speed is set by switching the power on and off very fast and changing how long it stays on each time; this trick is called pulse-width modulation, or PWM.
The battery feeds everything: motors, computer, sensors and lights. Robots usually use lithium batteries because they hold a lot of energy for their weight, but they must be charged and protected properly, which is why good packs have a small protection circuit built in. The Duckiebot uses its own battery pack, the Duckiebattery. A common beginner problem is motors pulling so much current that the computer's voltage dips and it restarts, so power is worth planning, not just plugging in.
The brain of the current Duckiebot (the DB21J) is an NVIDIA Jetson Nano, a credit-card-sized computer with a graphics chip that is good at running neural networks. Earlier Duckiebots, up to the DB19, used a Raspberry Pi. On top of the Jetson sits Duckietown's own interface board, the HUT, which connects the motors, LEDs, sensors and other parts to the computer.
- Motor driver: lets a small signal control a big current. H-bridge: lets the motor reverse.
- PWM: speed control by switching power on and off very quickly.
- Plan the power budget: motors, computer and sensors all draw from the same battery.
- Duckiebot DB21J: Jetson Nano 4GB. Older DB17 to DB19: Raspberry Pi 3.
/ Tools and names to know
/ Quick read
- WikiH-bridgeThe circuit that lets a motor run both ways.en.wikipedia.org
- WikiPulse-width modulationHow fast switching controls motor speed and LED brightness.en.wikipedia.org
- WikiLithium-ion batteryHow the batteries in most robots work, and their risks.en.wikipedia.org
- WikiNvidia JetsonThe family of small AI computers used in the Duckiebot.en.wikipedia.org
Sensors
Camera, wheel encoders, IMU, distance sensors and LiDAR.
The camera is the Duckiebot's main sense. It sits at the front and looks down at the road. A camera gives a lot of information, colours, lines, signs and other robots, but the robot needs software to turn pixels into meaning.
Wheel encoders count how far each wheel has turned. From that, the robot can estimate how far it has driven and how much it has turned. An IMU (inertial measurement unit) measures how the robot speeds up and rotates, like the sensor in a phone that knows when you tilt it. A time-of-flight sensor sends out a pulse of light and times how long it takes to bounce back, which tells the robot how far away the thing in front is. The DB21-series Duckiebots carry all four: camera, encoders, IMU and a time-of-flight sensor.
Bigger robots often add LiDAR. A LiDAR spins a laser and measures distances all around, building a map of points, called a point cloud, of walls, people and objects. It works in the dark and measures distance directly, which cameras cannot, but it costs more and sees no colour. Many robots combine several sensors, because each one fails in different ways.
- Camera: rich but needs heavy software to understand.
- Encoders: count wheel turns; good over short distances, drift over long ones.
- IMU: measures turning and acceleration; drifts if used alone.
- Time-of-flight: one distance straight ahead, from timing light.
- LiDAR: distances in every direction; common on mobile robots and self-driving cars.
/ Quick read
Software foundations
Linux, Python, Docker and ROS: the everyday tools of robot software.
Most robot computers run Linux, usually Ubuntu. You will spend a lot of time in a terminal: logging into the robot over the network, starting programs, reading logs. Python is the friendliest language for robotics and is used everywhere in Duckietown; C++ is used where speed matters most.
Duckietown packs all its software into Docker containers. A container is a sealed box that holds a program together with everything it needs to run. This means the same code runs the same way on a student's laptop and on every Duckiebot, and updating a robot is as simple as pulling a new container. Duckietown's own command-line tool, the Duckietown Shell (dts), wraps these steps.
ROS, the Robot Operating System, is not really an operating system. It is a set of libraries and tools that let a robot's software be split into small programs, called nodes, that talk to each other by sending messages on named channels, called topics. One node reads the camera, another finds the lane, another drives the motors. Duckietown's software is built as ROS nodes running inside Docker containers.
There are two generations: the original ROS (ROS 1) and ROS 2, which was rebuilt for reliability, security and real products. The last ROS 1 release, Noetic, reached end of life on 31 May 2025, so new projects should start on ROS 2.
- Linux and the terminal are daily tools; learn them early.
- Python for most robot code; C++ where speed is critical.
- Docker: the same software, packaged once, runs on every robot.
- ROS nodes publish and subscribe to topics; small parts, loosely joined.
- Start new projects on ROS 2; ROS 1 is end of life.
/ Tools and names to know
/ Quick read
/ Deep read
- OfficialROS 2 documentation: conceptsNodes, topics, services and the rest of ROS 2, explained by its makers.docs.ros.org
- OfficialROS 2 tutorialsHands-on official tutorials from first node to full system.docs.ros.org
- OfficialDuckietown: Docker basicsHow and why Duckietown runs everything in containers.docs.duckietown.com
- OfficialDuckietown: using ROSWriting your own ROS code for a Duckiebot.docs.duckietown.com
Perception
Turning camera pixels into lanes, signs and obstacles.
Perception means making sense of sensor data. For a Duckiebot it mostly means looking at camera images and finding the road. Duckietown roads have white lines at the edges and a dashed yellow line in the middle, so the robot looks for those colours, finds their edges and fits straight line pieces to them. From where those lines sit in the image, it works out where it is inside its lane.
First the camera must be calibrated. Every lens bends the picture a little, especially near the edges. Calibration means showing the camera a known pattern, like a checkerboard, from different angles so software can measure that bending and undo it. A second step works out where the camera sits relative to the ground, so a pixel in the image can be turned into a point on the road.
Most of this is classic computer vision, and OpenCV is the free library almost everyone uses for it: colour filtering, edge detection, line finding and calibration are all built in. Today many robots also use neural networks to recognise objects, like ducks, other robots or signs. Duckietown also uses AprilTags, printed square codes on its signs, which a camera can recognise and measure very reliably.
- Calibrate first: undo lens bending, then learn where the camera sits.
- Classic lane detection: filter by colour, find edges, fit lines.
- Neural networks are now common for detecting objects.
- Lighting changes break vision; test in the light you will really have.
/ Tools and names to know
/ Quick read
- WikiComputer visionWhat computers can and cannot get from images.en.wikipedia.org
- WikiCamera resectioning (calibration)The idea behind camera calibration.en.wikipedia.org
- WikiHough transformA classic way of finding straight lines, like lane markings, in an image.en.wikipedia.org
- WikiOpenCVBackground on the most used vision library.en.wikipedia.org
State estimation and localisation
Knowing where you are when every sensor is a little bit wrong.
The robot's state is what it needs to know about itself right now: where it is, which way it is facing, how fast it is moving. No sensor tells it this directly and perfectly, so the robot has to estimate it.
Odometry means adding up small movements from the wheel encoders to track position. It works well for a short while, but small errors pile up, so the estimate drifts further and further from the truth. This is called dead reckoning, the same way sailors once tracked a ship with no landmarks.
The fix is to combine sources. A filter, such as the Kalman filter or a particle filter, keeps a best guess plus how unsure it is, moves the guess forward using the wheel data, and then corrects it whenever a sensor sees something it recognises, like a lane line or a sign. The Duckiebot's lane follower does exactly this on a small scale: it estimates how far it sits from the centre of its lane and at what angle it is pointing.
When a robot has no map, it can build one and locate itself in it at the same time. This is called SLAM (simultaneous localisation and mapping) and it is how robot vacuums and warehouse robots learn a new space.
- State: position, heading and speed, always an estimate with some doubt.
- Odometry drifts; landmarks correct it.
- Filters blend a prediction with each new measurement, weighted by trust.
- SLAM: building the map and finding yourself in it, together.
/ Quick read
- WikiOdometryTracking position from wheel movement, and why it drifts.en.wikipedia.org
- WikiKalman filterThe classic way to blend predictions and noisy measurements.en.wikipedia.org
- WikiParticle filterTracking many guesses at once, used for robot localisation.en.wikipedia.org
- WikiSimultaneous localization and mappingHow robots map a place and locate themselves in it.en.wikipedia.org
Planning and control
Deciding where to go, then making the wheels actually get there.
Planning decides what to do: which way to turn at the next intersection, or which path gets from here to there without hitting anything. On a map, search methods such as A* find the shortest route through a grid or a road network. In Duckietown, planning is mostly about choosing a turn at each intersection and following the traffic rules.
Control makes the plan happen, moment by moment. The most common controller is PID. Imagine the robot is a little to the left of the lane centre. The P (proportional) part steers back harder the further off it is. The I (integral) part notices if it has been off to one side for a long time and adds a little extra push. The D (derivative) part sees how fast the error is shrinking and eases off so the robot does not overshoot and wobble. Tuning these three numbers is a rite of passage in robotics.
Path following joins the two. A simple method called pure pursuit picks a point a little way ahead on the path and steers towards it, like looking ahead when riding a bike. The Duckiebot's lane following is a control loop: the lane estimate goes in, wheel speeds come out, many times a second.
- Planning: where to go. Control: how to get there right now.
- PID: steer by how wrong you are, how long you have been wrong, and how fast it is changing.
- Too much P: wobble. Too little: slow to correct.
- Look-ahead methods like pure pursuit give smooth path following.
/ Tools and names to know
/ Quick read
/ Deep read
- BookPlanning Algorithms (LaValle, Cambridge University Press)A full textbook on planning, free to read online.lavalle.pl
- BookFeedback Systems (Åström and Murray)A thorough, free introduction to feedback and control.fbswiki.org
- OfficialNav2 documentationHow real ROS 2 robots plan and follow paths.docs.nav2.org
Learning-based robotics and simulation
Reinforcement learning, imitation learning, simulators and where AI fits now.
Instead of writing every rule by hand, a robot can learn. In reinforcement learning, the robot tries actions, gets a reward when things go well (staying in the lane) and a penalty when they do not (driving off the road), and slowly finds a behaviour that earns the most reward. In imitation learning, a person drives or moves the robot many times, and a neural network learns to copy what the person did from what the cameras saw.
Learning needs lots of practice, and real robots break, run out of battery and are slow. So most learning starts in a simulator, a virtual world with physics. Gazebo is the usual simulator for ROS robots, and MuJoCo is popular for arms and research. Duckietown had its own Gym simulator for years and is now moving to the Duckiematrix, a newer simulator still in beta. The catch is the "sim-to-real gap": a policy that works in the virtual world may fail on the real robot. Randomising colours, lighting and physics in the simulator helps it cope with the real world.
Where AI fits now: neural networks already do much of the seeing (detecting objects, estimating depth). The newer step is learning the actions too. Open projects like Hugging Face's LeRobot let anyone record demonstrations with a cheap arm, train a policy such as ACT, and run it on the robot. Larger vision-language-action models take a camera image and a written instruction and output motor commands. These work well on tasks like the ones they were trained on, and still need careful testing on anything new.
- Reinforcement learning: learn by trial, error and reward.
- Imitation learning: learn by copying human demonstrations.
- Train in simulation first; expect a sim-to-real gap.
- Classic control is still common for the low-level loop; learning often sits on top.
/ Tools and names to know
/ Quick read
/ Deep read
- BookReinforcement Learning: An Introduction (Sutton and Barto)The standard RL textbook, free online from the authors.incompleteideas.net
- PaperDomain Randomization for Transferring Deep Neural Networks from Simulation to the Real WorldThe paper behind randomising simulators to cross the sim-to-real gap.arxiv.org
- PaperLearning Fine-Grained Bimanual Manipulation with Low-Cost Hardware (ACT)The imitation-learning method many LeRobot users start with.arxiv.org
- OfficialDuckietown simulatorsDuckiematrix and the legacy Gym simulator, from the official docs.docs.duckietown.com
Safety and testing
Robots move in the real world, so mistakes have weight.
Software bugs on a website show an error page. Software bugs on a robot can crash it into a wall, a person or itself. So robots are built with layers of safety: an emergency stop that cuts motor power no matter what the software is doing, speed limits, bumpers or distance sensors that stop the robot when something is too close, and timeouts that stop the motors if commands stop arriving.
Testing goes in steps. Unit tests check small pieces of code on a laptop. Simulation checks the whole system in a virtual world. Hardware-in-the-loop testing runs the real computer and software against simulated sensors. Only then does the real robot run, first slowly, in a closed area, with someone holding the stop button. Recording sensor data from real runs lets you replay problems later.
Industrial robots have their own safety standards. ISO 10218, for example, covers industrial robot safety, and big factory arms usually work behind guards or in fenced cells. Small teaching robots like the Duckiebot are low-power and slow, which is part of what makes them good for learning, but the same habits matter.
- Always have a way to stop the motors that does not depend on the main software.
- Fail safe: if commands stop, the robot stops.
- Test in order: code, simulation, hardware-in-the-loop, slow real runs.
- Record real runs so you can replay and fix failures.
/ Quick read
- WikiEmergency stopWhy every machine needs a reliable off switch.en.wikipedia.org
- WikiISO 10218The main safety standard for industrial robots, summarised.en.wikipedia.org
- WikiHardware-in-the-loop simulationTesting real electronics against a simulated world.en.wikipedia.org
- WikiFunctional safetyHow engineers make safety systems that work even when parts fail.en.wikipedia.org
Other open-source robots worth knowing
TurtleBot, ROS 2 robots and low-cost open-source arms.
TurtleBot is the classic ROS teaching robot. TurtleBot3, made by ROBOTIS together with Open Robotics, is small and round, uses a Raspberry Pi as its main computer and carries a spinning LiDAR on top. It is the robot used in many ROS and ROS 2 navigation tutorials, which makes it a natural next step after a Duckiebot: the same ideas, but with LiDAR mapping and the standard ROS 2 navigation stack. TurtleBot4 is a newer, larger version built on ROS 2.
Arms are the other big family. The SO-101 (successor to the SO-100) is an open-source arm designed by RobotStudio with Hugging Face. Most of it is 3D printed and it moves with small servo motors. You build two: a leader arm that you move by hand, and a follower arm that copies it. Recording those demonstrations is exactly how LeRobot trains imitation-learning policies.
Wheels or arms, the skills are the same: power, sensors, ROS, perception, control and learning. Picking robots that share the open ROS ecosystem means what you learn on one carries over to the next.
- Duckiebot: camera-first self-driving, built for classes.
- TurtleBot3 / TurtleBot4: LiDAR, mapping and ROS 2 navigation.
- SO-101 with LeRobot: low-cost arm for imitation learning.
- Open designs let you see, change and fix every part.
/ Tools and names to know
/ Quick read
/ Deep read
- OfficialTurtleBot3 e-Manual (ROBOTIS)The official TurtleBot3 manual, from setup to navigation and SLAM.emanual.robotis.com
- OfficialTurtleBot4 user manualThe official guide to the ROS 2 TurtleBot.turtlebot.github.io
- OfficialSO-101 in the LeRobot docsHow to build, calibrate and teleoperate the SO-101 arm.huggingface.co
- ToolSO-ARM100 repository (RobotStudio)The open hardware files, parts list and build notes.github.com
From learning robot to real product
What changes when a robot has to be sold, certified and built by the thousand.
A teaching robot is meant to be opened, changed and broken. A product must work for people who never look inside. That means it must survive drops, heat, dust and years of use, be safe even when someone misuses it, and be fixable or updatable without an engineer on site.
Most of the work moves to the parts you did not think about while learning. Electronics move from development boards to custom circuit boards. The chassis is redesigned so it can be moulded or machined cheaply and assembled quickly, which is called design for manufacturing. Software needs remote updates, logging and a way to recover from failure. Our hardware topic covers these manufacturing steps in more depth.
Then comes certification. Anything with radios (Wi-Fi, Bluetooth) needs radio approval in each market, and anything electrical needs safety testing. In the European Union, products show conformity with CE marking, and machinery has its own rules, including a new EU Machinery Regulation replacing the older Machinery Directive. Robot arms that work near people bring in robot-specific safety standards. Plan for this early: it shapes the design, not just the paperwork.
- Prototype on open platforms; productise with custom boards and parts.
- Design for manufacturing and repair from the start.
- Budget time and money for radio, electrical and machinery certification.
- Field updates, logging and safe failure are product features, not extras.
/ Quick read
- WikiDesign for manufacturabilityDesigning parts so they are cheap and reliable to make.en.wikipedia.org
- WikiCE markingWhat the CE mark means for products sold in Europe.en.wikipedia.org
- WikiMachinery DirectiveThe EU rules for machines and their replacement by the Machinery Regulation.en.wikipedia.org
- WikiISO 10218Industrial robot safety requirements in brief.en.wikipedia.org
Paths through it
What each kind of reader needs, step by step.