grid_map icon indicating copy to clipboard operation
grid_map copied to clipboard

[BUG} GridMap Column Order appears reversed?

Open dgitz opened this issue 3 years ago • 2 comments

It appears that the Column order in GridMap is reversed. According to the wiki page, the top left cell should be col = 0, and should positively increment as its iterated to the right. This can be validated by building up a simple map, and then checking that the conversion from a (col,row) value as col is incremented should make the position value X increase.

However as is shown below, it actually decreases (it appears that to follow the convention in the wiki page you have to take col = costMap.getSize().x()-col-1)

        uint16_t width = 6;
        uint16_t height = 4;
        double resolution = 1.0;
        grid_map::GridMap map;
        grid_map::Length mapLength;
        mapLength.x() = (double)width * resolution;
        mapLength.y() = (double)height * resolution;
        grid_map::Position origin;
        origin.x() = 5.0;
        origin.y() = 10.0;
        map.setGeometry(mapLength, resolution, origin);
        grid_map::Matrix layer(width, height);
        double value = 1.0;
        for (int row = 0; row < height; ++row) {
            for (int col = 0; col < width; ++col) {
                layer(col, row) = value;
                value += 1.0;
            }
        }
        map.add("testlayer", layer);
        double expectedValue = 1.0;
        // According to GridMap documentat, Cell (0,0) is at the TOP LEFT of a Map, so as the col is
        // INCREASED the X value should INCREASE.  See:
        // https://github.com/ANYbotics/grid_map#conventions--definitions
        for (int row = 0; row < height; ++row) {
            double maxX = std::numeric_limits<double>::min();
            for (int col = 0; col < width; ++col) {
                grid_map::Index index(col, row);
                grid_map::Position position;
                bool v = map.getPosition(index, position);
                printf("test output %d %d %f %f\n", col, row, position.x(), position.y());
                // EXPECT_GT(position.x(), maxX);
                maxX = position.x();
            }
        }

Output: test output 0 0 7.500000 11.500000 test output 1 0 6.500000 11.500000 test output 2 0 5.500000 11.500000 test output 3 0 4.500000 11.500000 test output 4 0 3.500000 11.500000 test output 5 0 2.500000 11.500000 test output 0 1 7.500000 10.500000 test output 1 1 6.500000 10.500000 test output 2 1 5.500000 10.500000 test output 3 1 4.500000 10.500000 test output 4 1 3.500000 10.500000 test output 5 1 2.500000 10.500000 test output 0 2 7.500000 9.500000 test output 1 2 6.500000 9.500000 test output 2 2 5.500000 9.500000 test output 3 2 4.500000 9.500000 test output 4 2 3.500000 9.500000 test output 5 2 2.500000 9.500000 test output 0 3 7.500000 8.500000 test output 1 3 6.500000 8.500000 test output 2 3 5.500000 8.500000 test output 3 3 4.500000 8.500000 test output 4 3 3.500000 8.500000 test output 5 3 2.500000 8.500000

dgitz avatar Feb 13 '22 13:02 dgitz

AH! Apparently grid_map doesn't follow ROS conventions for frames (X is Up, Y is Left). Be warned!

dgitz avatar Feb 14 '22 15:02 dgitz

Does the chapter Conventions and definitions in the README clarify your question?

maximilianwulf avatar May 04 '22 15:05 maximilianwulf