Skip to content

Commit 539461f

Browse files
N-Eikipre-commit-ci[bot]scepter914
authored andcommitted
feat(radar_crossing_noise_filter): add unit test (#6257)
* update node Signed-off-by: N-Eiki <naganagaeichan@gmail.com> * add test Signed-off-by: N-Eiki <naganagaeichan@gmail.com> * style(pre-commit): autofix * update year Signed-off-by: N-Eiki <naganagaeichan@gmail.com> * use tier4_autoware_utils Signed-off-by: N-Eiki <naganagaeichan@gmail.com> * style(pre-commit): autofix --------- Signed-off-by: N-Eiki <naganagaeichan@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Satoshi Tanaka <16330533+scepter914@users.noreply.github.com> Signed-off-by: Kotaro Yoshimoto <pythagora.yoshimoto@gmail.com>
1 parent 3773fef commit 539461f

File tree

4 files changed

+210
-0
lines changed

4 files changed

+210
-0
lines changed

perception/radar_crossing_objects_noise_filter/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ rclcpp_components_register_node(radar_crossing_objects_noise_filter_node_compone
1717

1818
# Tests
1919
if(BUILD_TESTING)
20+
find_package(ament_cmake_ros REQUIRED)
2021
list(APPEND AMENT_LINT_AUTO_EXCLUDE ament_cmake_uncrustify)
2122
find_package(ament_lint_auto REQUIRED)
2223
ament_lint_auto_find_test_dependencies()
24+
25+
file(GLOB_RECURSE test_files test/**/*.cpp)
26+
ament_add_ros_isolated_gtest(radar_crossing_objects_noise_filter ${test_files})
27+
28+
target_link_libraries(radar_crossing_objects_noise_filter
29+
radar_crossing_objects_noise_filter_node_component
30+
)
2331
endif()
2432

2533
# Package

perception/radar_crossing_objects_noise_filter/include/radar_crossing_objects_noise_filter/radar_crossing_objects_noise_filter_node.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class RadarCrossingObjectsNoiseFilterNode : public rclcpp::Node
5858
// Parameter
5959
NodeParam node_param_{};
6060

61+
public:
6162
// Core
6263
bool isNoise(const DetectedObject & object);
6364
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 TierIV
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+
#include <rclcpp/rclcpp.hpp>
16+
17+
#include <gtest/gtest.h>
18+
19+
int main(int argc, char * argv[])
20+
{
21+
testing::InitGoogleTest(&argc, argv);
22+
rclcpp::init(argc, argv);
23+
bool result = RUN_ALL_TESTS();
24+
rclcpp::shutdown();
25+
return result;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
// Copyright 2024 Tier IV, Inc.
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+
#include "radar_crossing_objects_noise_filter/radar_crossing_objects_noise_filter_node.hpp"
16+
#include "tier4_autoware_utils/geometry/geometry.hpp"
17+
#include "tier4_autoware_utils/math/unit_conversion.hpp"
18+
19+
#include <geometry_msgs/msg/point32.hpp>
20+
21+
#include <gtest/gtest.h>
22+
23+
std::shared_ptr<radar_crossing_objects_noise_filter::RadarCrossingObjectsNoiseFilterNode> get_node(
24+
double angle_threshold, double velocity_threshold)
25+
{
26+
rclcpp::NodeOptions node_options;
27+
28+
node_options.parameter_overrides(
29+
{{"angle_threshold", angle_threshold}, {"velocity_threshold", velocity_threshold}});
30+
auto node =
31+
std::make_shared<radar_crossing_objects_noise_filter::RadarCrossingObjectsNoiseFilterNode>(
32+
node_options);
33+
return node;
34+
}
35+
36+
autoware_auto_perception_msgs::msg::DetectedObject get_object(
37+
geometry_msgs::msg::Vector3 velocity, geometry_msgs::msg::Point position,
38+
geometry_msgs::msg::Quaternion orientation)
39+
{
40+
autoware_auto_perception_msgs::msg::DetectedObject object;
41+
object.kinematics.twist_with_covariance.twist.linear = velocity;
42+
object.kinematics.pose_with_covariance.pose.position = position;
43+
object.kinematics.pose_with_covariance.pose.orientation = orientation;
44+
return object;
45+
}
46+
47+
TEST(RadarCrossingObjectsFilter, IsNoise)
48+
{
49+
rclcpp::init(0, nullptr);
50+
{
51+
auto velocity = tier4_autoware_utils::createVector3(40.0, 30.0, 0.0);
52+
auto position = tier4_autoware_utils::createPoint(1.0, 0.0, 0.0);
53+
auto orientation = tier4_autoware_utils::createQuaternion(1.0, 1.0, 1.0, 0.0);
54+
auto object = get_object(velocity, position, orientation);
55+
{
56+
double velocity_threshold = 40.0;
57+
double angle_threshold = 1.0472;
58+
auto node = get_node(angle_threshold, velocity_threshold);
59+
EXPECT_TRUE(node->isNoise(object));
60+
}
61+
{
62+
double velocity_threshold = 40.0;
63+
double angle_threshold = -1.0472;
64+
65+
auto node = get_node(angle_threshold, velocity_threshold);
66+
EXPECT_TRUE(node->isNoise(object));
67+
}
68+
{
69+
double velocity_threshold = -40.0;
70+
double angle_threshold = 1.0472;
71+
72+
auto node = get_node(angle_threshold, velocity_threshold);
73+
EXPECT_TRUE(node->isNoise(object));
74+
}
75+
{
76+
double velocity_threshold = -40.0;
77+
double angle_threshold = -1.0472;
78+
auto node = get_node(angle_threshold, velocity_threshold);
79+
EXPECT_TRUE(node->isNoise(object));
80+
}
81+
}
82+
83+
{
84+
auto velocity = tier4_autoware_utils::createVector3(40.0, 30.0, 0.0);
85+
auto position = tier4_autoware_utils::createPoint(1.0, 2.0, 0.0);
86+
auto orientation = tier4_autoware_utils::createQuaternion(1.0, 1.0, 1.0, 0.0);
87+
auto object = get_object(velocity, position, orientation);
88+
{
89+
double velocity_threshold = 40.0;
90+
double angle_threshold = 1.0472;
91+
auto node = get_node(angle_threshold, velocity_threshold);
92+
EXPECT_FALSE(node->isNoise(object));
93+
}
94+
{
95+
double velocity_threshold = 40.0;
96+
double angle_threshold = -1.0472;
97+
auto node = get_node(angle_threshold, velocity_threshold);
98+
EXPECT_FALSE(node->isNoise(object));
99+
}
100+
{
101+
double velocity_threshold = -40.0;
102+
double angle_threshold = 1.0472;
103+
auto node = get_node(angle_threshold, velocity_threshold);
104+
EXPECT_FALSE(node->isNoise(object));
105+
}
106+
{
107+
double velocity_threshold = -40.0;
108+
double angle_threshold = -1.0472;
109+
auto node = get_node(angle_threshold, velocity_threshold);
110+
EXPECT_FALSE(node->isNoise(object));
111+
}
112+
}
113+
114+
{
115+
auto velocity = tier4_autoware_utils::createVector3(24.0, 18.0, 0.0);
116+
auto position = tier4_autoware_utils::createPoint(1.0, 0.0, 0.0);
117+
auto orientation = tier4_autoware_utils::createQuaternion(1.0, 1.0, 1.0, 0.0);
118+
auto object = get_object(velocity, position, orientation);
119+
{
120+
double velocity_threshold = 40.0;
121+
double angle_threshold = 1.0472;
122+
auto node = get_node(angle_threshold, velocity_threshold);
123+
EXPECT_FALSE(node->isNoise(object));
124+
}
125+
{
126+
double velocity_threshold = 40.0;
127+
double angle_threshold = -1.0472;
128+
auto node = get_node(angle_threshold, velocity_threshold);
129+
EXPECT_FALSE(node->isNoise(object));
130+
}
131+
{
132+
double velocity_threshold = -40.0;
133+
double angle_threshold = 1.0472;
134+
auto node = get_node(angle_threshold, velocity_threshold);
135+
EXPECT_TRUE(node->isNoise(object));
136+
}
137+
{
138+
double velocity_threshold = -40.0;
139+
double angle_threshold = -1.0472;
140+
auto node = get_node(angle_threshold, velocity_threshold);
141+
EXPECT_TRUE(node->isNoise(object));
142+
}
143+
}
144+
145+
{
146+
auto velocity = tier4_autoware_utils::createVector3(24.0, 18.0, 0.0);
147+
auto position = tier4_autoware_utils::createPoint(1.0, 2.0, 0.0);
148+
auto orientation = tier4_autoware_utils::createQuaternion(1.0, 1.0, 1.0, 0.0);
149+
auto object = get_object(velocity, position, orientation);
150+
{
151+
double velocity_threshold = 40.0;
152+
double angle_threshold = 1.0472;
153+
auto node = get_node(angle_threshold, velocity_threshold);
154+
EXPECT_FALSE(node->isNoise(object));
155+
}
156+
{
157+
double velocity_threshold = 40.0;
158+
double angle_threshold = -1.0472;
159+
auto node = get_node(angle_threshold, velocity_threshold);
160+
EXPECT_FALSE(node->isNoise(object));
161+
}
162+
{
163+
double velocity_threshold = -40.0;
164+
double angle_threshold = 1.0472;
165+
auto node = get_node(angle_threshold, velocity_threshold);
166+
EXPECT_FALSE(node->isNoise(object));
167+
}
168+
{
169+
double velocity_threshold = -40.0;
170+
double angle_threshold = -1.0472;
171+
auto node = get_node(angle_threshold, velocity_threshold);
172+
EXPECT_FALSE(node->isNoise(object));
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)