CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
subscribers
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
7
#include "
carla/ros2/subscribers/CarlaEgoVehicleControlSubscriber.h
"
8
9
#include "
carla/Logging.h
"
10
#include "
carla/ros2/ROS2CallbackData.h
"
11
#include "
carla/ros2/subscribers/SubscriberImpl.h
"
12
#include "
carla/ros2/types/msg/CarlaEgoVehicleControl.h
"
13
14
namespace
carla
{
15
namespace
ros2
{
16
17
struct
CarlaEgoVehicleControlTraits
{
18
using
msg_type
=
msg::CarlaEgoVehicleControl
;
19
};
20
21
CarlaEgoVehicleControlSubscriber::CarlaEgoVehicleControlSubscriber
(
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
31
CarlaEgoVehicleControlSubscriber::~CarlaEgoVehicleControlSubscriber
() =
default
;
32
33
ROS2CallbackData
CarlaEgoVehicleControlSubscriber::GetMessage
() {
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
47
void
CarlaEgoVehicleControlSubscriber::ProcessMessages
(
ActorCallback
callback) {
48
if
(
_impl
->HasNewMessage()) {
49
auto
control = this->
GetMessage
();
50
callback(this->
GetActor
(), control);
51
}
52
}
53
54
}
// namespace ros2
55
}
// namespace carla
CarlaEgoVehicleControlSubscriber.h
CarlaEgoVehicleControl.h
Logging.h
ROS2CallbackData.h
SubscriberImpl.h
carla::ros2::BaseSubscriber::GetActor
void * GetActor() const noexcept
Definition
BaseSubscriber.h:43
carla::ros2::BaseSubscriber::BaseSubscriber
BaseSubscriber()=default
carla::ros2::CarlaEgoVehicleControlSubscriber::CarlaEgoVehicleControlSubscriber
CarlaEgoVehicleControlSubscriber(void *vehicle, std::string base_topic_name, std::string frame_id)
Definition
CarlaEgoVehicleControlSubscriber.cpp:21
carla::ros2::CarlaEgoVehicleControlSubscriber::ProcessMessages
void ProcessMessages(ActorCallback callback) override
Definition
CarlaEgoVehicleControlSubscriber.cpp:47
carla::ros2::CarlaEgoVehicleControlSubscriber::GetMessage
ROS2CallbackData GetMessage() override
Definition
CarlaEgoVehicleControlSubscriber.cpp:33
carla::ros2::CarlaEgoVehicleControlSubscriber::_impl
std::shared_ptr< SubscriberImpl< CarlaEgoVehicleControlTraits > > _impl
Definition
CarlaEgoVehicleControlSubscriber.h:36
carla::ros2::CarlaEgoVehicleControlSubscriber::~CarlaEgoVehicleControlSubscriber
~CarlaEgoVehicleControlSubscriber() override
carla::ros2::SubscriberImpl
Definition
SubscriberImpl.h:27
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::ROS2CallbackData
std::variant< VehicleControl, AckermannControl, VehicleAccelerationControl > ROS2CallbackData
Definition
ROS2CallbackData.h:51
carla::ros2::ActorCallback
std::function< void(void *actor, ROS2CallbackData data)> ActorCallback
Definition
ROS2CallbackData.h:55
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
carla::ros2::CarlaEgoVehicleControlTraits
Definition
CarlaEgoVehicleControlSubscriber.cpp:17
carla::ros2::CarlaEgoVehicleControlTraits::msg_type
msg::CarlaEgoVehicleControl msg_type
Definition
CarlaEgoVehicleControlSubscriber.cpp:18
carla::ros2::VehicleControl
Definition
ROS2CallbackData.h:17
carla::ros2::VehicleControl::reverse
bool reverse
Definition
ROS2CallbackData.h:22
carla::ros2::VehicleControl::manual_gear_shift
bool manual_gear_shift
Definition
ROS2CallbackData.h:24
carla::ros2::VehicleControl::hand_brake
bool hand_brake
Definition
ROS2CallbackData.h:21
carla::ros2::VehicleControl::throttle
float throttle
Definition
ROS2CallbackData.h:18
carla::ros2::VehicleControl::brake
float brake
Definition
ROS2CallbackData.h:20
carla::ros2::VehicleControl::steer
float steer
Definition
ROS2CallbackData.h:19
carla::ros2::VehicleControl::gear
int32_t gear
Definition
ROS2CallbackData.h:23
carla::ros2::msg::CarlaEgoVehicleControl
Definition
CarlaEgoVehicleControl.h:13
Generated by
1.18.0