Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
j2735_types.cpp
Go to the documentation of this file.
1// Copyright 2023 Leidos
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
18{
19auto DDateTime::from_msg(const j2735_v2x_msgs::msg::DDateTime & msg) -> DDateTime
20{
21 DDateTime d_date_time;
22
23 if (msg.presence_vector & msg.YEAR) {
24 d_date_time.year = units::time::year_t{static_cast<double>(msg.year.year)};
25 }
26
27 if (msg.presence_vector & msg.MONTH) {
28 d_date_time.month = Month{msg.month.month};
29 }
30
31 if (msg.presence_vector & msg.DAY) {
32 d_date_time.day = units::time::day_t{static_cast<double>(msg.day.day)};
33 }
34
35 if (msg.presence_vector & msg.HOUR) {
36 d_date_time.hour = units::time::hour_t{static_cast<double>(msg.hour.hour)};
37 }
38
39 if (msg.presence_vector & msg.MINUTE) {
40 d_date_time.minute = units::time::minute_t{static_cast<double>(msg.minute.minute)};
41 }
42
43 if (msg.presence_vector & msg.SECOND) {
44 d_date_time.second = units::time::millisecond_t{static_cast<double>(msg.second.millisecond)};
45 }
46
47 if (msg.presence_vector & msg.OFFSET) {
48 d_date_time.time_zone_offset =
49 units::time::minute_t{static_cast<double>(msg.offset.offset_minute)};
50 }
51
52 return d_date_time;
53}
54
55auto AccelerationSet4Way::from_msg(const j2735_v2x_msgs::msg::AccelerationSet4Way & msg)
57{
58 return {
59 units::acceleration::centi_meters_per_second_squared_t{static_cast<double>(msg.longitudinal)},
60 units::acceleration::centi_meters_per_second_squared_t{static_cast<double>(msg.lateral)},
61 units::acceleration::two_centi_standard_gravities_t{static_cast<double>(msg.vert)},
62 units::angular_velocity::centi_degrees_per_second_t{static_cast<double>(msg.yaw_rate)}};
63}
64
65auto AccelerationSet4Way::from_msg(const carma_v2x_msgs::msg::AccelerationSet4Way & msg)
67{
68 return {
69 units::acceleration::meters_per_second_squared_t{static_cast<double>(msg.longitudinal)},
70 units::acceleration::meters_per_second_squared_t{static_cast<double>(msg.lateral)},
71 units::acceleration::meters_per_second_squared_t{static_cast<double>(msg.vert)},
72 units::angular_velocity::degrees_per_second_t{static_cast<double>(msg.yaw_rate)}};
73}
74
75auto Position3D::from_msg(const j2735_v2x_msgs::msg::Position3D & msg) -> Position3D
76{
77 Position3D position{
78 units::angle::deci_micro_degrees_t{static_cast<double>(msg.latitude)},
79 units::angle::deci_micro_degrees_t{static_cast<double>(msg.longitude)}, std::nullopt};
80
81 if (msg.elevation_exists) {
82 position.elevation = units::length::deca_centimeters_t{static_cast<double>(msg.elevation)};
83 }
84
85 return position;
86}
87
88auto Position3D::from_msg(const carma_v2x_msgs::msg::Position3D & msg) -> Position3D
89{
90 Position3D position{
91 units::angle::degree_t{static_cast<double>(msg.latitude)},
92 units::angle::degree_t{static_cast<double>(msg.longitude)}, std::nullopt};
93
94 if (msg.elevation_exists) {
95 position.elevation = units::length::meter_t{static_cast<double>(msg.elevation)};
96 }
97
98 return position;
99}
100
101auto Heading::from_msg(const j2735_v2x_msgs::msg::Heading & heading) -> Heading
102{
103 return {units::angle::eighth_deci_degrees_t{static_cast<double>(heading.heading)}};
104}
105
106auto Heading::from_msg(const carma_v2x_msgs::msg::Heading & heading) -> Heading
107{
108 return {units::angle::degree_t{static_cast<double>(heading.heading)}};
109}
110
111auto Speed::from_msg(const j2735_v2x_msgs::msg::Speed & speed) -> Speed
112{
113 return {units::velocity::two_centi_meters_per_second_t{static_cast<double>(speed.speed)}};
114}
115
116auto Speed::from_msg(const carma_v2x_msgs::msg::Speed & speed) -> Speed
117{
118 return {units::velocity::meters_per_second_t{static_cast<double>(speed.speed)}};
119}
120
121} // namespace carma_cooperative_perception
static auto from_msg(const j2735_v2x_msgs::msg::AccelerationSet4Way &msg) -> AccelerationSet4Way
Definition: j2735_types.cpp:55
std::optional< units::time::hour_t > hour
Definition: j2735_types.hpp:41
std::optional< units::time::day_t > day
Definition: j2735_types.hpp:40
std::optional< units::time::minute_t > minute
Definition: j2735_types.hpp:42
static auto from_msg(const j2735_v2x_msgs::msg::DDateTime &msg) -> DDateTime
Definition: j2735_types.cpp:19
std::optional< units::time::year_t > year
Definition: j2735_types.hpp:38
std::optional< units::time::second_t > second
Definition: j2735_types.hpp:43
std::optional< units::time::minute_t > time_zone_offset
Definition: j2735_types.hpp:44
static auto from_msg(const j2735_v2x_msgs::msg::Heading &heading) -> Heading
static auto from_msg(const j2735_v2x_msgs::msg::Position3D &msg) -> Position3D
Definition: j2735_types.cpp:75
std::optional< units::length::deca_centimeters_t > elevation
Definition: j2735_types.hpp:67
static auto from_msg(const j2735_v2x_msgs::msg::Speed &speed) -> Speed