PricingDownload
Product

Platform

All features32 capabilities, from IDE to CICompliance KitsISO 26262, DO-178C, IEC 62304...AI GovernanceControl AI-generated C/C++ codeWhat’s new in 2027Latest version highlightsScreenshotsSee the product in action

Analyze & improve

Coding standardsMISRA, CERT, CWE, AUTOSARArchitecture & dependenciesGraphs, matrix, cyclesTechnical debtMeasured in hours and dollarsQuality gatesStop regressions in CISmart Code CityYour codebase in 3D

Integrations

IDE pluginsVisual Studio, VS Code, CLion...CI/CD pipelinesJenkins, Azure DevOps, GitHub, GitLabSonarQube pluginC/C++ results in SonarQubeExternal analyzersClang-Tidy, Cppcheck, coverageFeature on Demand
Solutions

By need

Functional safetyCompliance kits per standardCoding standardsMISRA, CERT, AUTOSAR, ISO...Legacy modernizationRefactor large C/C++ safelyCode auditExpert review of your codebaseM&A due diligenceAssess technical health fast

By role

DevelopersSoftware architectsTech leadsDevOps engineersEngineering managersProject managers

CTOsCIOs / IT leadersQA engineersSecurity leadersComplianceConsultantsRequest a guided PoC
Industries

Safety-critical

AutomotiveISO 26262, MISRA, AUTOSARAerospace & DefenseDO-178C programsMedical DevicesIEC 62304 softwareEnergy & UtilitiesIEC 61508 systemsEmbedded SystemsFirmware and devices

Enterprise

Financial ServicesTrading and paymentsGame DevelopmentEngines and large C++Software VendorsCommercial C/C++ productsGovernmentAgencies and contractorsAll industries & case studies
Resources

Learn

DocumentationGuides, rules and CI setupKnowledge baseFrequently asked questionsBlogC and C++ code quality articlesRelease notesEvery version since 2009

Customers

Case studiesSuccess storiesTestimonialsWhat users sayOur customersCompanies using CppDependGold Code QualityOpen source projects we rate

Programs & company

Feature on DemandMissing features built for freeFree for open sourceLicenses for OSS and studentsContact usSales and supportEULALicense agreement
Docs
Documentation

User Guides

ROS 2 Analysis Guide

What the ROS 2 section of CppDepend shows, how to read each page, and what to do about each finding. Illustrated with a demo package (2 nodes, 6 publishers, 4 subscriptions, 3 timers, 1 service, 1 client, 35 findings).

22 min readUser GuidesCppDepend 2027

Introduction

A ROS 2 system fails quietly. A topic with the wrong QoS, a message type that differs by one word, a callback that sleeps, a service client waiting for an answer that can never be delivered: none of these produces a compile error, and most produce no run-time error either. Nodes start, and nothing happens.

The ROS 2 section of the Features tree rebuilds the architecture of a C++ (rclcpp) package from its sources, package.xml, CMakeLists.txt, Python launch files and YAML parameter files, and checks it with 32 rules. It answers: who publishes and who listens, do the QoS profiles match, what runs in which callback group on which executor, can a callback block or deadlock, are parameters declared and used, does the build and launch description agree with the code?

Nothing is run and no ROS installation is needed: the analysis is static, like the rest of CppDepend.

7 pagesOverview, Nodes & Topics, Callbacks & Executors, QoS Compatibility, Services & Parameters, Blocking & Deadlocks, Build & Launch.
32 rulesROS2-TOPIC / QOS / SRV / CB / EXEC / LIFE / PARAM / BUILD / LAUNCH.
Imported issuesEvery finding is an issue of the tool ROS2: Issues panel, report, quality gates.
ActionableOpen at file and line, standards chips, baseline for “only new findings”.

