Skip to content

Commit

Permalink
Add tests for interface_configuration_type consistently (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed Jun 6, 2024
1 parent 7d6e473 commit 598ed7f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
29 changes: 15 additions & 14 deletions pid_controller/test/test_pid_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,46 @@ TEST_F(PidControllerTest, all_parameters_set_configure_success)
ASSERT_FALSE(controller_->params_.use_external_measured_states);
}

TEST_F(PidControllerTest, check_exported_intefaces)
TEST_F(PidControllerTest, check_exported_interfaces)
{
SetUpController();

ASSERT_EQ(controller_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS);

auto command_interfaces = controller_->command_interface_configuration();
ASSERT_EQ(command_interfaces.names.size(), dof_command_values_.size());
for (size_t i = 0; i < command_interfaces.names.size(); ++i)
auto cmd_if_conf = controller_->command_interface_configuration();
ASSERT_EQ(cmd_if_conf.names.size(), dof_command_values_.size());
for (size_t i = 0; i < cmd_if_conf.names.size(); ++i)
{
EXPECT_EQ(command_interfaces.names[i], dof_names_[i] + "/" + command_interface_);
EXPECT_EQ(cmd_if_conf.names[i], dof_names_[i] + "/" + command_interface_);
}
EXPECT_EQ(cmd_if_conf.type, controller_interface::interface_configuration_type::INDIVIDUAL);

auto state_intefaces = controller_->state_interface_configuration();
ASSERT_EQ(state_intefaces.names.size(), dof_state_values_.size());
auto state_if_conf = controller_->state_interface_configuration();
ASSERT_EQ(state_if_conf.names.size(), dof_state_values_.size());
size_t si_index = 0;
for (const auto & interface : state_interfaces_)
{
for (const auto & dof_name : dof_names_)
{
EXPECT_EQ(state_intefaces.names[si_index], dof_name + "/" + interface);
EXPECT_EQ(state_if_conf.names[si_index], dof_name + "/" + interface);
++si_index;
}
}
EXPECT_EQ(state_if_conf.type, controller_interface::interface_configuration_type::INDIVIDUAL);

// check ref itfs
auto reference_interfaces = controller_->export_reference_interfaces();
ASSERT_EQ(reference_interfaces.size(), dof_state_values_.size());
auto ref_if_conf = controller_->export_reference_interfaces();
ASSERT_EQ(ref_if_conf.size(), dof_state_values_.size());
size_t ri_index = 0;
for (const auto & interface : state_interfaces_)
{
for (const auto & dof_name : dof_names_)
{
const std::string ref_itf_name =
std::string(controller_->get_node()->get_name()) + "/" + dof_name + "/" + interface;
EXPECT_EQ(reference_interfaces[ri_index].get_name(), ref_itf_name);
EXPECT_EQ(
reference_interfaces[ri_index].get_prefix_name(), controller_->get_node()->get_name());
EXPECT_EQ(reference_interfaces[ri_index].get_interface_name(), dof_name + "/" + interface);
EXPECT_EQ(ref_if_conf[ri_index].get_name(), ref_itf_name);
EXPECT_EQ(ref_if_conf[ri_index].get_prefix_name(), controller_->get_node()->get_name());
EXPECT_EQ(ref_if_conf[ri_index].get_interface_name(), dof_name + "/" + interface);
++ri_index;
}
}
Expand Down
29 changes: 15 additions & 14 deletions pid_controller/test/test_pid_controller_preceding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,45 +49,46 @@ TEST_F(PidControllerTest, all_parameters_set_configure_success)
ASSERT_EQ(controller_->params_.command_interface, command_interface_);
}

TEST_F(PidControllerTest, check_exported_intefaces)
TEST_F(PidControllerTest, check_exported_interfaces)
{
SetUpController();

ASSERT_EQ(controller_->on_configure(rclcpp_lifecycle::State()), NODE_SUCCESS);

auto command_intefaces = controller_->command_interface_configuration();
ASSERT_EQ(command_intefaces.names.size(), dof_command_values_.size());
for (size_t i = 0; i < command_intefaces.names.size(); ++i)
auto cmd_if_conf = controller_->command_interface_configuration();
ASSERT_EQ(cmd_if_conf.names.size(), dof_command_values_.size());
for (size_t i = 0; i < cmd_if_conf.names.size(); ++i)
{
EXPECT_EQ(command_intefaces.names[i], dof_names_[i] + "/" + command_interface_);
EXPECT_EQ(cmd_if_conf.names[i], dof_names_[i] + "/" + command_interface_);
}
EXPECT_EQ(cmd_if_conf.type, controller_interface::interface_configuration_type::INDIVIDUAL);

auto state_intefaces = controller_->state_interface_configuration();
ASSERT_EQ(state_intefaces.names.size(), dof_state_values_.size());
auto state_if_conf = controller_->state_interface_configuration();
ASSERT_EQ(state_if_conf.names.size(), dof_state_values_.size());
size_t si_index = 0;
for (const auto & interface : state_interfaces_)
{
for (const auto & dof_name : reference_and_state_dof_names_)
{
EXPECT_EQ(state_intefaces.names[si_index], dof_name + "/" + interface);
EXPECT_EQ(state_if_conf.names[si_index], dof_name + "/" + interface);
++si_index;
}
}
EXPECT_EQ(state_if_conf.type, controller_interface::interface_configuration_type::INDIVIDUAL);

// check ref itfs
auto reference_interfaces = controller_->export_reference_interfaces();
ASSERT_EQ(reference_interfaces.size(), dof_state_values_.size());
auto ref_if_conf = controller_->export_reference_interfaces();
ASSERT_EQ(ref_if_conf.size(), dof_state_values_.size());
size_t ri_index = 0;
for (const auto & interface : state_interfaces_)
{
for (const auto & dof_name : reference_and_state_dof_names_)
{
const std::string ref_itf_name =
std::string(controller_->get_node()->get_name()) + "/" + dof_name + "/" + interface;
EXPECT_EQ(reference_interfaces[ri_index].get_name(), ref_itf_name);
EXPECT_EQ(
reference_interfaces[ri_index].get_prefix_name(), controller_->get_node()->get_name());
EXPECT_EQ(reference_interfaces[ri_index].get_interface_name(), dof_name + "/" + interface);
EXPECT_EQ(ref_if_conf[ri_index].get_name(), ref_itf_name);
EXPECT_EQ(ref_if_conf[ri_index].get_prefix_name(), controller_->get_node()->get_name());
EXPECT_EQ(ref_if_conf[ri_index].get_interface_name(), dof_name + "/" + interface);
++ri_index;
}
}
Expand Down

0 comments on commit 598ed7f

Please sign in to comment.