Skip to content
cccskills
FreePublished on GitHub

add-ros-publisher

Extend CARLA’s native ROS 2 interface to publish sensor data or receive vehicle commands. Covers topic implementation, registration, data connections, and verification, plus adding middleware, the communication layer used to exchange messages.

OriginalShow the original description

Adds a new topic to CARLA's native ROS 2 interface — a publisher (BasePublisher + PublisherImpl, topic suffix, QoS, registration in ROS2::GetOrCreateSensor, a ProcessDataFrom* entry point and its call site in the UE4 plugin) or a subscriber that lets ROS drive an actor. Also covers adding a middleware (RMW) behind IPublisherMiddleware. Use when the user asks to "publish X to ROS from CARLA", "add a ROS topic/publisher/subscriber", "make the obstacle/lane-invasion sensor publish", "add odometry to ROS", or "add another RMW".

See how to install

Good for

  • Publish obstacle sensor data to ROS 2
  • Add a topic for vehicle speed commands
  • Integrate another communication middleware
  • Investigate a topic that builds but stays silent

Files included (5)

  • SKILL.md11.4 KB
  • references/layers.md6.7 KB
  • scripts/check_env.sh3.3 KB
  • scripts/env.sh2.2 KB
  • scripts/verify.sh1.7 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Add a ROS 2 publisher or subscriber

Paths. scripts/… and references/… below are relative to the directory holding this SKILL.md. Your working directory is the user's project, not that directory, so prefix them with its absolute path or the command is not found.

A topic exists only when four things line up: a message type, a publisher object, a registration so something creates it, and a call site that feeds it data. Miss the last one and everything compiles while the topic never appears.

UE4 sensor/actor  --ProcessDataFrom*-->  ROS2 (dispatch, ROS2.cpp)
                                          |  GetOrCreateSensor / RegisterVehicle
                                          v
                            Carla<X>Publisher  (topic suffix + QoS)
                                          v
                            PublisherImpl<Traits>  -> MiddlewareFactory
                                          v
                     FastDDS | CycloneDDS | Zenoh middleware

Message types are [[add-ros-message-type]]; this skill is everything below the type.

On CARLA 0.10.0 (the UE5 line: 5.5 and 5.8)

The publisher layer was refactored on 0.10.0, so the file you copy from differs. The right-hand column is UE 5.8; UE 5.5 has the same BasicPublisher refactor but no middleware/ directory, so its QoS type is the pre-QosProfile.h one and it has none of the Autoware rows ([[check-ue5-limitations]]):

0.9.x0.10.0
base class to inheritCarlaPublisherBasicPublisher (and BasicSubscriber / BasicListener)
QoS typePublisherQos.hQosProfile.h
middlewareIPublisherMiddleware implssame, plus ActiveMiddleware.{h,cpp}
map publisherCarlaMapPublisherremoved — do not model a new publisher on it
DVS cameraCarlaDVSPublisherCarlaDVSCameraPublisher
Autoware—AutowareGNSSPublisher, AutowareVehicleStatusPublisher, AutowareControlSubscriber, AutowareSteeringCompensation.h

0.10.0 also factors the per-sensor maths out of the publishers into reusable headers you should use rather than re-derive: CameraIntrinsics, ImuMath, DvsEventEncoding, OpticalFlowEncoding, PointCloudFieldsLayout, RadarPolarToCartesian, TransformQuaternion, and AckermannControlConversion on the subscriber side. A new listeners/ directory holds BasicListener.

The registration point, the ProcessDataFrom* entry points and the UE plugin call sites work the same way on both.

Instructions

Progress:
- [ ] Step 1: Check prerequisites (bash scripts/check_env.sh), clear FAILs
- [ ] Step 2: Confirm the message type exists in types/msg (else add-ros-message-type)
- [ ] Step 3: Write publishers/Carla<X>Publisher.h (+ .cpp for the Write logic)
- [ ] Step 4: Register it — GetOrCreateSensor case, or RegisterVehicle/Actor
- [ ] Step 5: Add the ProcessDataFrom<X> entry point in ROS2.h/.cpp
- [ ] Step 6: Call it from the UE4 side, inside `#if defined(WITH_ROS2)`
- [ ] Step 7: bash scripts/verify.sh, then rebuild the plugin (build-carla-ue4 ROS2=1)
- [ ] Step 8: Prove the topic — visualize-ros-rviz topics / hz

Step 3: the publisher

Copy the shape of the simplest existing one (CarlaGNSSPublisher): derive from BasePublisher, hold a PublisherImpl<Traits>, Init the topic in the constructor, implement Write(...) and Publish().

class CarlaFooPublisher : public BasePublisher {
  public:
    struct FooMsgTraits { using msg_type = msg::Foo; };   // the only type binding

