Skip to content

Commit

Permalink
feat(radar_tracks_noise_filter): add unit test (autowarefoundation#6113)
Browse files Browse the repository at this point in the history
* feat/test_radar_tracks_noise_filter

Signed-off-by: N-Eiki <[email protected]>

* change file name

Signed-off-by: N-Eiki <[email protected]>

---------

Signed-off-by: N-Eiki <[email protected]>
Co-authored-by: Satoshi Tanaka <[email protected]>
  • Loading branch information
2 people authored and kyoichi-sugahara committed Jan 29, 2024
1 parent a1adbea commit d7ad651
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sensing/radar_tracks_noise_filter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ rclcpp_components_register_node(radar_tracks_noise_filter_node_component

# Tests
if(BUILD_TESTING)
find_package(ament_cmake_ros REQUIRED)
list(APPEND AMENT_LINT_AUTO_EXCLUDE ament_cmake_uncrustify)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
file(GLOB_RECURSE test_files test/**/*.cpp)
ament_add_ros_isolated_gtest(radar_tracks_noise_filter ${test_files})

target_link_libraries(radar_tracks_noise_filter
radar_tracks_noise_filter_node_component
)
endif()

# Package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RadarTrackCrossingNoiseFilterNode : public rclcpp::Node
// Parameter
NodeParam node_param_{};

public:
// Core
bool isNoise(const RadarTrack & radar_track);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2023 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "radar_tracks_noise_filter/radar_tracks_noise_filter_node.hpp"

#include <radar_msgs/msg/radar_scan.hpp>

#include <gtest/gtest.h>

std::shared_ptr<radar_tracks_noise_filter::RadarTrackCrossingNoiseFilterNode> get_node(
float velocity_y_threshold)
{
rclcpp::NodeOptions node_options;
node_options.parameter_overrides({
{"node_params.is_amplitude_filter", true},
{"velocity_y_threshold", velocity_y_threshold},
});

auto node =
std::make_shared<radar_tracks_noise_filter::RadarTrackCrossingNoiseFilterNode>(node_options);
return node;
}

radar_msgs::msg::RadarTrack getRadarTrack(float velocity_x, float velocity_y)
{
radar_msgs::msg::RadarTrack radar_track;
geometry_msgs::msg::Vector3 vector_msg;
vector_msg.x = velocity_x;
vector_msg.y = velocity_y;
vector_msg.z = 0.0;
radar_track.velocity = vector_msg;
return radar_track;
}

TEST(RadarTracksNoiseFilter, isNoise)
{
using radar_msgs::msg::RadarTrack;
using radar_tracks_noise_filter::RadarTrackCrossingNoiseFilterNode;
rclcpp::init(0, nullptr);
{
float velocity_node_threshold = 0.0;
float y_velocity = 0.0;
float x_velocity = 10.0;
std::shared_ptr<RadarTrackCrossingNoiseFilterNode> node = get_node(velocity_node_threshold);
RadarTrack radar_track = getRadarTrack(x_velocity, y_velocity);
EXPECT_TRUE(node->isNoise(radar_track));
}

{
float velocity_node_threshold = -1.0;
float y_velocity = 3.0;
float x_velocity = 10.0;
std::shared_ptr<RadarTrackCrossingNoiseFilterNode> node = get_node(velocity_node_threshold);
RadarTrack radar_track = getRadarTrack(x_velocity, y_velocity);
EXPECT_TRUE(node->isNoise(radar_track));
}

{
float velocity_node_threshold = -1.0;
float y_velocity = 3.0;
float x_velocity = 100.0;
std::shared_ptr<RadarTrackCrossingNoiseFilterNode> node = get_node(velocity_node_threshold);
RadarTrack radar_track = getRadarTrack(x_velocity, y_velocity);
EXPECT_TRUE(node->isNoise(radar_track));
}

{
float velocity_node_threshold = 3.0;
float y_velocity = 1.0;
float x_velocity = 10.0;
std::shared_ptr<RadarTrackCrossingNoiseFilterNode> node = get_node(velocity_node_threshold);
RadarTrack radar_track = getRadarTrack(x_velocity, y_velocity);
EXPECT_FALSE(node->isNoise(radar_track));
}

{
float velocity_node_threshold = 3.0;
float y_velocity = 1.0;
float x_velocity = -10.0;
std::shared_ptr<RadarTrackCrossingNoiseFilterNode> node = get_node(velocity_node_threshold);
RadarTrack radar_track = getRadarTrack(x_velocity, y_velocity);
EXPECT_FALSE(node->isNoise(radar_track));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 TierIV
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <rclcpp/rclcpp.hpp>

#include <gtest/gtest.h>

int main(int argc, char * argv[])
{
testing::InitGoogleTest(&argc, argv);
rclcpp::init(argc, argv);
bool result = RUN_ALL_TESTS();
rclcpp::shutdown();
return result;
}

0 comments on commit d7ad651

Please sign in to comment.