scenario_simulator_v2 C++ API
helper.hpp
Go to the documentation of this file.
1 // Copyright 2024 TIER IV, Inc. All rights reserved.
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 
15 #ifndef TRAFFIC_SIMULATOR__TEST__TRAFFIC_LIGHTS__HELPER_HPP_
16 #define TRAFFIC_SIMULATOR__TEST__TRAFFIC_LIGHTS__HELPER_HPP_
17 
18 #include <rclcpp/time.hpp>
19 #include <std_msgs/msg/header.hpp>
20 
22 // clang-format off
23 inline auto stateFromColor(const std::string & color) -> std::string { return color + " solidOn circle"; }
24 inline auto stateFromStatus(const std::string & status) -> std::string { return "green " + status + " circle"; }
25 inline auto stateFromShape(const std::string & shape) -> std::string { return "green solidOn " + shape; }
26 // clang-format on
27 
29 inline auto getTime(const builtin_interfaces::msg::Time & time) -> int
30 {
31  static constexpr int nanosecond_multiplier = static_cast<int>(1e+9);
32  return static_cast<int>(time.sec) * nanosecond_multiplier + static_cast<int>(time.nanosec);
33 }
34 
36 inline auto getTime(const std_msgs::msg::Header & header) -> int { return getTime(header.stamp); }
37 
39 inline auto getTime(const rclcpp::Time & time) -> int
40 {
41  return static_cast<int>(time.nanoseconds());
42 }
43 
44 #endif // TRAFFIC_SIMULATOR__TEST__TRAFFIC_LIGHTS__HELPER_HPP_
std::string string
Definition: junit5.hpp:26
auto stateFromShape(const std::string &shape) -> std::string
Definition: helper.hpp:25
auto getTime(const builtin_interfaces::msg::Time &time) -> int
Returns time in nanoseconds.
Definition: helper.hpp:29
auto stateFromStatus(const std::string &status) -> std::string
Definition: helper.hpp:24
auto stateFromColor(const std::string &color) -> std::string
Helper functions.
Definition: helper.hpp:23