How it works

  • Nodes. Every class that derives from rclcpp::Node or rclcpp_lifecycle::LifecycleNode is a node. A class registered with RCLCPP_COMPONENTS_REGISTER_NODE is marked as a component. The node name is read from the constructor call.
  • Entities. Publishers, subscriptions, timers, services, clients, action servers and clients and parameters are read from the create_* and declare_parameter calls. Topic names are read from string literals and from const strings; a name built at run time is skipped. QoS is read from rclcpp::QoS(...), from the chained calls (.reliable(), .transient_local()…) and from the predefined profiles.
  • Callbacks. Method callbacks and lambdas are turned into functions of their own. The call graph then follows the calls: a helper called from a callback counts as part of the callback (for example “calls spin_some (through helper)”).
  • Callback groups and executors. Callback groups (MutuallyExclusive or Reentrant), rclcpp::spin, SingleThreadedExecutor and MultiThreadedExecutor are read from the code of main().
  • Build and launch. package.xml (dependencies), CMakeLists.txt (find_package, executables), *.launch.py (Node(...), ComposableNode(...), names, namespaces, remaps) and YAML parameter files.
  • Rules and result. The 32 rules run on this model. The result is stored next to the analysis result as <result>.ros2.json; the pages read it, and every finding is also sent to the Issues panel.
A hint, not a proofThe graph is built from what the sources say. A topic published by another package or replayed from a bag shows as “no publisher”; a launch namespace or remap can change a name at run time. Findings that depend on this say so in their message.

The demo project

The screenshots show a small package demo_pkg written to contain one example of almost every mistake. The numbers you will see in the pages:

ItemValueDetail
Nodes2sensor (class SensorNode) and control_node (class ControlNode)
Publishers / subscriptions6 / 4SensorNode: 4 publishers; ControlNode: 2 publishers and 4 subscriptions
Timers, services, clients3, 1, 12 timers in SensorNode, 1 in ControlNode; service /reset; client /add_two_ints
Callbacks8timers, subscriptions and the service callback
Executor1MultiThreadedExecutor created in main
Findings3518 High, 4 Medium, 13 Other

1 · ROS 2 Overview

Page 1: ROS 2 Overview, with the explanation card, the tiles and the first area cards.
Page 1: ROS 2 Overview, with the explanation card, the tiles and the first area cards.

What is on the screen

  • “What this page shows” card: the explanation of the page. Every page of the section starts with one.
  • Tiles, in two rows: Nodes, Publishers, Subscriptions, Timers, Services, Clients, Callbacks, then the findings as High (red), Medium (orange) and Other (grey).
  • Areas: one card per page below (Nodes & Topics, Callbacks & Executors, and so on) with its number of findings and how many are High. A click opens the page.
  • Under the areas: the baseline card, the standards evidence card and the complete list of findings grouped by rule.
  • Refresh (top right) reloads the result of the last analysis.

How to read it

Start with the red tile. A High finding means the system cannot work as written: messages that never arrive, a callback that stops the executor, a deadlock. A green tile means nothing of that class was found. The area cards tell you which page to open first: in the demo, Nodes & Topics has 7 findings (2 High) and Callbacks & Executors has 8 (4 High).

What to do

Open the area with the most High findings. Once the picture is clear, use Set baseline (see Baseline) so that later analyses show only what is new.

Rules of this page

No rules of its own: it summarises the other pages.

In the demo project

  • 2 nodes, 6 publishers and 4 subscriptions: the topics are not all connected (see page 2).
  • 18 High findings come mostly from QoS and type mismatches, blocking callbacks, the deadlock, missing rclcpp::init and the lost publisher handle.

2 · Nodes & Topics

Page 2: Nodes &amp; Topics, the node table and the beginning of the topic graph.
Page 2: Nodes & Topics, the node table and the beginning of the topic graph.

What is on the screen

  • Nodes: one row per node with its class and the number of publishers (Pub), subscriptions (Sub), timers, services, clients and parameters. A node registered as a component is marked.
  • Topic graph: one row per topic with the message type, the publishers and the subscribers (each with its QoS: reliability, durability, history and depth) and a State badge.
