scikit-robot icon indicating copy to clipboard operation
scikit-robot copied to clipboard

Is changing the non-root cascaded coords allowed?

Open HiroIshida opened this issue 1 year ago • 1 comments

I expected new and co2's worldcoords match, but they don't.

import numpy as np
from skrobot.coordinates import CascadedCoords, Coordinates
np.random.seed(0)

co1 = CascadedCoords(pos = [0.1, 0.2, 0.3])
co2 = CascadedCoords()
co1.assoc(co2)
new = Coordinates(np.random.randn(3))
co2.newcoords(new)
print(new)
print(co2)

output

#<Coordinates 0x7f3010dd8700 1.764 0.400 0.979 / 0.0 -0.0 0.0>
#<CascadedCoords 0x7f3010ebf3a0 1.864 0.600 1.279 / 0.0 -0.0 0.0>

Looks like a bug, but I'm not certain. Is changing the child coords allowed? If so, the above behavior is itended?

HiroIshida avatar Dec 18 '23 06:12 HiroIshida

Thank you for pointing out the issue. The newcoords method in CascadedCoords is set to change position relative to the parent link by default. To change coordinates relative to the world instead of the parent, you can do as follows. However, as you mentioned, this behavior might be confusing. As a solution, it might be better to add arguments like "world" or "local" to newcoords, similar to other functions, to allow changing coordinates relative to these. What do you think?

import numpy as np
from skrobot.coordinates import CascadedCoords, Coordinates
np.random.seed(0)

co1 = CascadedCoords(pos=[0.1, 0.2, 0.3])
co2 = CascadedCoords()
co1.assoc(co2)
new = Coordinates(pos=[1, 2, 3])
co2.newcoords(co2.parent.copy_worldcoords().inverse_transformation().transform(
    new))
# co2.newcoords(new)
print(new)
print(co2)

iory avatar Dec 25 '23 01:12 iory