nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
nros C++ API

Lightweight ROS 2 client library for embedded real-time systems — freestanding C++14 surface that mirrors rclcpp.

Quick Start

#include <nros/nros.hpp>
#include "std_msgs.hpp" // generated by nano_ros_generate_interfaces()
int main() {
// 1. Initialise the global session.
NROS_TRY(nros::init("tcp/127.0.0.1:7447"));
// 2. Create a node.
nros::Node node;
NROS_TRY(nros::create_node(node, "cpp_talker"));
// 3. Create a typed publisher.
NROS_TRY(node.create_publisher(pub, "/chatter"));
// 4. Publish messages.
std_msgs::msg::Int32 msg{};
for (int i = 0; nros::ok() && i < 10; ++i) {
msg.data = i;
pub.publish(msg);
nros::spin(1000);
}
return 0;
}
Definition future.hpp:40
Definition node.hpp:158
Result create_publisher(Publisher< M > &out, const char *topic, const QoS &qos=QoS::default_profile())
Definition publisher.hpp:272
Result spin()
Definition nros.hpp:77
Result shutdown()
Definition node.hpp:663
bool ok()
Check if the nros session is initialized.
Definition node.hpp:717
Result init(const char *locator=nullptr, uint8_t domain_id=0)
Definition node.hpp:568
Result create_node(Node &out, const char *name, const char *ns=nullptr)
Definition node.hpp:728
Umbrella header — pulls in every public C++ API surface.
#define NROS_TRY(expr)
Definition result.hpp:90

See Getting Started for the full walkthrough.

API Modules

The C++ API is organised into the following module groups (see the Modules tab in the sidebar for each group's contents):

Group Description
init Library initialisation, global session, nros::ok()
node Node creation and lifecycle (nros::Node)
pubsub Publishers and subscriptions (nros::Publisher<M>, nros::Subscription<M>)
service Service servers and clients (nros::Service<S>, nros::Client<S>)
action Action servers and clients (nros::ActionServer<A>, nros::ActionClient<A>)
executor Callback dispatch, timers, guard conditions
clock Monotonic and wall-clock time
qos Quality-of-Service settings
errors Error codes, nros::Result, NROS_TRY
support Span, FixedString, FixedSequence, std_compat

Header Organisation

Include the umbrella header for the full surface:

#include <nros/nros.hpp>

Or include only the per-module headers you need (<nros/publisher.hpp>, <nros/subscription.hpp>, …) for faster compile times in large projects.

Concepts

Guides

Freestanding vs <tt>std</tt>

By default nros-cpp is freestanding C++14: no STL, no exceptions, no RTTI. Define NROS_CPP_STD before including <nros/nros.hpp> to enable std::string, std::function, and std::chrono convenience overloads on host platforms.