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

Add reference timeout parameter to controllers templates #111

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Robotgir
Copy link
Contributor

shall include all changes related to reference timeout

@@ -139,6 +143,30 @@ controller_interface::CallbackReturn DummyClassName::on_configure(
return controller_interface::CallbackReturn::SUCCESS;
}

void DummyClassName::reference_callback(const std::shared_ptr<ControllerReferenceMsg> msg)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

saw that ref_callback is called in different order in standard and chainable controller, hence adjusting it to be consistent with standard controller

Copy link
Member

Choose a reason for hiding this comment

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

in the chainable controller,
this callback is not used at all. I mean, you can call it, but nothing will happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for the confusion i should have written "ref_callback is defined in different order in standard and chain-able controller classes, hence adjusting it to be consistent with standard controller"

its trivial change, just changed the order

// Reference Subscriber
ref_subscriber_ = get_node()->create_subscription<ControllerReferenceMsg>(
"~/reference", subscribers_qos,
"~/commands", subscribers_qos,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

saw that usage of "/reference" is inconsistent in the current master version changed to "/reference" completely in a different PR
#106

@@ -192,7 +195,7 @@ TEST_F(DummyClassNameTest, test_update_logic_fast)

EXPECT_EQ(*(controller_->control_mode_.readFromRT()), control_mode_type::FAST);
EXPECT_EQ(joint_command_values_[STATE_MY_ITFS], TEST_DISPLACEMENT);
EXPECT_TRUE(std::isnan((*(controller_->input_ref_.readFromRT()))->displacements[0]));
EXPECT_EQ((*(controller_->input_ref_.readFromRT()))->displacements[0], TEST_DISPLACEMENT);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i just adjusted this to work here, but wanted to get confirmation from you. I see that in mecanum we set reference msg to nan when ref_timeout = 0 and for too old msg (age_of_last_command > ref_timeout_)

in this particular test we have testing update fast logic where age_of_last_command <= ref_timeout_

and more over this test will be over written in the PR #106
with a different name with similar logic test

@@ -366,6 +372,166 @@ TEST_F(DummyClassNameTest, receive_message_and_publish_updated_status)
ASSERT_EQ(msg.set_point, 0.45);
}

// when too old msg is sent expect reference msg reset
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added ref_timeout related tests with agreed naming convention

// Reference Subscriber
ref_subscriber_ = get_node()->create_subscription<ControllerReferenceMsg>(
"~/reference", subscribers_qos,
"~/commands", subscribers_qos,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"~/commands", subscribers_qos,
"~/reference", subscribers_qos,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok change ing it to /reference everywhere

@@ -139,6 +143,30 @@ controller_interface::CallbackReturn DummyClassName::on_configure(
return controller_interface::CallbackReturn::SUCCESS;
}

void DummyClassName::reference_callback(const std::shared_ptr<ControllerReferenceMsg> msg)
Copy link
Member

Choose a reason for hiding this comment

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

in the chainable controller,
this callback is not used at all. I mean, you can call it, but nothing will happen.

Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

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

  • Please use reference instead of command.
  • One test is not fully implemented when testing only a single call.
  • Why is there repetition of the logic in both the update methods? Only method that gets things from callback should have the logic.

const auto age_of_last_command = get_node()->now() - msg->header.stamp;
if (msg->joint_names.size() == params_.joints.size()) {
if (ref_timeout_ == rclcpp::Duration::from_seconds(0) || age_of_last_command <= ref_timeout_) {
input_ref_.writeFromNonRT(msg);
Copy link
Member

Choose a reason for hiding this comment

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

Should we not have here default value of the header is timestamp is "0"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are referring to this handling of case if header.stamp ==0 right?

this is included in the improvements from mecanum PR, you can see the line in the below link, should i also implement this in this ref_timeout PR?

https://github.com/StoglRobotics/ros_team_workspace/pull/106/files#diff-6e6a1012850b4b6040c5339b00ffad68f776d9edb72dbbe3e1d84482d52c4081R189-R197

Comment on lines 271 to 272
auto current_ref = input_ref_.readFromRT();
const auto age_of_last_command = get_node()->now() - (*current_ref)->header.stamp;
Copy link
Member

Choose a reason for hiding this comment

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

why is this here? This should be in the update reference from subscribers only. Please adjust

Comment on lines 276 to 289
// send message only if there is no timeout
if (age_of_last_command <= ref_timeout_ || ref_timeout_ == rclcpp::Duration::from_seconds(0)) {
if (!std::isnan(reference_interfaces_[i])) {
if (*(control_mode_.readFromRT()) == control_mode_type::SLOW) {
reference_interfaces_[i] /= 2;
}
command_interfaces_[i].set_value(reference_interfaces_[i]);
if (ref_timeout_ == rclcpp::Duration::from_seconds(0)) {
reference_interfaces_[i] = std::numeric_limits<double>::quiet_NaN();
}
}
command_interfaces_[i].set_value(reference_interfaces_[i]);

reference_interfaces_[i] = std::numeric_limits<double>::quiet_NaN();
} else {
command_interfaces_[i].set_value(0.0);
(*current_ref)->displacements[i] = std::numeric_limits<double>::quiet_NaN();
Copy link
Member

Choose a reason for hiding this comment

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

Why is the code here repeated?

// Reference Subscriber
ref_subscriber_ = get_node()->create_subscription<ControllerReferenceMsg>(
"~/reference", subscribers_qos,
"~/commands", subscribers_qos,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"~/commands", subscribers_qos,
"~/reference", subscribers_qos,

command_interfaces_[i].set_value((*current_ref)->displacements[i]);

} else {
command_interfaces_[i].set_value(0.0);
Copy link
Member

Choose a reason for hiding this comment

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

here under is missing resetting of refrence interfaces...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is standard controller and in my understanding we dont have reference_interfaces in standard controller. Please correct me if i am wrong

EXPECT_FALSE(std::isnan((*(controller_->input_ref_.readFromNonRT()))->duration));
EXPECT_EQ((*(controller_->input_ref_.readFromNonRT()))->displacements[0], 0.45);
EXPECT_EQ((*(controller_->input_ref_.readFromNonRT()))->velocities[0], 0.0);
EXPECT_EQ((*(controller_->input_ref_.readFromNonRT()))->duration, 1.25);
Copy link
Member

Choose a reason for hiding this comment

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

you should call this also a second time to be sure that this works only once - not you can not confirm that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extended the test here like this but have question,
it works when setting the ref_msg to nan like done here

but instead of individually setting them like that i wanted to just call
reset_controller_reference_msg(*(input_ref_.readFromRT()), state_joints_, get_node());

but this is not working, also made sure that the fun is being called but the msg is not being reset. is the way i am inputing the ref_msg wrong? like this "*(input_ref_.readFromRT())".

GiridharBukka added 3 commits March 29, 2023 18:41
…lback_expect_reference_msg_being_used_only_once and extending its relavant code in controllers
@mergify
Copy link

mergify bot commented May 12, 2023

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

4 similar comments
@mergify
Copy link

mergify bot commented Aug 11, 2023

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

@mergify
Copy link

mergify bot commented Oct 9, 2023

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

Copy link

mergify bot commented Dec 12, 2023

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

Copy link

mergify bot commented Feb 1, 2024

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

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.

2 participants