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

Get joint state by name or index of joint #210

Merged
merged 8 commits into from
Sep 16, 2021

Conversation

domire8
Copy link
Contributor

@domire8 domire8 commented Sep 16, 2021

As requested, the function get_joint_index and get_X for a single joint by providing the name or index of the joint. This fails and throws a new exception JointNotFoundException 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 :)

Copy link
Member

@eeberhard eeberhard left a 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
Copy link
Member

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

Copy link
Member

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 {
Copy link
Member

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) {
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
TEST(JointStateTest, GetNameByIndex) {
TEST(JointStateTest, GetIndexByName) {

Comment on lines 83 to 87
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()));
}
Copy link
Member

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?

Copy link
Member

@eeberhard eeberhard left a comment

Choose a reason for hiding this comment

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

Incredible stuff ✨

Copy link
Contributor

@buschbapti buschbapti left a 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

@domire8 domire8 merged commit 37fa1b1 into develop Sep 16, 2021
@domire8 domire8 deleted the feature/get-joint-state-by-name branch September 16, 2021 14:08
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