-
Notifications
You must be signed in to change notification settings - Fork 3
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
Get joint state by name or index of joint #210
Conversation
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.
A very useful feature, and generally well implemented. Only have a few comments.
* @brief Getter of the positions attribute | ||
* @brief Get joint index by the name of the joint, if it exists. | ||
* @param joint_name The name of the desired joint | ||
* @return The index of the joint, if it exists |
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.
Would be good to add a @details tag that it will throw a JointNotFoundException on failure
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 would actually be nice to add on each scalar getter too, just for explicitness. You can use @copydetails JointState::get_joint_index()
and it will automatically fill in.
#include <iostream> | ||
|
||
namespace state_representation::exceptions { | ||
class JointNotFoundException : public std::logic_error { |
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.
Exception class should also have a simple docstring with @class
and @brief
tags
@@ -228,6 +249,15 @@ TEST(JointStateTest, GetSetData) { | |||
EXPECT_THROW(js1.set_data(Eigen::Vector2d::Zero()), exceptions::IncompatibleSizeException); | |||
} | |||
|
|||
TEST(JointStateTest, GetNameByIndex) { |
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.
TEST(JointStateTest, GetNameByIndex) { | |
TEST(JointStateTest, GetIndexByName) { |
if (joint_index > this->get_size()) { | ||
throw JointNotFoundException( | ||
"Index '" + std::to_string(joint_index) + "' is out of range for joint state with size" | ||
+ std::to_string(this->get_size())); | ||
} |
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.
there's a bit of code duplication in these four methods. could you define a local static method assert_index_in_range
or similar that takes the index and size and does this check?
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.
Incredible stuff ✨
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.
Very good! Thanks a lot
As requested, the function
get_joint_index
andget_X
for a single joint by providing the name or index of the joint. This fails and throws a new exceptionJointNotFoundException
in case the joint doesn't exist.Sorry for the large diff in JointState.hpp, I took the liberty to improve the doc a bit, trying to make it more consistent, becuase @eeberhard is always using the generated doc now :)