ROB-360 · Lesson 2 of 12 · 29 min

Requirements, design and documentation for robot software

Most failed robot projects do not fail because the team could not write code. They fail because the team built the wrong thing, or built the right thing without being able to show that it works. Requirements engineering is the discipline of deciding, writing down and checking what the system must do. Design turns those requirements into a structure. Documentation keeps both understandable as people come and go. This lesson covers practical techniques suited to robot teams: use cases and operational scenarios, well-formed requirements with verification methods, interface control documents, architecture decision records and traceability.

From needs to requirements

Requirements start with stakeholders: the customer who pays, the operators who work beside the robot, maintenance technicians, safety officers, regulators and the team itself. Each has needs expressed in their own words: 'the robot must not get in the way of forklifts', 'I want to swap the battery in five minutes'. The engineer's job is to turn these into requirements that are specific enough to design against and test.

Robot teams often begin with an operational design domain (ODD), a description of the conditions under which the robot is meant to work: the environment (indoor warehouse, aisles at least 1.8 m wide, concrete floor, slopes under 2 %), the lighting, the people and vehicles present, temperatures, network coverage and so on. The ODD bounds the problem. A requirement such as 'the robot shall localize to within 5 cm' only means something inside a stated ODD, and behaviour outside it, such as stopping and calling for help, must be specified too.

Use cases and scenarios describe how the system is used. A use case names an actor and a goal ('operator sends robot to dock') and lists the main sequence of steps plus alternative and exception flows (dock occupied, path blocked, battery critical). For robots, scenario lists are especially valuable because they become test cases, both in simulation and on the real robot. Writing the exception flows is where most of the value lies; the happy path is usually obvious.

Writing good requirements

A good requirement is necessary, unambiguous, verifiable, feasible and singular (one requirement per statement). The conventional form uses 'shall' for mandatory requirements: 'The robot shall stop within 0.5 m of a detected person when travelling at up to 1.5 m/s.' It names a measurable quantity, a condition and a limit. Contrast 'The robot shall be safe around people', which no test could ever confirm. The EARS templates (easy approach to requirements syntax) help by giving patterns such as 'When <trigger>, the <system> shall <response>' and 'While <state>, the <system> shall <response>'.

Requirements fall into functional requirements (what the robot does: navigate to a station, pick a tote) and non-functional or quality requirements (how well: latency, availability, accuracy, maintainability, security). Robots also have many constraints imposed from outside: a maximum mass, a power budget, a required safety standard, a supported operating system. Each requirement should carry an identifier, a rationale explaining why it exists, its source, its priority and its verification method.

Verification methods, often abbreviated IADT, with simulation as a widely used addition
Verification methodWhat it meansRobot example
InspectionExamine a document, drawing or artefactCheck the emergency stop is red and mushroom-shaped
AnalysisCalculation or model shows complianceStopping distance computed from deceleration and latency
DemonstrationOperate the system and observeRobot docks successfully in front of the customer
TestControlled measurement against a criterion200 docking attempts with a measured success rate
SimulationModel-based test, often with many variations10 000 simulated routes with random obstacles

Worked problem

Turning a vague need into a testable requirement

An operator says: "The robot should not take forever to get to the packing station." Write a verifiable requirement, given that the longest route is 120 m and the robot cruises at 1.2 m/s.

Show solution
  1. Ideal travel time on the longest route: \( 120 / 1.2 = 100 \) s.
  2. Allow for acceleration, turns and slowing near people: say 30 % margin, giving about 130 s.
  3. State the condition, the metric and the statistic: under nominal traffic, measured over many runs.

Answer: "Within the ODD and under nominal traffic, the robot shall reach the packing station from any storage aisle within 130 s for at least 95 % of missions." It is measurable, has a condition and a statistic, and its rationale (operator throughput) can be recorded.

Requirements for reliability and statistics

Many robot requirements are statistical, because the world is variable. A requirement like 'the robot shall successfully dock 99 % of the time' raises a practical question: how many trials are needed to show it? If the robot docks successfully in all n trials, a common approximation (the rule of three) says the 95 % upper confidence bound on the failure rate is about 3/n. To show a failure rate below 1 % with no failures observed, you need about 300 successful trials. To show 99.9 %, you need about 3000. This is one reason simulation is so valuable: it makes thousands of trials affordable, provided the simulation is trustworthy (lessons 5 and 8).

How many trials a statistical requirement needs, and how often a weaker robot would still pass
import math
# Trials needed to claim failure rate below p with 95 % confidence and zero failures seen:
# (1 - p)^n <= 0.05  ->  n >= ln(0.05) / ln(1 - p)
for p in (0.05, 0.01, 0.001):
    n = math.ceil(math.log(0.05) / math.log(1 - p))
    print(f"failure rate < {p:.3f}: need {n} consecutive successes (rule of three gives {3/p:.0f})")