State badgeMeaning
connectedAt least one publisher and one subscriber, same type, compatible QoS.
no subscriberGrey: published, nobody listens.
no publisherOrange: subscribed, nothing is published.
mismatchRed: a type, reliability or durability mismatch. The two sides never connect.

How to read it

Look for topics that cannot work: a subscriber with no publisher (nothing arrives), two different types on one topic, a QoS mismatch. A publisher with no subscriber is often fine (rviz, rosbag, another package), but it is also what a typo looks like: /scan vs /scann gives one orange and one grey row.

What to do

  • Compare the names of the orange and grey rows: a pair that differs by one character is a typo.
  • Check the namespace of the node in the launch file: a relative name scan becomes /ns/scan.
  • Use one constant for each topic name and type, shared by both nodes.

Rules of this page

RuleWhat it detectsHow to fixStandards
ROS2-TOPIC-01Subscription without publisherCheck the topic name and namespace, or start the node that publishes it. With a launch remap the names may no longer match.
ROS2-TOPIC-02Publisher without subscriberFine for topics read by tools such as rviz or rosbag; otherwise remove the publisher or add the subscriber.
ROS2-TOPIC-03Topic type mismatchPublisher and subscriber must use the same message type: they never connect otherwise.
ROS2-TOPIC-04Invalid topic, service or action nameUse letters, digits and underscores separated by '/'; a segment cannot start with a digit.
ROS2-TOPIC-05Node subscribes to its own topicCheck that the callback does not publish the message again (infinite loop).

In the demo project

  • /bad-topic name (std_msgs/msg/String) is published by SensorNode and has no subscriber; its name also contains a hyphen and a space (ROS2-TOPIC-04).
  • /scan: SensorNode publishes std_msgs/msg/Float32, ControlNode subscribes with std_msgs/msg/String (ROS2-TOPIC-03).
  • /nobody_publishes is subscribed and not published (ROS2-TOPIC-01); /lost_handle, /bad-topic name and /dyn are published and not subscribed (ROS2-TOPIC-02).
  • ControlNode publishes and subscribes to /cmd and receives its own messages (ROS2-TOPIC-05); the row shows connected.

3 · Callbacks & Executors

Page 3: Callbacks &amp; Executors, the executor table and the callback table.
Page 3: Callbacks & Executors, the executor table and the callback table.

What is on the screen

  • Executors: each executor created in the code, where it is created (function) and its number of threads (auto = hardware concurrency). rclcpp::spin(node) uses a single-threaded executor.
  • Callbacks: every subscription, timer, service and action callback with:
    • Kind (Timer, Subscription, Service…) and Node;
    • Callback name (lambda for an anonymous function);
    • Trigger: the period of a timer or the topic or service name;
    • Group: the callback group (default group when none is given);
    • Type: MutuallyExclusive (grey) or Reentrant (green);
    • Blocks in: the blocking call found in the callback (red), empty when none.
  • Below: the findings about spinning and the life of entities.

How to read it

The rule to keep in mind: callbacks of one MutuallyExclusive group never run at the same time, even on a MultiThreadedExecutor. By default every callback of a node is in the same default group, so a multi-threaded executor gives no parallelism unless you create groups. A Reentrant group allows the callbacks of that group to run in parallel, including a callback with itself, so its shared data needs protection.

A red “Blocks in” cell means that while that callback runs, every other callback of its group (or, on a single-threaded executor, of the whole process) waits.

What to do

  • Give independent work its own group:
    auto g = create_callback_group(rclcpp::CallbackGroupType::Reentrant);
    rclcpp::SubscriptionOptions o; o.callback_group = g;
    sub_ = create_subscription<std_msgs::msg::String>("cmd", 10, cb, o);
  • Create entities once, in the constructor, and keep them in members.
  • Call rclcpp::init first and rclcpp::shutdown last in main(); spin from main() only.

Rules of this page