    CarlaFooPublisher(std::string base_topic_name, std::string frame_id):
      BasePublisher(base_topic_name, frame_id),
      _impl(std::make_shared<PublisherImpl<FooMsgTraits>>()) {
        // Suffix decides the topic; NO suffix means "publish on the base name",
        // which is what IMU/GNSS/collision do. Pass PublisherQos::SensorData()
        // for high-rate streams so a slow subscriber cannot stall the sim.
        if (!_impl->Init(GetBaseTopicName() + "/foo", PublisherQos::SensorData())) {
          log_warning("CarlaFooPublisher: Init failed for topic: ", GetBaseTopicName(), "/foo");
        }
    }
    bool Publish() { return _impl->Publish(); }
    bool Write(int32_t seconds, uint32_t nanoseconds, /* payload */);
  private:
    std::shared_ptr<PublisherImpl<FooMsgTraits>> _impl;
};

Header in publishers/, Write body in the matching .cpp if it is more than a few lines. No CMake edit is needed — LibCarla/cmake/ros2/CMakeLists.txt globs publishers/*.cpp, subscribers/*.cpp, types/*.cpp, middleware/*/*.cpp. A brand-new subdirectory does need a glob entry.

Init failure is a warning, not an error: a typo'd topic leaves a live publisher object that publishes nowhere. Watch for that line in the server log.

Steps 4-6: wire it up

ForRegister inFeed from
a sensora case ESensors::<X>: in ROS2::GetOrCreateSensorProcessDataFrom<X> called in that sensor's UE4 class
a vehicle/actor streamROS2::RegisterVehicle / RegisterActorthe actor's tick or an RPC path
a subscriber (ROS drives CARLA)RegisterVehicle's subscriber listProcessMessages(callback) → ActorROS2Handler

The dispatch function is the seam: it takes the raw CARLA data, casts the base publisher to the concrete type, Writes, Publishes, and (for sensors) also updates the TF publisher. Copy ProcessDataFromGNSS — it is the shortest complete example.

On the UE4 side the call must sit inside #if defined(WITH_ROS2) and be guarded by ROS2->IsEnabled(); the transform passed is relative to the attach parent when there is one:

#if defined(WITH_ROS2)
auto ROS2 = carla::ros2::ROS2::GetInstance();
if (ROS2->IsEnabled()) {
  AActor* ParentActor = GetAttachParentActor();
  auto Transform = ParentActor ? GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform())
                               : GetActorTransform();
  ROS2->ProcessDataFromFoo(Stream.GetSensorType(), Transform, Data, this);
}
#endif

Steps 7-8: verify

bash scripts/verify.sh                          # LibCarla + its tests, with --ros2
ROS2=1 bash ../../ue4/build-carla-ue4/scripts/06_build_editor.sh   # the plugin call site
# then, against a running ROS 2 server:
bash ../visualize-ros-rviz/scripts/ros_view.sh topics
bash ../visualize-ros-rviz/scripts/ros_view.sh hz /carla/<actor>/foo

verify.sh proves it compiles and the middleware layer still passes its tests. Only hz/echo proves the topic. A publisher can build, register, and still be silent: the most common reasons are the sensor not being enabled for ROS ([[create-sensor]] --ros), a UE4 call site that never runs, and a sensor whose Tick is skipped because nothing listens.

Sensors with no publisher yet

ROS2::GetOrCreateSensor deliberately returns nullptr for these, so they are the natural targets — and each already has a ProcessDataFrom* or needs one:

SensorNote
other.lane_invasionCarlaLineInvasion message type already exists
other.obstacleProcessDataFromObstacleDetection exists in ROS2.h
other.rssno message type yet
world observerhigh volume; think before publishing

Adding a middleware (RMW)

Same layer, one level down: implement IPublisherMiddleware / ISubscriberMiddleware, add the include + case in MiddlewareFactory, a Middleware enum value and its MiddlewareFromString mapping, and a CARLA_ROS2_MIDDLEWARE_<NAME> compile definition in LibCarla/cmake/ros2/CMakeLists.txt (all three are defined at once, so IsMiddlewareAvailable answers correctly at run time). Extend test_ros2_middleware.cpp. Per-RMW quirks — Zenoh's router and wire format, CycloneDDS's sertype, FastDDS's shared participant — are in references/layers.md.

Examples

Example 1: publish the obstacle sensor

User says: "make the obstacle detection sensor publish to ROS"

CarlaLineInvasion/a suitable type exists → write CarlaObstaclePublisher → replace the nullptr case for ESensors::ObstacleDetectionSensor → fill in ProcessDataFromObstacleDetection (declared already) → the call site in ObstacleDetectionSensor.cpp already exists → verify → hz.

