Skip to content

Conversation

@destogl
Copy link
Member

@destogl destogl commented Mar 6, 2022

This PR adds explicit tests for the ControllerInterface class where basic behaviors are tested.

The most important behavior definition here is:

update_rate parameter is read at configuration and can be updated only when controller is cleaned-up and configured again

The PR depends on #538 to be merged first.

@destogl destogl force-pushed the controller-interface-test-pr branch from 925bfef to a23bb91 Compare March 7, 2022 12:02
@mergify
Copy link
Contributor

mergify bot commented Mar 14, 2022

This pull request is in conflict. Could you fix it @destogl?

const rclcpp_lifecycle::State & ControllerInterface::configure()
{
update_rate_ = node_->get_parameter("update_rate").as_int();
// TODO(destogl): this should actually happen in "on_configure" but I am not sure how to get
Copy link
Member Author

Choose a reason for hiding this comment

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

@bmagyar please comment on this. Maybe you have an idea how to achieve the behavior I described.

Copy link
Contributor

Choose a reason for hiding this comment

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

@destogl I am maybe more a fan of:

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn 
ControllerInterface::on_configure(const rclcpp_lifecycle::State &previous_state) {

      if (get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
      {
        update_rate_ = get_node()->get_parameter("update_rate").as_int();

      }
      return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
ControllerInterfaceImpl::on_configure(const rclcpp_lifecycle::State & previous_state)
{
   rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn cb_ret = ControllerInterface::on_configure(previous_state);
   // rest of the code
   
   return cb_ret;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This is also a valid approach, for sure. @bmagyar what do you think?

The only “drawback” from my side is that uses have to explicit call this on the parent class. If someone forgets to do this, it may come with an issue that this is not working.

Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't rely on people remembering stuff for us... the code in this PR may be ugly but we don't spill complexity into user code

Copy link
Contributor

Choose a reason for hiding this comment

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

@bmagyar @destogl We could then maybe refactor parts in the hardware_interface

Copy link
Contributor

@livanov93 livanov93 left a comment

Choose a reason for hiding this comment

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

Generally, it looks good to me. There is only one comment regarding the configuration process.
We can decide this later when @bmagyar takes a look.

const rclcpp_lifecycle::State & ControllerInterface::configure()
{
update_rate_ = node_->get_parameter("update_rate").as_int();
// TODO(destogl): this should actually happen in "on_configure" but I am not sure how to get
Copy link
Contributor

Choose a reason for hiding this comment

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

@destogl I am maybe more a fan of:

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn 
ControllerInterface::on_configure(const rclcpp_lifecycle::State &previous_state) {

      if (get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
      {
        update_rate_ = get_node()->get_parameter("update_rate").as_int();

      }
      return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
ControllerInterfaceImpl::on_configure(const rclcpp_lifecycle::State & previous_state)
{
   rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn cb_ret = ControllerInterface::on_configure(previous_state);
   // rest of the code
   
   return cb_ret;
}

const rclcpp_lifecycle::State & ControllerInterface::configure()
{
update_rate_ = node_->get_parameter("update_rate").as_int();
// TODO(destogl): this should actually happen in "on_configure" but I am not sure how to get
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't rely on people remembering stuff for us... the code in this PR may be ugly but we don't spill complexity into user code

@destogl
Copy link
Member Author

destogl commented Apr 6, 2022

I going to merge this to unblock other things.

@destogl destogl merged commit 1554e15 into ros-controls:master Apr 6, 2022
@destogl destogl deleted the controller-interface-test-pr branch April 6, 2022 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants