Skip to content

Conversation

@jsbyysheng
Copy link
Contributor

Reference issue

fix error: 'numpy.ndarray' object has no attribute 'append'

What does this implement/fix?

When running grid_based_sweep_coverage_path_planner.py and giving ox and oy without ox[0] == ox[-1], you will get fix error: 'numpy.ndarray' object has no attribute 'append'

Additional information

CheckList

-[] Did you add an unittest for your new example or defect fix?
-[] Did you add documents for your new example?
-[] All CIs are green? (You can check it after submitting)

fix error: 'numpy.ndarray' object has no attribute 'append'
@jsbyysheng jsbyysheng changed the title Update grid_map_lib.py fix error: 'numpy.ndarray' object has no attribute 'append' Apr 27, 2022
if (pol_x[0] != pol_x[-1]) or (pol_y[0] != pol_y[-1]):
pol_x.append(pol_x[0])
pol_y.append(pol_y[0])
np.append(pol_x, pol_x[0])
Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for your PR. is it possible to add a test for this change in this file? https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_grid_map_lib.py

Copy link
Contributor Author

@jsbyysheng jsbyysheng Apr 27, 2022

Choose a reason for hiding this comment

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

After my survey, the error occurs in grid_based_sweep_coverage_path_planner.py because the function convert_grid_coordinate returns numpy.ndarray. I think it more suitable to modify grid_based_sweep_coverage_path_planner.py:

from

def convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position):
    tx = [ix - sweep_start_position[0] for ix in ox]
    ty = [iy - sweep_start_position[1] for iy in oy]
    th = math.atan2(sweep_vec[1], sweep_vec[0])
    rot = Rot.from_euler('z', th).as_matrix()[0:2, 0:2]
    converted_xy = np.stack([tx, ty]).T @ rot

    return converted_xy[:, 0], converted_xy[:, 1]

to

def convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position):
    tx = [ix - sweep_start_position[0] for ix in ox]
    ty = [iy - sweep_start_position[1] for iy in oy]
    th = math.atan2(sweep_vec[1], sweep_vec[0])
    rot = Rot.from_euler('z', th).as_matrix()[0:2, 0:2]
    converted_xy = np.stack([tx, ty]).T @ rot

    return converted_xy[:, 0].tolist(), converted_xy[:, 1].tolist()

In this case, we do not need to change the algorithm file and the pytest file. What do you think about it?

Copy link
Owner

Choose a reason for hiding this comment

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

I prefer to use np.array instead of build-in list in codes. So I love this PR change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I think test should be add to https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_grid_based_sweep_coverage_path_planner.py because in https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_grid_map_lib.py, ox[0] != ox[-1] and oy[0]!=oy[-1] make np.append effective.

def test_polygon_set():
    ox = [0.0, 20.0, 50.0, 100.0, 130.0, 40.0]
    oy = [0.0, -20.0, 0.0, 30.0, 60.0, 80.0]

    grid_map = GridMap(600, 290, 0.7, 60.0, 30.5)

    grid_map.set_value_from_polygon(ox, oy, 1.0, inside=False)

Copy link
Owner

@AtsushiSakai AtsushiSakai Apr 30, 2022

Choose a reason for hiding this comment

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

The test looks good to me!

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

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

I added a test. So LGTM. thank you!!

@AtsushiSakai AtsushiSakai merged commit a3fd04f into AtsushiSakai:master May 7, 2022
@jsbyysheng jsbyysheng deleted the jsbyysheng-patch-1 branch May 7, 2022 09:18
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.

2 participants