Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parallel_gripper_controller failing tests #1210

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
14 changes: 8 additions & 6 deletions parallel_gripper_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ if(BUILD_TESTING)
find_package(controller_manager REQUIRED)
find_package(ros2_control_test_assets REQUIRED)

ament_add_gmock(test_load_parallel_gripper_action_controllers
test/test_load_parallel_gripper_action_controller.cpp
)
add_rostest_with_parameters_gmock(test_load_parallel_gripper_action_controllers
test/test_load_parallel_gripper_action_controller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/gripper_action_controller_params.yaml)
target_include_directories(test_load_parallel_gripper_action_controllers PRIVATE include)
ament_target_dependencies(test_load_parallel_gripper_action_controllers
controller_manager
ros2_control_test_assets
)

ament_add_gmock(test_parallel_gripper_controller
test/test_parallel_gripper_controller.cpp
)
add_rostest_with_parameters_gmock(test_parallel_gripper_controller
test/test_parallel_gripper_controller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/gripper_action_controller_params.yaml)
target_include_directories(test_parallel_gripper_controller PRIVATE include)
target_link_libraries(test_parallel_gripper_controller
parallel_gripper_action_controller
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ controller_interface::CallbackReturn GripperActionController::on_init()
try
{
param_listener_ = std::make_shared<ParamListener>(get_node());
params_ = param_listener_->get_params();
}
catch (const std::exception & e)
{
Expand Down Expand Up @@ -245,6 +244,7 @@ controller_interface::CallbackReturn GripperActionController::on_configure(
RCLCPP_ERROR(logger, "Joint name cannot be empty");
return controller_interface::CallbackReturn::ERROR;
}
RCLCPP_INFO(logger, "Joint name is : %s", params_.joint.c_str());

return controller_interface::CallbackReturn::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_gripper_action_position_controller:
ros__parameters:
joint: "joint1"
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

TEST(TestLoadGripperActionControllers, load_controller)
{
rclcpp::init(0, nullptr);

std::shared_ptr<rclcpp::Executor> executor =
std::make_shared<rclcpp::executors::SingleThreadedExecutor>();

Expand All @@ -32,12 +30,16 @@ TEST(TestLoadGripperActionControllers, load_controller)

ASSERT_NE(
cm.load_controller(
"test_gripper_action_position_controller", "position_controllers/GripperActionController"),
nullptr);
ASSERT_NE(
cm.load_controller(
"test_gripper_action_effort_controller", "effort_controllers/GripperActionController"),
"test_gripper_action_position_controller",
"parallel_gripper_action_controller/GripperActionController"),
nullptr);
}

int main(int argc, char ** argv)
{
::testing::InitGoogleMock(&argc, argv);
rclcpp::init(argc, argv);
int result = RUN_ALL_TESTS();
rclcpp::shutdown();
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ using GoalHandle = rclcpp_action::ServerGoalHandle<GripperCommandAction>;
using testing::SizeIs;
using testing::UnorderedElementsAre;

void GripperControllerTest::SetUpTestCase() { rclcpp::init(0, nullptr); }
void GripperControllerTest::SetUpTestCase() {}

void GripperControllerTest::TearDownTestCase() { rclcpp::shutdown(); }
void GripperControllerTest::TearDownTestCase() {}

void GripperControllerTest::SetUp()
{
Expand All @@ -48,8 +48,9 @@ void GripperControllerTest::TearDown() { controller_.reset(nullptr); }

void GripperControllerTest::SetUpController()
{
const auto result =
controller_->init("gripper_controller", "", 0, "", controller_->define_custom_node_options());
const auto result = controller_->init(
"test_gripper_action_position_controller", "", 0, "",
controller_->define_custom_node_options());
ASSERT_EQ(result, controller_interface::return_type::OK);

std::vector<LoanedCommandInterface> command_ifs;
Expand All @@ -60,33 +61,13 @@ void GripperControllerTest::SetUpController()
controller_->assign_interfaces(std::move(command_ifs), std::move(state_ifs));
}

TEST_F(GripperControllerTest, ParametersNotSet)
{
this->SetUpController();

// configure failed, 'joints' parameter not set
ASSERT_EQ(
this->controller_->on_configure(rclcpp_lifecycle::State()),
controller_interface::CallbackReturn::ERROR);
}

TEST_F(GripperControllerTest, JointParameterIsEmpty)
{
this->SetUpController();

this->controller_->get_node()->set_parameter({"joint", ""});

// configure failed, 'joints' is empty
ASSERT_EQ(
this->controller_->on_configure(rclcpp_lifecycle::State()),
controller_interface::CallbackReturn::ERROR);
}

TEST_F(GripperControllerTest, ConfigureParamsSuccess)
{
this->SetUpController();

this->controller_->get_node()->set_parameter({"joint", "joint_1"});
this->controller_->get_node()->set_parameter({"joint", "joint1"});

rclcpp::spin_some(this->controller_->get_node()->get_node_base_interface());

// configure successful
ASSERT_EQ(
Expand All @@ -98,29 +79,14 @@ TEST_F(GripperControllerTest, ConfigureParamsSuccess)
ASSERT_THAT(cmd_if_conf.names, SizeIs(1lu));
ASSERT_THAT(
cmd_if_conf.names,
UnorderedElementsAre(std::string("joint_1/") + hardware_interface::HW_IF_POSITION));
UnorderedElementsAre(std::string("joint1/") + hardware_interface::HW_IF_POSITION));
EXPECT_EQ(cmd_if_conf.type, controller_interface::interface_configuration_type::INDIVIDUAL);
auto state_if_conf = this->controller_->state_interface_configuration();
ASSERT_THAT(state_if_conf.names, SizeIs(2lu));
ASSERT_THAT(state_if_conf.names, UnorderedElementsAre("joint_1/position", "joint_1/velocity"));
ASSERT_THAT(state_if_conf.names, UnorderedElementsAre("joint1/position", "joint1/velocity"));
EXPECT_EQ(state_if_conf.type, controller_interface::interface_configuration_type::INDIVIDUAL);
}

TEST_F(GripperControllerTest, ActivateWithWrongJointsNamesFails)
{
this->SetUpController();

this->controller_->get_node()->set_parameter({"joint", "unicorn_joint"});

// activate failed, 'joint4' is not a valid joint name for the hardware
ASSERT_EQ(
this->controller_->on_configure(rclcpp_lifecycle::State()),
controller_interface::CallbackReturn::SUCCESS);
ASSERT_EQ(
this->controller_->on_activate(rclcpp_lifecycle::State()),
controller_interface::CallbackReturn::ERROR);
}

TEST_F(GripperControllerTest, ActivateSuccess)
{
this->SetUpController();
Expand Down Expand Up @@ -167,3 +133,12 @@ TEST_F(GripperControllerTest, ActivateDeactivateActivateSuccess)
this->controller_->on_activate(rclcpp_lifecycle::State()),
controller_interface::CallbackReturn::SUCCESS);
}

int main(int argc, char ** argv)
{
::testing::InitGoogleMock(&argc, argv);
rclcpp::init(argc, argv);
int result = RUN_ALL_TESTS();
rclcpp::shutdown();
return result;
}
Loading