RuleWhat it detectsHow to fixStandards
ROS2-EXEC-01Spin inside a node constructorCreate the node, then spin it from main() or from an executor.
ROS2-EXEC-02Node created but never spunCall rclcpp::spin(node) or add the node to an executor and spin it.
ROS2-EXEC-03Timer callback longer than its periodShorten the callback, increase the period, or move the work to another thread.
ROS2-EXEC-04Second spin never reachedAdd all the nodes to one executor and spin it once.
ROS2-EXEC-05Multi-threaded executor with a single callback groupCreate Reentrant or separate MutuallyExclusive groups for the callbacks that may run in parallel.
ROS2-LIFE-01rclcpp::init missingCall rclcpp::init(argc, argv) first in main().
ROS2-LIFE-02Created entity is destroyed at onceKeep the returned shared pointer in a member variable.
ROS2-LIFE-03Entity created inside a callbackCreate publishers, subscriptions and timers once, in the constructor.CWE-401 (Missing release of memory)
ROS2-LIFE-04rclcpp::shutdown missingCall rclcpp::shutdown() before leaving main().

In the demo project

  • One MultiThreadedExecutor created in main; but SensorNode’s callbacks are all in the default group (ROS2-EXEC-05).
  • The 50 ms timer of SensorNode sleeps 200 ms: it can never keep its rate (ROS2-EXEC-03).
  • The ControlNode constructor calls spin (ROS2-EXEC-01); main() spins twice, so the second spin is reached only after Ctrl-C (ROS2-EXEC-04).
  • main() never calls rclcpp::init (ROS2-LIFE-01, creating a node will throw) nor rclcpp::shutdown (ROS2-LIFE-04).
  • The publisher lost_handle is not stored and is destroyed at once (ROS2-LIFE-02); the publisher dyn is created in a callback at every call (ROS2-LIFE-03).

4 · QoS Compatibility

Page 4: QoS Compatibility, the QoS of every publisher and subscription.
Page 4: QoS Compatibility, the QoS of every publisher and subscription.

What is on the screen

One table for the whole system: Topic, Role (Publisher or Subscription), Node, Reliability, Durability, History and Code (how the QoS was written: a depth such as 10, a profile name, or the variable that holds it, such as qos). An empty cell means the code does not set it: the system default applies. Best-effort is orange, reliable is green.

How to read it

Compatibility rules of DDS, in one table:

Publisher offersSubscription requestsResult
reliablereliable or best_effortconnected
best_effortbest_effortconnected
best_effortreliablenever connects (ROS2-QOS-01)
transient_localtransient_local or volatileconnected
volatiletransient_localnever connects (ROS2-QOS-02)

There is no error message at run time: the topic is simply silent. ros2 topic info -v shows the same incompatibility, but only after you start the system.

What to do

  • Make both sides use the same profile. Define it once:
    // in a shared header
    inline rclcpp::QoS ScanQoS() { return rclcpp::SensorDataQoS(); }
    // publisher and subscription
    create_publisher<sensor_msgs::msg::LaserScan>("scan", ScanQoS());
  • Use KeepLast(N) unless every message must be kept (ROS2-QOS-03).
  • When the code builds the QoS in a variable (Code column shows a name), the analysis reads the chained calls; if it cannot, the cells stay empty and no mismatch is reported.

Rules of this page

RuleWhat it detectsHow to fixStandards
ROS2-QOS-01QoS reliability mismatchA reliable subscription cannot receive from a best_effort publisher: make both reliable or both best_effort.
ROS2-QOS-02QoS durability mismatchA transient_local subscription needs a transient_local publisher: set the same durability on both.
ROS2-QOS-03KeepAll history (unbounded memory)Use KeepLast(N) unless every message must be kept; memory grows when the other side is slow.CWE-770 (Allocation without limits)

In the demo project

  • /scan: SensorNode publishes best_effort, ControlNode requests reliable: no message is delivered (ROS2-QOS-01). The Code column shows qos, a variable.
  • /status: the subscription requests transient_local, the publisher is volatile (ROS2-QOS-02).
  • The other topics use the default: reliable, volatile, keep_last (10).

5 · Services & Parameters

Page 5: Services &amp; Parameters, the service and action table and the parameter table.
Page 5: Services & Parameters, the service and action table and the parameter table.

What is on the screen

  • Services and actions: Name, Role (Service/server, Client, Action server, Action client), Node, Type (package/srv/Name) and, for a server, the Callback that answers.
  • Parameters: each declare_parameter with its node and default value.
  • Below: the YAML parameter files with the keys they set, and the findings.

How to read it

A client without a server waits forever (or until its timeout). A parameter read before it is declared throws ParameterNotDeclaredException. A YAML key that no node declares is ignored silently: the usual causes are a misspelt key and a wrong node name in the file.

What to do

  • Check the service name and namespace, and that its package is built and launched. A server in another package is normal: the message says “may be in another package”.
  • Declare every parameter in the constructor:
    declare_parameter("rate", 10);
    ...
    int rate = get_parameter("rate").as_int();
  • Remove declared parameters nobody reads, and YAML keys nobody declares.

Rules of this page

RuleWhat it detectsHow to fixStandards
ROS2-PARAM-01Parameter read but not declaredCall declare_parameter(name, default) in the constructor before get_parameter.
ROS2-PARAM-02Parameter declared but never readRead it with get_parameter, or remove the declaration.
ROS2-PARAM-03Parameter file key not declaredDeclare the parameter in the node, or remove the key from the file.
ROS2-SRV-01Service client without serverCheck the service name, or start the node that provides it.
ROS2-SRV-02Service type mismatchClient and server must use the same .srv type.
ROS2-SRV-03Service server without clientFine for services called from the command line; otherwise remove it.

In the demo project

  • The client /add_two_ints (example_interfaces/srv/AddTwoInts) has no server in the sources (ROS2-SRV-01).
  • The service /reset (std_srvs/srv/Trigger, callback ControlNode::on_reset) has no client (ROS2-SRV-03).
  • missing_param is read but not declared (ROS2-PARAM-01); rate and never_used are declared and never read (ROS2-PARAM-02).
  • params.yaml sets gain and unknown_option, which no node declares (ROS2-PARAM-03).

6 · Blocking & Deadlocks

Page 6: Blocking &amp; Deadlocks, the callbacks that block and the baseline card.
Page 6: Blocking & Deadlocks, the callbacks that block and the baseline card.

What is on the screen

  • Callbacks that block: only the callbacks that wait, spin or loop, with Kind, Node, Callback, Trigger, Group, Type and the blocking call in red. Recognised: sleep_for, sleep_until, future.get()/wait(), spin_until_future_complete, spin_some, spin, wait_for_service, an endless loop (while (true) without break or return).
  • The Baseline card (see Baseline): in the screenshot “No baseline: every finding counts as new” and the Set baseline button.
  • The findings, including data shared between callbacks.

How to read it

While a callback blocks, every other callback of the same MutuallyExclusive group waits, and on a single-threaded executor the whole node does. The worst case is the deadlock: a callback sends a service request with a client of its own group, then waits for the answer; the answer is delivered by a callback of that same group, which cannot start because the first one has not returned.

What to do

  • Replace the wait by an asynchronous call with a response callback:
    client_->async_send_request(req,
      [this](rclcpp::Client<AddTwoInts>::SharedFuture f) {
        RCLCPP_INFO(get_logger(), "sum %ld", f.get()->sum);
      });
  • If a synchronous call is unavoidable: put the client in its own (or a Reentrant) group and use a MultiThreadedExecutor.
  • Replace sleep_for by a timer; run an endless loop in its own thread, or do one step per timer call.
  • Protect a member written by one callback and read by another with a mutex or std::atomic.

Rules of this page

