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

getIndex() Unable to Obtain Index for Maximum Negative Length of Map #272

Closed
BruceChanJianLe opened this issue Nov 23, 2020 · 10 comments
Closed

Comments

@BruceChanJianLe
Copy link

My grid_map is geometry size is as below:

map_.setGeometry(grid_map::Length(1.0, 1.0), 0.05, grid_map::Position(0.0, 0.0));

When my position is -0.5 (return from getClosestPositionInMap()), which is still valid in the map, I get the error of

/usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h:365: Eigen::DenseCoeffsBase<Derived, 1>::Scalar& Eigen::DenseCoeffsBase<Derived, 1>::operator()(Eigen::Index, Eigen::Index) [with Derived = Eigen::Matrix<float, -1, -1>; Eigen::DenseCoeffsBase<Derived, 1>::Scalar = float; Eigen::Index = long int]: Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed.

However, if my position is 0.5 (return from getClosestPositionInMap()), I do not get the error, and I am able to obtain the index.

I specifically mentioned getClosestPositionInMap() function as I am not sure whether should the getClosestPositionInMap() return something like -0.49 instead of -0.5, or is this a bug inside of getIndex().

Below code will fail when any of the x or y position is -0.5 which is the maximum negative length of the map.

if(map_.getIndex(points_["point_a"], index_a_)
&& map_.getIndex(points_["point_b"], index_b_))
 {
    // Loop through line region
    for(grid_map::LineIterator itr(map_, index_a_, index_b_); !itr.isPastEnd(); ++itr)
    {
        // Change value from 0.0 to 1.0
        map_.at("type", *itr) = 1.0;
        // Publish map
        publish();
    }
}

Thank you for taking your time to look into this matter:D

@maximilianwulf
Copy link
Collaborator

Hey @BruceChanJianLe, thank you for submitting the bug. Could you submit a short unit test into this file: https://github.com/ANYbotics/grid_map/blob/master/grid_map_core/test/GridMapTest.cpp. I guess you can copy the code from above.

@BruceChanJianLe
Copy link
Author

Hi @maximilianwulf, thanks for getting back. I have submitted a short unit test as requested in #275. Please have a look at the failing test NegativeClosestPositionInMap. Thank you:D

@maximilianwulf
Copy link
Collaborator

Thank you, we will have a look at it.

@BruceChanJianLe
Copy link
Author

You're welcome! Thank you for taking your time to look into this issue.

@maximilianwulf
Copy link
Collaborator

Hey @BruceChanJianLe, indeed the function getClosestPositionInMap gives values at the border of the map, which can in some cases lead to indices outside of the map. I made a fix that should make the function save. It will be merged in the coming days. Thank you for reporting the issue.

@BruceChanJianLe
Copy link
Author

Hi @maximilianwulf, thank you for looking into this issue, appreciate your time and contribution to the community. Please remember to close this issue when the fix is merged, before that, I shall leave this issue as open. Thanks again and take care!

@maximilianwulf
Copy link
Collaborator

Hey @BruceChanJianLe, a fix is on the way. Let me know if you have further issues.

@BruceChanJianLe
Copy link
Author

Hi @maximilianwulf, thanks for looking into this is issue. I will be looking forward to the fix! Thank you:)

@maximilianwulf
Copy link
Collaborator

You can check out this commit f1344bd

@BruceChanJianLe
Copy link
Author

Wonderful! I will test on it when it is successfully merged into master branch. Thank you @maximilianwulf !

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

No branches or pull requests

2 participants