CARLA
Loading...
Searching...
No Matches
CarlaEgoVehicleControlSubscriber.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8
9#include "carla/Logging.h"
13
14namespace carla {
15namespace ros2 {
16
20
22 void *vehicle, std::string base_topic_name, std::string frame_id)
23 : BaseSubscriber(vehicle, std::move(base_topic_name), std::move(frame_id)),
24 _impl(std::make_shared<SubscriberImpl<CarlaEgoVehicleControlTraits>>()) {
25 if (!_impl->Init(this->GetBaseTopicName() + "/vehicle_control_cmd")) {
26 log_error("CarlaEgoVehicleControlSubscriber failed to initialize on base topic",
27 this->GetBaseTopicName());
28 }
29}
30
32
34 auto message = _impl->GetMessage();
35
36 VehicleControl control;
37 control.throttle = message.throttle;
38 control.steer = message.steer;
39 control.brake = message.brake;
40 control.hand_brake = message.hand_brake;
41 control.reverse = message.reverse;
42 control.gear = message.gear;
43 control.manual_gear_shift = message.manual_gear_shift;
44 return control;
45}
46
48 if (_impl->HasNewMessage()) {
49 auto control = this->GetMessage();
50 callback(this->GetActor(), control);
51 }
52}
53
54} // namespace ros2
55} // namespace carla
const std::string & GetBaseTopicName() const noexcept
void * GetActor() const noexcept
CarlaEgoVehicleControlSubscriber(void *vehicle, std::string base_topic_name, std::string frame_id)
std::shared_ptr< SubscriberImpl< CarlaEgoVehicleControlTraits > > _impl
std::function< void(void *actor, ROS2CallbackData data)> ActorCallback
std::variant< VehicleControl, AckermannControl, VehicleAccelerationControl > ROS2CallbackData
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
Definition Logging.h:110