CARLA
 
载入中...
搜索中...
未找到
CarlaSubscriberListener.cpp
浏览该文件的文档.
1#define _GLIBCXX_USE_CXX11_ABI 0
2
4#include <iostream>
5
6#include <fastdds/dds/subscriber/DataReader.hpp>
7#include <fastdds/dds/subscriber/DataReaderListener.hpp>
8#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
9#include <fastdds/dds/subscriber/SampleInfo.hpp>
13
14namespace carla {
15namespace ros2 {
16
17 namespace efd = eprosima::fastdds::dds;
18 using erc = eprosima::fastrtps::types::ReturnCode_t;
19
21 public:
23 efd::DataReader* reader,
24 const efd::SubscriptionMatchedStatus& info) override;
25 void on_data_available(efd::DataReader* reader) override;
26
27 int _matched {0};
28 bool _first_connected {false};
31 };
32
33 void CarlaSubscriberListenerImpl::on_subscription_matched(efd::DataReader* reader, const efd::SubscriptionMatchedStatus& info)
34 {
35 if (info.current_count_change == 1) {
36 _matched = info.total_count;
37 _first_connected = true;
38 } else if (info.current_count_change == -1) {
39 _matched = info.total_count;
40 if (_matched == 0) {
42 }
43 } else {
44 std::cerr << info.current_count_change
45 << " is not a valid value for PublicationMatchedStatus current count change" << std::endl;
46 }
47 }
48
50 {
51 efd::SampleInfo info;
52 eprosima::fastrtps::types::ReturnCode_t rcode = reader->take_next_sample(&_message, &info);
53 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
54 VehicleControl control;
55 control.throttle = _message.throttle();
56 control.steer = _message.steer();
57 control.brake = _message.brake();
58 control.hand_brake = _message.hand_brake();
59 control.reverse = _message.reverse();
60 control.gear = _message.gear();
62 _owner->ForwardMessage(control);
63 }
64 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
65 std::cerr << "RETCODE_ERROR" << std::endl;
66 }
67 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
68 std::cerr << "RETCODE_UNSUPPORTED" << std::endl;
69 }
70 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
71 std::cerr << "RETCODE_BAD_PARAMETER" << std::endl;
72 }
73 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
74 std::cerr << "RETCODE_PRECONDITION_NOT_MET" << std::endl;
75 }
76 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
77 std::cerr << "RETCODE_OUT_OF_RESOURCES" << std::endl;
78 }
79 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
80 std::cerr << "RETCODE_NOT_ENABLED" << std::endl;
81 }
82 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
83 std::cerr << "RETCODE_IMMUTABLE_POLICY" << std::endl;
84 }
85 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
86 std::cerr << "RETCODE_INCONSISTENT_POLICY" << std::endl;
87 }
88 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
89 std::cerr << "RETCODE_ALREADY_DELETED" << std::endl;
90 }
91 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
92 std::cerr << "RETCODE_TIMEOUT" << std::endl;
93 }
94 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
95 std::cerr << "RETCODE_NO_DATA" << std::endl;
96 }
97 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
98 std::cerr << "RETCODE_ILLEGAL_OPERATION" << std::endl;
99 }
100 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
101 std::cerr << "RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
102 }
103 }
104
108
113
115
116}}
CarlaEgoVehicleControlSubscriber * _owner
void on_subscription_matched(efd::DataReader *reader, const efd::SubscriptionMatchedStatus &info) override
void on_data_available(efd::DataReader *reader) override
carla_msgs::msg::CarlaEgoVehicleControl _message
std::unique_ptr< CarlaSubscriberListenerImpl > _impl
void SetOwner(CarlaEgoVehicleControlSubscriber *owner)
CarlaSubscriberListener(CarlaEgoVehicleControlSubscriber *owner)
This class represents the structure CarlaEgoVehicleControl defined by the user in the IDL file.
eProsima_user_DllExport void reverse(bool _reverse)
This function sets a value in member reverse
eProsima_user_DllExport void hand_brake(bool _hand_brake)
This function sets a value in member hand_brake
eProsima_user_DllExport void brake(float _brake)
This function sets a value in member brake
eProsima_user_DllExport void throttle(float _throttle)
This function sets a value in member throttle
eProsima_user_DllExport void gear(int32_t _gear)
This function sets a value in member gear
eProsima_user_DllExport void manual_gear_shift(bool _manual_gear_shift)
This function sets a value in member manual_gear_shift
eProsima_user_DllExport void steer(float _steer)
This function sets a value in member steer
eprosima::fastrtps::types::ReturnCode_t erc
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133