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

move creation of stateinterfaces to systeminterface #9

Closed
wants to merge 8 commits into from

Conversation

mamueluth
Copy link
Member

Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:

  1. Limited scope. Your PR should do one thing or one set of things. Avoid adding “random fixes” to PRs. Put those on separate PRs.
  2. Give your PR a descriptive title. Add a short summary, if required.
  3. Make sure the pipeline is green.
  4. Don’t be afraid to request reviews from maintainers.
  5. New code = new tests. If you are adding new functionality, always make sure to add some tests exercising the code and serving as live documentation of your original intention.

To send us a pull request, please:

  • Fork the repository.
  • Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
  • Ensure local tests pass. (colcon test and pre-commit run (requires you to install pre-commit by pip3 install pre-commit)
  • Commit to your fork using clear commit messages.
  • Send a pull request, answering any default questions in the pull request interface.
  • Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@@ -116,6 +117,13 @@ class ReadWriteHandle : public ReadOnlyHandle
class StateInterface : public ReadOnlyHandle
{
public:
explicit StateInterface(
const InterfaceDescription & interface_description, double * value_ptr = nullptr)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we actually need to extend this here. We are not storing InterfaceDescription, but extending this might be useful in the future to support other types. What we also don't need here is the third argument value_ptr. Did you plan to remove it in the future? I mean we require this for backward compatibility, but for new approach only InterfaceDescription should sufficient.

Copy link
Member

Choose a reason for hiding this comment

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

Looking into this, it might be useful to move the storage here, when using getter and setters, which means that we don't need this method, but more something like:

Suggested change
const InterfaceDescription & interface_description, double * value_ptr = nullptr)
const InterfaceDescription & interface_description)

This should for now store the variable with value, and later we move it into handles, for example:

const InterfaceDescription & interface_description) : ReadOnlyHandle(interface_description)  // new method there see below)
{
  value = std::limits<double>::quietNan();  // it might be that we can move this even in the ReadOnlyHandle, which is even better so we don't need to duplicate this code in the interfaces --> this means if there is no pointer, we create our own storage of values.
  value_ptr_ = &value;
}  // This method might be removed later when we remove the old functionality

private:
  double value; // later we move this value into 

... [this should go above in the `ReadOnlyHandle`

explicit ReadOnlyHandle(const InterfaceDescription & interface_description)
  : prefix_name_(interface_description.prefix_name.), interface_name_(interface_description.interface_info.name), value_ptr_(nullptr)
{
} 

Later changes within this file / handles are OK. Therefore, it is not so relevant where you move storage, but of course nicer the code the better. Only the changes of external API are critical.

Copy link
Member Author

Choose a reason for hiding this comment

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

working on this as a second step. Needs quite a lot of changes.

*/
struct InterfaceDescription
{
InterfaceDescription(const std::string & prefix_name_in, const InterfaceInfo & interface_info_in)
Copy link
Member

Choose a reason for hiding this comment

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

This is a good idea to add this class, but please add also then type and size and so on. Maybe we have already something suitable here. What about InterfaceInfo structure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what you mean, i already use InterfaceInfo but i created this since the unique name of the component is missing and ComponentInfo does store all command/state Interfaces which we don't want either. Or am i mistaken?

return CallbackReturn::SUCCESS;
};

virtual void add_state_interface_descriptions()
Copy link
Member

Choose a reason for hiding this comment

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

Method name is not so good. Why don't you use the stateless method, this means doesn't access to the global variables? This parsing will repeat in all components, so maybe adding this into URDF parser or Hardware Info might be enough. Actually, we have this already in the InterfaceInfo class. OK, only sorting into different vectors is not there… Perhaps something be added on the parser level, as it is repeatable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cannot think of a better name. moved it to component parser

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed it to import _<command/state>_interface_descriptions

{
for (const auto & state_interface : joint.state_interfaces)
{
joint_states_descr_.emplace_back(InterfaceDescription(joint.name, state_interface));
Copy link
Member

Choose a reason for hiding this comment

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

Just write the full name, it is clearer.

Suggested change
joint_states_descr_.emplace_back(InterfaceDescription(joint.name, state_interface));
joint_states_description_.emplace_back(InterfaceDescription(joint.name, state_interface));

Comment on lines +279 to +327
double joint_state_get_value(const InterfaceDescription & interface_descr) const
{
return joint_states_.at(interface_descr.get_name());
}

void joint_state_set_value(const InterfaceDescription & interface_descr, const double & value)
{
joint_states_[interface_descr.get_name()] = value;
}

double joint_command_get_value(const InterfaceDescription & interface_descr) const
{
return joint_commands_.at(interface_descr.get_name());
}

void joint_command_set_value(const InterfaceDescription & interface_descr, const double & value)
{
joint_commands_[interface_descr.get_name()] = value;
}

double sensor_state_get_value(const InterfaceDescription & interface_descr) const
{
return sensor_states_.at(interface_descr.get_name());
}

void sensor_state_set_value(const InterfaceDescription & interface_descr, const double & value)
{
sensor_states_[interface_descr.get_name()] = value;
}

double gpio_state_get_value(const InterfaceDescription & interface_descr) const
{
return gpio_states_.at(interface_descr.get_name());
}

void gpio_state_set_value(const InterfaceDescription & interface_descr, const double & value)
{
gpio_states_[interface_descr.get_name()] = value;
}

double gpio_command_get_value(const InterfaceDescription & interface_descr) const
{
return gpio_commands_.at(interface_descr.get_name());
}

void gpio_commands_set_value(const InterfaceDescription & interface_descr, const double & value)
{
gpio_commands_[interface_descr.get_name()] = value;
}
Copy link
Member

Choose a reason for hiding this comment

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

This looks good!

Copy link

mergify bot commented Jan 8, 2024

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

@mamueluth mamueluth closed this Jan 22, 2024
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