RuleWhat it detectsHow to fixStandards
ROS2-CB-01Blocking call in a callbackNever sleep or wait in a callback: use a timer, an asynchronous call with a response callback, or another thread.
ROS2-CB-02Spin inside a callbackDo not spin from a callback: the executor is already spinning. Use callbacks and futures instead.
ROS2-CB-03Synchronous service call deadlockPut the client in its own callback group (or a Reentrant one) and use a MultiThreadedExecutor, or use async_send_request with a response callback.CWE-833 (Deadlock)
ROS2-CB-04Endless loop in a callbackDo one step per call and let a timer call it again, or run the loop in its own thread.CWE-835 (Infinite loop)
ROS2-CB-05Unprotected data shared between callbacksProtect the member with a mutex (std::lock_guard) or use std::atomic, or put the callbacks in one MutuallyExclusive group.CWE-362 (Race condition), CWE-820 (Missing synchronization)

In the demo project

  • 5 blocking callbacks: the lambda timer of SensorNode (sleep_for), on_scan (get), on_cmd (spin_some, Reentrant group fast_group_), on_reset (sleep_for) and the 1000 ms lambda timer of ControlNode (endless loop).
  • on_scan waits for /add_two_ints with a client of its own MutuallyExclusive group: deadlock (ROS2-CB-03).
  • on_cmd reaches spin_some through a helper (ROS2-CB-02).
  • counter_ is written by the timer and read by on_cmd without protection (ROS2-CB-05).

7 · Build & Launch

Page 7: Build &amp; Launch, the packages and the launched nodes.
Page 7: Build & Launch, the packages and the launched nodes.

What is on the screen

  • Packages (from package.xml and CMakeLists.txt): the dependencies declared in package.xml, the find_package lines, and the executables.
  • Launched nodes (from *.launch.py, Node(...) and ComposableNode(...)): name, namespace, package / executable and the remaps (old -> new).
  • Below: the findings of the consistency checks, and the YAML files used by the launch.

How to read it

A message package that is included but not declared in package.xml builds on your machine (it is installed) and fails in a clean workspace or a CI container, or builds in the wrong order. Two launched nodes with the same name and namespace collide: their topics and parameters mix. A remap that matches nothing does nothing.

What to do

  • For every #include <pkg/...> add <depend>pkg</depend> to package.xml, and find_package(pkg REQUIRED) with ament_target_dependencies in CMake.
  • Give each launched node a unique name or namespace.
  • Check the left side of a remap against the name used in the code (or the full name after the namespace).

Rules of this page

RuleWhat it detectsHow to fixStandards
ROS2-BUILD-01Included package missing from package.xmlAdd a <depend> line for the package in package.xml.
ROS2-BUILD-02Included package missing from CMake find_packageAdd find_package(<package> REQUIRED) and list it in ament_target_dependencies.
ROS2-LAUNCH-01Launch remap matches nothingCheck the name on the left of the remap: it must match a topic or service name used by the node.
ROS2-LAUNCH-02Duplicate node name in launchGive each node a unique name or namespace.

In the demo project

  • Package demo_pkg: dependencies ament_cmake, rclcpp, std_msgs, the same in find_package; executable sensor_node.
  • nodes.cpp includes std_srvs and example_interfaces headers that package.xml does not declare (ROS2-BUILD-01, twice).
  • The launch file starts two nodes called sensor in namespace / (ROS2-LAUNCH-02); the second remaps /does_not_exist -> /other, which matches nothing (ROS2-LAUNCH-01).

Reading a finding

Findings are listed on the Overview and on the page of their area, grouped by rule in expanders. Each finding shows:

  • Severity colour: red High, orange Medium, grey Other.
  • Message: names the node, the callback or entity and the cause (“the subscription callback on_scan of ControlNode (scan) blocks in fut.get()…”).
  • Location file:line: click to copy.
  • Open button: opens the source file at that line (in the editor chosen in the options; in the browser through VS Code).
  • Standards chips for the rules that have a real counterpart (see below).
  • New / in baseline badge once a baseline exists.

For findings in package.xml, CMakeLists.txt, a launch file or a YAML file, the Open button opens that file.

Baseline & new findings

