-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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.
hardware_interface/include/hardware_interface/hardware_info.hpp
Outdated
Show resolved
Hide resolved
*/ | ||
struct InterfaceDescription | ||
{ | ||
InterfaceDescription(const std::string & prefix_name_in, const InterfaceInfo & interface_info_in) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
joint_states_descr_.emplace_back(InterfaceDescription(joint.name, state_interface)); | |
joint_states_description_.emplace_back(InterfaceDescription(joint.name, state_interface)); |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
This pull request is in conflict. Could you fix it @mamueluth? |
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
To send us a pull request, please:
colcon test
andpre-commit run
(requires you to install pre-commit bypip3 install pre-commit
)