Skip to content

Commit cb2c240

Browse files
refactor(motion_utils): supress log message with rclcpp logging
Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent 86804e1 commit cb2c240

File tree

3 files changed

+89
-58
lines changed

3 files changed

+89
-58
lines changed

common/motion_utils/include/motion_utils/resample/resample_utils.hpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
#include <motion_utils/trajectory/trajectory.hpp>
2222
#include <tier4_autoware_utils/geometry/geometry.hpp>
2323

24+
#include <string>
2425
#include <vector>
2526

2627
namespace resample_utils
2728
{
2829
constexpr double close_s_threshold = 1e-6;
2930

30-
#define log_error(message) std::cerr << "\033[31m " << message << " \033[0m" << std::endl;
31+
static inline rclcpp::Logger get_logger()
32+
{
33+
constexpr const char * logger{"motion_utils.resample_utils"};
34+
return rclcpp::get_logger(logger);
35+
}
3136

3237
template <class T>
3338
bool validate_size(const T & points)
@@ -62,27 +67,27 @@ bool validate_arguments(const T & input_points, const std::vector<double> & resa
6267
{
6368
// Check size of the arguments
6469
if (!validate_size(input_points)) {
65-
log_error("[resample_utils] invalid argument: The number of input points is less than 2");
70+
RCLCPP_DEBUG(get_logger(), "invalid argument: The number of input points is less than 2");
6671
tier4_autoware_utils::print_backtrace();
6772
return false;
6873
}
6974
if (!validate_size(resampling_intervals)) {
70-
log_error(
71-
"[resample_utils] invalid argument: The number of resampling intervals is less than 2");
75+
RCLCPP_DEBUG(
76+
get_logger(), "invalid argument: The number of resampling intervals is less than 2");
7277
tier4_autoware_utils::print_backtrace();
7378
return false;
7479
}
7580

7681
// Check resampling range
7782
if (!validate_resampling_range(input_points, resampling_intervals)) {
78-
log_error("[resample_utils] invalid argument: resampling interval is longer than input points");
83+
RCLCPP_DEBUG(get_logger(), "invalid argument: resampling interval is longer than input points");
7984
tier4_autoware_utils::print_backtrace();
8085
return false;
8186
}
8287

8388
// Check duplication
8489
if (!validate_points_duplication(input_points)) {
85-
log_error("[resample_utils] invalid argument: input points has some duplicated points");
90+
RCLCPP_DEBUG(get_logger(), "invalid argument: input points has some duplicated points");
8691
tier4_autoware_utils::print_backtrace();
8792
return false;
8893
}
@@ -95,23 +100,23 @@ bool validate_arguments(const T & input_points, const double resampling_interval
95100
{
96101
// Check size of the arguments
97102
if (!validate_size(input_points)) {
98-
log_error("[resample_utils] invalid argument: The number of input points is less than 2");
103+
RCLCPP_DEBUG(get_logger(), "invalid argument: The number of input points is less than 2");
99104
tier4_autoware_utils::print_backtrace();
100105
return false;
101106
}
102107

103108
// check resampling interval
104109
if (resampling_interval < motion_utils::overlap_threshold) {
105-
log_error(
106-
"[resample_utils] invalid argument: resampling interval is less than " +
107-
std::to_string(motion_utils::overlap_threshold));
110+
RCLCPP_DEBUG(
111+
get_logger(), "invalid argument: resampling interval is less than %f",
112+
motion_utils::overlap_threshold);
108113
tier4_autoware_utils::print_backtrace();
109114
return false;
110115
}
111116

112117
// Check duplication
113118
if (!validate_points_duplication(input_points)) {
114-
log_error("[resample_utils] invalid argument: input points has some duplicated points");
119+
RCLCPP_DEBUG(get_logger(), "invalid argument: input points has some duplicated points");
115120
tier4_autoware_utils::print_backtrace();
116121
return false;
117122
}

0 commit comments

Comments
 (0)