For CI gates you usually care about what is new. The Baseline card (visible on every findings page, as in the Blocking & Deadlocks screenshot, where it says “No baseline: every finding counts as new”) takes the current findings as the reference.

  • Set baseline / Update baseline: stores a fingerprint of every finding (rule + file name + function + message without numbers). Moving code does not make a finding new.
  • Clear baseline: forgets the reference.
  • Show only new findings here: filters the page.
  • Only new findings in the Issues panel and quality gates: from the next analysis, findings already in the baseline are not sent to the Issues panel, the report and the gates. A gate on “no High issue of tool ROS2” then means “no new High issue”.
  • The findings fixed since the baseline are listed when some disappeared.

The baseline file <project>.findings-baseline.json is shared with the RTOS analysis (one section per tool). If the project file is unknown the card says so: analyse from a saved project. Without the GUI (CI): make-baseline.py <project> <analysis-result> [--only-new].

Standards evidence

Most ROS 2 rules are design rules of the framework and have no equivalent in a coding standard. Only the rules with a real counterpart carry standards chips, and the Overview ends with a Standards evidence card (green = checked, no finding; red = findings).

RuleReference
ROS2-CB-03 synchronous service call deadlockCWE-833 Deadlock
ROS2-CB-04 endless loop in a callbackCWE-835 Loop with unreachable exit condition
ROS2-CB-05 unprotected shared dataCWE-362 Race condition; CWE-820 Missing synchronization
ROS2-LIFE-03 entity created in a callbackCWE-401 Missing release of memory
ROS2-QOS-03 KeepAll historyCWE-770 Allocation without limits
Guidance, not certificationCheck rule numbers against the edition your project is assessed against. MISRA C++ and AUTOSAR C++14 rules apply to the C++ code itself and are not specific to ROS 2.

Issues & quality gates

Findings are imported issues of the tool ROS2. They appear in the Issues panel, in the HTML report and in the quality gates; the issue type is the rule id (ROS2-CB-03…). With Only new findings enabled, baseline findings are left out of all three.

// all High issues of the ROS 2 analysis
from i in ImportedIssues where i.Tool == "ROS2" && i.Severity == Severity.High select i

Typical gates: no High finding of tool ROS2; no ROS2-CB-03 (deadlock); no ROS2-QOS-01 or ROS2-TOPIC-03 (a connection that can never work).

Result files

FileContent
<result>.ros2.jsonEverything the pages show: nodes, topics, QoS, callbacks, executors, services, parameters, packages, launch, findings with fingerprints and standards.
<project>.findings-baseline.jsonThe baseline (RTOS and ROS 2).

Limits

  • Static analysis of C++ (rclcpp). Python nodes (rclpy) are not analysed.
  • Topic, service and parameter names built at run time are skipped. Namespaces and remaps from the launch files are not applied to the graph: findings affected by them say so (“the launch files use namespaces or remaps”).
  • Only Python launch files (*.launch.py) are read; XML and YAML launch files are not.
  • Custom message definitions (.msg, .srv) are not checked; a type is compared by its name.
  • A topic or service used with another package (or a rosbag) looks unconnected: severity of those findings is deliberately low.
  • Callback groups and executors are tracked by name in the source; groups passed through several layers of functions can be missed.

Troubleshooting

SymptomCause and remedy
“No ROS 2 result yet”Run the analysis, then Refresh. Results of an older version need a new analysis.
The section is emptyNo class derives from rclcpp::Node in the analysed sources: check that the package sources are part of the project.
A node is missingNode created without a class (std::make_shared<rclcpp::Node>("x") in main) or a class defined in a macro or generated code.
A topic shows no publisher but you know it existsPublished by another package, or the name is built at run time.
QoS cells are emptyThe QoS comes from a variable or a function the analysis cannot follow: the system default is assumed and no mismatch is reported.
Build & Launch is emptyNo package.xml or *.launch.py under the project folders.
Baseline cannot be savedProject file unknown: analyse from a saved project.

All rules

32 rules.

