Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nav2_controller/plugins/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ament_add_gtest(pctest progress_checker.cpp)
target_link_libraries(pctest simple_progress_checker)
ament_add_gtest(gctest goal_checker.cpp)
target_link_libraries(gctest simple_goal_checker stopped_goal_checker)
135 changes: 135 additions & 0 deletions nav2_controller/plugins/test/progress_checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2017, Locus Robotics
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <memory>
#include <string>

#include "gtest/gtest.h"
#include "nav2_controller/plugins/simple_progress_checker.hpp"
#include "nav_2d_utils/conversions.hpp"
#include "nav2_util/lifecycle_node.hpp"

using nav2_controller::SimpleProgressChecker;

class TestLifecycleNode : public nav2_util::LifecycleNode
{
public:
explicit TestLifecycleNode(const std::string & name)
: nav2_util::LifecycleNode(name)
{
}

nav2_util::CallbackReturn on_configure(const rclcpp_lifecycle::State &)
{
return nav2_util::CallbackReturn::SUCCESS;
}

nav2_util::CallbackReturn on_activate(const rclcpp_lifecycle::State &)
{
return nav2_util::CallbackReturn::SUCCESS;
}

nav2_util::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &)
{
return nav2_util::CallbackReturn::SUCCESS;
}

nav2_util::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &)
{
return nav2_util::CallbackReturn::SUCCESS;
}

nav2_util::CallbackReturn onShutdown(const rclcpp_lifecycle::State &)
{
return nav2_util::CallbackReturn::SUCCESS;
}

nav2_util::CallbackReturn onError(const rclcpp_lifecycle::State &)
{
return nav2_util::CallbackReturn::SUCCESS;
}
};

void checkMacro(
nav2_core::ProgressChecker & pc,
double x0, double y0,
double x1, double y1,
int delay,
bool expected_result)
{
pc.reset();
geometry_msgs::msg::PoseStamped pose0, pose1;
pose0.pose.position.x = x0;
pose0.pose.position.y = y0;
pose1.pose.position.x = x1;
pose1.pose.position.y = y1;
EXPECT_TRUE(pc.check(pose0));
rclcpp::sleep_for(std::chrono::seconds(delay));
if (expected_result) {
EXPECT_TRUE(pc.check(pose1));
} else {
EXPECT_FALSE(pc.check(pose1));
}
}

TEST(SimpleProgressChecker, progress_checker_reset)
{
auto x = std::make_shared<TestLifecycleNode>("progress_checker");

nav2_core::ProgressChecker * pc = new SimpleProgressChecker;
pc->reset();
delete pc;
EXPECT_TRUE(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how the reset method is being tested. Also, do we need EXPECT_TRUE(true);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making sure it doesn't crash as the next test is dependent on it. EXPECT_TRUE is used as a convention for returning from TEST functions. I have based these tests on the already available goal_checker tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah alright, thanks for explaining it:)

}

TEST(SimpleProgressChecker, unit_tests)
{
auto x = std::make_shared<TestLifecycleNode>("progress_checker");

SimpleProgressChecker pc;
pc.initialize(x, "nav2_controller");
checkMacro(pc, 0, 0, 0, 0, 1, true);
checkMacro(pc, 0, 0, 1, 0, 1, true);
checkMacro(pc, 0, 0, 0, 1, 1, true);
checkMacro(pc, 0, 0, 1, 0, 11, true);
checkMacro(pc, 0, 0, 0, 1, 11, true);
checkMacro(pc, 0, 0, 0, 0, 11, false);
}

int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
16 changes: 11 additions & 5 deletions nav2_controller/src/nav2_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,29 @@ ControllerServer::~ControllerServer()
nav2_util::CallbackReturn
ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
{
auto node = shared_from_this();

RCLCPP_INFO(get_logger(), "Configuring controller interface");

get_parameter("progress_checker_plugin", progress_checker_id_);
if (progress_checker_id_ == default_progress_checker_id_) {
declare_parameter(default_progress_checker_id_ + ".plugin", default_progress_checker_type_);
nav2_util::declare_parameter_if_not_declared(
node, default_progress_checker_id_ + ".plugin",
rclcpp::ParameterValue(default_progress_checker_type_));
}
get_parameter("goal_checker_plugin", goal_checker_id_);
if (goal_checker_id_ == default_goal_checker_id_) {
declare_parameter(default_goal_checker_id_ + ".plugin", default_goal_checker_type_);
nav2_util::declare_parameter_if_not_declared(
node, default_goal_checker_id_ + ".plugin",
rclcpp::ParameterValue(default_goal_checker_type_));
}

get_parameter("controller_plugins", controller_ids_);
if (controller_ids_ == default_ids_) {
for (size_t i = 0; i < default_ids_.size(); ++i) {
declare_parameter(default_ids_[i] + ".plugin", default_types_[i]);
nav2_util::declare_parameter_if_not_declared(
node, default_ids_[i] + ".plugin",
rclcpp::ParameterValue(default_types_[i]));
}
}
controller_types_.resize(controller_ids_.size());
Expand All @@ -95,8 +103,6 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)

costmap_ros_->on_configure(state);

auto node = shared_from_this();

try {
progress_checker_type_ = nav2_util::get_plugin_type_param(node, progress_checker_id_);
progress_checker_ = progress_checker_loader_.createUniqueInstance(progress_checker_type_);
Expand Down
3 changes: 3 additions & 0 deletions nav2_core/include/nav2_core/progress_checker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ProgressChecker
{
public:
typedef std::shared_ptr<nav2_core::ProgressChecker> Ptr;

virtual ~ProgressChecker() {}

/**
* @brief Initialize parameters for ProgressChecker
* @param node Node pointer
Expand Down