Example 2: let ROS steer via a new command topic

User says: "add a ROS topic to set the ego's target speed"

Type first ([[add-ros-message-type]]) → subscriber modelled on AckermannControlSubscriber → register it in RegisterVehicle → extend ROS2CallbackData and ActorROS2Handler to apply it → verify → ros2 topic pub.

Example 3: a fourth RMW

User says: "add support for another DDS implementation"

Follow "Adding a middleware": interface pair, factory case, enum + string, CMake definition, test. No publisher changes at all — that is the point of the layer.

Troubleshooting

Problem: it all compiles but the topic never appears Cause: usually the call site, not the publisher — the #if defined(WITH_ROS2) block is missing, unreachable, or the plugin was rebuilt without ROS2=1. Solution: confirm Ros2 ON in Config/OptionalModules.ini, rebuild step 06 with ROS2=1, then check the sensor is enable_for_ros-ed.

Problem: PublisherImpl: Failed to create middleware publisher Cause: MiddlewareFactory has no case for the active middleware, or the RMW is not compiled in. Solution: check IsMiddlewareAvailable and the CARLA_ROS2_MIDDLEWARE_* definitions in LibCarla/cmake/ros2/CMakeLists.txt.

Problem: Init failed for topic: … in the server log, everything else fine Cause: an invalid topic name (empty ros_name, double slash) — Init only warns. Solution: fix the name; remember unnamed actors become actor<id>.

Problem: subscriber never receives, publisher works Cause: QoS mismatch (the peer is reliable+transient_local against a volatile publisher), or the topic string differs by a suffix. Solution: visualize-ros-rviz info <topic> shows endpoint counts and QoS on both sides.

Problem: a new .cpp is not compiled Cause: it is in a new subdirectory; the CMake glob lists directories explicitly. Solution: add the glob line in LibCarla/cmake/ros2/CMakeLists.txt.

Outputs

Edited sources in the checkout, a green check.LibCarla, and — after the plugin rebuild — a new topic visible from ROS 2.

Layer-by-layer detail (publisher/subscriber contracts, QoS profiles, dispatch, the middleware interfaces and their quirks) in references/layers.md.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Add a message type to CARLA's native ROS 2 interface. Create its C++ data structure, serialization code for transmission, type identity hash, registration, and tests, with Docker-based hash calculation and build checks.

  • Adding a standard ROS 2 message type missing from CARLA
  • Defining a custom carla_msgs message
  • Investigating type-hash warnings
carla-simulator/carla14.5KUpdated Oct 18, 2026

Summarize ScenarioRunner results to see which scenarios passed and which checks failed. Compare runs before and after changes, or analyze recorded driving to produce measurements and plots of vehicle distance and deviation from the lane center.

  • Checking scenario pass and fail results
  • Comparing results before and after controller changes
  • Plotting vehicle distances from a recorded run
carla-simulator/carla14.5KUpdated Oct 18, 2026

audit-carla-docs

FreeSummary

Checks a local CARLA checkout for missing API documentation, outdated references, broken links, and pages absent from navigation. Produces a grouped Markdown report without building the project or running the simulator.

  • Reviewing documentation before a release
  • Finding missing or outdated API references
  • Checking broken links and navigation gaps
carla-simulator/carla14.5KUpdated Oct 18, 2026

bounding-boxes

FreeSummary

Read and display CARLA object bounding boxes, then project them onto a camera image as 2D rectangles. Export an annotated PNG and box coordinates in JSON for object detection annotation work.

  • Adding vehicle boxes to a camera image
  • Exporting box coordinates for detection annotations
  • Checking vehicle dimensions
carla-simulator/carla14.5KUpdated Oct 18, 2026

build-carla-ue4

FreeSummary

Builds CARLA's ue4-dev branch on Linux, producing the Unreal Engine 4.26 editor, server modules, and an installed Python client package. Fetches required content, optionally compiles native ROS 2 support, and verifies the build against a source-built server.

  • Building CARLA ue4-dev from source
  • Compiling CARLA with native ROS 2 support
  • Building the Python client for an existing environment
carla-simulator/carla14.5KUpdated Oct 18, 2026

build-carla-ue58

FreeSummary

Build CARLA for Unreal Engine 5.8 using CMake, the tool that configures its build process. The skill guides engine setup, optional ROS 2 support, Python API rebuilding, editor builds, and checks that the expected files were actually produced.

  • Building CARLA for Unreal Engine 5.8
  • Building and verifying native ROS 2 support
  • Rebuilding the Python API after client changes
carla-simulator/carla14.5KUpdated Oct 18, 2026

See all skills by carla-simulator

Report a problem with this skill