RuleWhat it detectsHow to fixStandards
ROS2-BUILD-01Included package missing from package.xmlAdd a <depend> line for the package in package.xml.
ROS2-BUILD-02Included package missing from CMake find_packageAdd find_package(<package> REQUIRED) and list it in ament_target_dependencies.
ROS2-CB-01Blocking call in a callbackNever sleep or wait in a callback: use a timer, an asynchronous call with a response callback, or another thread.
ROS2-CB-02Spin inside a callbackDo not spin from a callback: the executor is already spinning. Use callbacks and futures instead.
ROS2-CB-03Synchronous service call deadlockPut the client in its own callback group (or a Reentrant one) and use a MultiThreadedExecutor, or use async_send_request with a response callback.CWE-833 (Deadlock)
ROS2-CB-04Endless loop in a callbackDo one step per call and let a timer call it again, or run the loop in its own thread.CWE-835 (Infinite loop)
ROS2-CB-05Unprotected data shared between callbacksProtect the member with a mutex (std::lock_guard) or use std::atomic, or put the callbacks in one MutuallyExclusive group.CWE-362 (Race condition), CWE-820 (Missing synchronization)
ROS2-EXEC-01Spin inside a node constructorCreate the node, then spin it from main() or from an executor.
ROS2-EXEC-02Node created but never spunCall rclcpp::spin(node) or add the node to an executor and spin it.
ROS2-EXEC-03Timer callback longer than its periodShorten the callback, increase the period, or move the work to another thread.
ROS2-EXEC-04Second spin never reachedAdd all the nodes to one executor and spin it once.
ROS2-EXEC-05Multi-threaded executor with a single callback groupCreate Reentrant or separate MutuallyExclusive groups for the callbacks that may run in parallel.
ROS2-LAUNCH-01Launch remap matches nothingCheck the name on the left of the remap: it must match a topic or service name used by the node.
ROS2-LAUNCH-02Duplicate node name in launchGive each node a unique name or namespace.
ROS2-LIFE-01rclcpp::init missingCall rclcpp::init(argc, argv) first in main().
ROS2-LIFE-02Created entity is destroyed at onceKeep the returned shared pointer in a member variable.
ROS2-LIFE-03Entity created inside a callbackCreate publishers, subscriptions and timers once, in the constructor.CWE-401 (Missing release of memory)
ROS2-LIFE-04rclcpp::shutdown missingCall rclcpp::shutdown() before leaving main().
ROS2-PARAM-01Parameter read but not declaredCall declare_parameter(name, default) in the constructor before get_parameter.
ROS2-PARAM-02Parameter declared but never readRead it with get_parameter, or remove the declaration.
ROS2-PARAM-03Parameter file key not declaredDeclare the parameter in the node, or remove the key from the file.
ROS2-QOS-01QoS reliability mismatchA reliable subscription cannot receive from a best_effort publisher: make both reliable or both best_effort.
ROS2-QOS-02QoS durability mismatchA transient_local subscription needs a transient_local publisher: set the same durability on both.
ROS2-QOS-03KeepAll history (unbounded memory)Use KeepLast(N) unless every message must be kept; memory grows when the other side is slow.CWE-770 (Allocation without limits)
ROS2-SRV-01Service client without serverCheck the service name, or start the node that provides it.
ROS2-SRV-02Service type mismatchClient and server must use the same .srv type.
ROS2-SRV-03Service server without clientFine for services called from the command line; otherwise remove it.
ROS2-TOPIC-01Subscription without publisherCheck the topic name and namespace, or start the node that publishes it. With a launch remap the names may no longer match.
ROS2-TOPIC-02Publisher without subscriberFine for topics read by tools such as rviz or rosbag; otherwise remove the publisher or add the subscriber.
ROS2-TOPIC-03Topic type mismatchPublisher and subscriber must use the same message type: they never connect otherwise.
ROS2-TOPIC-04Invalid topic, service or action nameUse letters, digits and underscores separated by '/'; a segment cannot start with a digit.
ROS2-TOPIC-05Node subscribes to its own topicCheck that the callback does not publish the message again (infinite loop).
Was this page helpful?
Evaluating CppDepend on a production codebase?Get a guided proof of concept with our static analysis architects.
Request a PoC