# With failures allowed, use the binomial distribution: probability of seeing <= k failures
def p_at_most(k, n, p):
    return sum(math.comb(n, i) * p**i * (1 - p)**(n - i) for i in range(k + 1))
print(f"chance a 1-percent robot shows 0 failures in 300 runs: {p_at_most(0, 300, 0.01):.3f}")
print(f"chance a 2-percent robot shows <= 1 failure in 300 runs: {p_at_most(1, 300, 0.02):.3f}")
Output
failure rate < 0.050: need 59 consecutive successes (rule of three gives 60)
failure rate < 0.010: need 299 consecutive successes (rule of three gives 300)
failure rate < 0.001: need 2995 consecutive successes (rule of three gives 3000)
chance a 1-percent robot shows 0 failures in 300 runs: 0.049
chance a 2-percent robot shows <= 1 failure in 300 runs: 0.017

The last two lines show the other side: even a robot that fails 2 % of the time has a small but real chance of passing a short test. Acceptance tests should therefore be designed with both risks in mind, the risk of rejecting a good system and the risk of accepting a bad one, and the requirement should say which statistic is used.

Interfaces and interface control documents

Interfaces are where robot projects break. A camera team publishes images in one frame convention and the perception team assumes another; a motor drive expects velocity in revolutions per minute and receives radians per second. An interface control document (ICD) defines each interface precisely: message type and fields, units, coordinate frames, rates, latency budget, quality-of-service settings, ownership, error handling and versioning. In ROS 2, much of this is captured in the .msg, .srv and .action definitions themselves, which is a strong reason to write them carefully, with units in field names or comments and with REP 103 (units and conventions) and REP 105 (frames) followed consistently.

A message definition that states its publisher, rate, QoS, frames and units
# DockStatus.msg  (listing) -- an interface definition doubles as documentation
# Published by: dock_manager at 2 Hz, QoS reliable, transient local depth 1
std_msgs/Header header        # stamp = time of last state change; frame_id = "map"
uint8 STATE_IDLE=0
uint8 STATE_APPROACHING=1
uint8 STATE_DOCKED=2
uint8 STATE_FAULT=3
uint8 state
float32 distance_to_dock_m     # along the approach path (m); NaN if unknown
float32 charge_current_a       # amperes into the battery; 0 when not docked
string fault_text              # empty unless state == STATE_FAULT

Interfaces also need versioning rules. Adding an optional field is usually compatible; changing the meaning or units of a field is not, and should create a new message type or a new topic. Teams that share message packages across many repositories pin versions and run compatibility checks in continuous integration (lesson 7).

Design decisions and architecture decision records

Every project makes hundreds of design decisions: which SLAM library, which middleware vendor, whether to use behaviour trees or state machines, whether to run perception on a GPU module. Months later, nobody remembers why. An architecture decision record (ADR) is a short document, often a page, that captures one significant decision: the context and forces at play, the options considered, the decision, and its consequences, good and bad. ADRs are numbered, dated and kept in the repository next to the code, and they are never edited after acceptance; a later ADR supersedes an earlier one if the decision changes.

Worked problem

A weighted decision matrix for an ADR

A team compares two localization approaches. Criteria and weights: accuracy 0.4, compute cost 0.2, robustness in changing layouts 0.3, team familiarity 0.1. Scores out of 5: option A (2-D lidar AMCL) 3, 5, 3, 5; option B (lidar SLAM with continuous map update) 4, 3, 5, 2. Which scores higher?

Show solution
  1. Option A: \( 0.4(3) + 0.2(5) + 0.3(3) + 0.1(5) = 1.2 + 1.0 + 0.9 + 0.5 = 3.6 \).
  2. Option B: \( 0.4(4) + 0.2(3) + 0.3(5) + 0.1(2) = 1.6 + 0.6 + 1.5 + 0.2 = 3.9 \).
  3. Sensitivity: if robustness drops to 0.2 weight and familiarity rises to 0.2, A becomes 3.8 and B 3.6, so the choice depends on that judgement.

Answer: B scores 3.9 against 3.6, but the result flips with a plausible change of weights. The ADR should record the weights, the sensitivity and the deciding argument, not just the winner.

Traceability and the V-model

Traceability links each requirement to the design elements that implement it and the tests that verify it, and back again. It answers questions like 'which tests must be rerun if we change the stopping requirement?' and 'which requirement does this test exist for?'. Safety standards such as ISO 13849, IEC 61508 and ISO 26262, met in ROB-320, require traceability for safety functions. The V-model pictures the relationship: the left side descends from needs through system requirements and architecture to detailed design and code; the right side ascends through unit, integration and system tests to acceptance, with each level of testing verifying the matching level of design.

A V-shaped diagram. The left arm descends through four boxes: stakeholder needs and operational design domain, system requirements, architecture and interfaces, and detailed design. The bottom of the V is labelled code. The right arm ascends through unit tests, integration tests, system tests and acceptance tests. Dashed horizontal arrows connect each left box to the box on the right at the same height, labelled verifies.
The V-model: each level of testing on the right verifies the matching level of design on the left

Agile teams sometimes see the V-model as heavyweight, but the two fit together: a sprint can still trace its stories to requirements and its acceptance criteria to tests. What matters is that the links exist and are kept current, ideally in tools that live alongside the code, such as requirement IDs in test names and a script that reports untested requirements.

Worked problem

A traceability gap report

A project has 140 requirements. 126 are linked to at least one passing test, 8 are linked only to analysis documents, and 6 have no verification link at all. What fraction are verified by test, and what should happen to the rest?

Show solution
  1. Verified by test: \( 126 / 140 = 0.90 \), so 90 %.
  2. Verified by analysis: \( 8 / 140 \approx 5.7 \) %; these may be acceptable if analysis is the planned method.
  3. Unverified: \( 6 / 140 \approx 4.3 \) %; each needs a test, an analysis or a decision to remove the requirement.

Answer: 90 % are verified by test. The 6 untraced requirements are a release risk: either verify them or delete them with a recorded reason.

Documentation that stays alive

Documentation decays unless it is cheap to maintain. Practical habits help: keep docs in the repository as Markdown or reStructuredText so they are reviewed with code; generate API documentation from code comments (for example with Doxygen or Sphinx, as the ROS documentation system does); keep a README in every package stating what it does, its interfaces and how to run its tests; and write runbooks for operators and field technicians in plain language. A good test is whether a new team member can build, run and test a package in a day using only its documentation.

Common mistakes

  • MistakeWriting requirements such as "the robot shall be reliable"

    InsteadState a measurable quantity, a condition, a limit and a statistic.

  • MistakeSpecifying only the happy path of each use case

    InsteadWrite the exception flows; they become the most valuable test cases.

  • MistakeClaiming 99.9 % reliability from 50 successful trials

    InsteadZero failures in n trials bounds the failure rate near 3/n; plan trial counts accordingly.

  • MistakeChanging the units of an existing message field

    InsteadCreate a new field or message type and version the interface.

  • MistakeRecording only which option won a design decision

    InsteadWrite an ADR with context, options, consequences and sensitivity.

Summary and key terms

  • Requirements come from many stakeholders and are bounded by an operational design domain.
  • Use cases and scenarios, especially their exception flows, become test cases.
  • Good requirements are necessary, unambiguous, verifiable, feasible and singular, with a rationale and verification method.
  • Statistical requirements need enough trials; zero failures in n trials supports a failure rate of roughly 3/n.
  • Interface control documents and carefully written message definitions prevent unit, frame and timing mismatches.
  • Architecture decision records capture why decisions were made and are superseded rather than edited.
  • Traceability links requirements to design and tests, as the V-model pictures, and documentation lives with the code.
Stakeholder
A person or organization with an interest in the system.
Operational design domain
The conditions under which a robot is designed to operate.
Use case
A description of how an actor uses the system to reach a goal, including exception flows.
Non-functional requirement
A requirement on qualities such as latency, accuracy, availability or security.
EARS
A set of templates for writing clear requirements, such as "When <trigger>, the <system> shall <response>".
Verification method
How a requirement will be checked: inspection, analysis, demonstration, test or simulation.
Interface control document
A specification of an interface: data, units, frames, rates, timing and ownership.
Architecture decision record
A short, dated document recording one significant design decision and its rationale.
Traceability
Links between requirements, design elements and tests in both directions.
V-model
A development model pairing each level of design with a matching level of testing.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. What does an operational design domain describe?

    Show answer

    The conditions under which the robot is meant to work.

  2. Rewrite "the robot shall dock quickly" as a verifiable requirement.

    Show answer

    For example: "The robot shall complete docking within 60 s of arriving at the approach point in 95 % of attempts."

  3. Name the four classic verification methods.

    Show answer

    Inspection, analysis, demonstration and test.

  4. About how many failure-free trials support a failure rate below 0.5 %?

    Show answer

    About 600.

  5. What should an ICD state about a topic besides its message type?

    Show answer

    Units, frames, rate, QoS, latency budget, owner and error handling.

  6. Is adding an optional message field usually a breaking change?

    Show answer

    No; changing meaning or units is.

  7. What four parts does an ADR usually contain?

    Show answer

    Context, options, decision and consequences.

  8. Why are ADRs not edited after acceptance?

    Show answer

    They record history; a new ADR supersedes an old one.

  9. In the V-model, which tests verify the architecture?

    Show answer

    Integration tests.

  10. Name one habit that keeps documentation current.

    Show answer

    Keep it in the repository and review it with code.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz