-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ami-iit/feature/remove_plucker
Remove references of Plucker coordinates
- Loading branch information
Showing
10 changed files
with
172 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,75 @@ | ||
import jax.numpy as jnp | ||
|
||
import jaxsim.typing as jtp | ||
from jaxsim.sixd import so3 | ||
|
||
from .quaternion import Quaternion | ||
from .skew import Skew | ||
|
||
|
||
class Adjoint: | ||
@staticmethod | ||
def rotate_x(theta: float) -> jtp.Matrix: | ||
def from_quaternion_and_translation( | ||
quaternion: jtp.Vector = jnp.array([1.0, 0, 0, 0]), | ||
translation: jtp.Vector = jnp.zeros(3), | ||
inverse: bool = False, | ||
normalize_quaternion: bool = False, | ||
) -> jtp.Matrix: | ||
|
||
c = jnp.cos(theta).squeeze() | ||
s = jnp.sin(theta).squeeze() | ||
assert quaternion.size == 4 | ||
assert translation.size == 3 | ||
|
||
return jnp.array( | ||
[ | ||
[1, 0, 0, 0, 0, 0], | ||
[0, c, s, 0, 0, 0], | ||
[0, -s, c, 0, 0, 0], | ||
[0, 0, 0, 1, 0, 0], | ||
[0, 0, 0, 0, c, s], | ||
[0, 0, 0, 0, -s, c], | ||
] | ||
Q_sixd = so3.SO3.from_quaternion_xyzw(xyzw=Quaternion.to_xyzw(quaternion)) | ||
Q_sixd = Q_sixd if not normalize_quaternion else Q_sixd.normalize() | ||
|
||
return Adjoint.from_rotation_and_translation( | ||
rotation=Q_sixd.as_matrix(), translation=translation, inverse=inverse | ||
) | ||
|
||
@staticmethod | ||
def rotate_y(theta: float) -> jtp.Matrix: | ||
def from_rotation_and_translation( | ||
rotation: jtp.Matrix = jnp.eye(3), | ||
translation: jtp.Vector = jnp.zeros(3), | ||
inverse: bool = False, | ||
) -> jtp.Matrix: | ||
|
||
c = jnp.cos(theta).squeeze() | ||
s = jnp.sin(theta).squeeze() | ||
|
||
return jnp.array( | ||
[ | ||
[c, 0, -s, 0, 0, 0], | ||
[0, 1, 0, 0, 0, 0], | ||
[s, 0, c, 0, 0, 0], | ||
[0, 0, 0, c, 0, -s], | ||
[0, 0, 0, 0, 1, 0], | ||
[0, 0, 0, s, 0, c], | ||
] | ||
) | ||
assert rotation.shape == (3, 3) | ||
assert translation.size == 3 | ||
|
||
@staticmethod | ||
def rotate_z(theta: float) -> jtp.Matrix: | ||
A_R_B = rotation.squeeze() | ||
A_o_B = translation.squeeze() | ||
|
||
c = jnp.cos(theta).squeeze() | ||
s = jnp.sin(theta).squeeze() | ||
if not inverse: | ||
X = A_X_B = jnp.block( | ||
[ | ||
[A_R_B, Skew.wedge(A_o_B) @ A_R_B], | ||
[jnp.zeros(shape=(3, 3)), A_R_B], | ||
] | ||
) | ||
else: | ||
X = B_X_A = jnp.block( | ||
[ | ||
[A_R_B.T, -A_R_B.T @ Skew.wedge(A_o_B)], | ||
[jnp.zeros(shape=(3, 3)), A_R_B.T], | ||
] | ||
) | ||
|
||
return jnp.array( | ||
[ | ||
[c, s, 0, 0, 0, 0], | ||
[-s, c, 0, 0, 0, 0], | ||
[0, 0, 1, 0, 0, 0], | ||
[0, 0, 0, c, s, 0], | ||
[0, 0, 0, -s, c, 0], | ||
[0, 0, 0, 0, 0, 1], | ||
] | ||
) | ||
return X | ||
|
||
@staticmethod | ||
def translate(direction: jtp.Vector) -> jtp.Matrix: | ||
def to_transform(adjoint: jtp.Matrix) -> jtp.Matrix: | ||
|
||
X = adjoint.squeeze() | ||
assert X.shape == (6, 6) | ||
|
||
x, y, z = direction | ||
R = X[0:3, 0:3] | ||
o_x_R = X[0:3, 3:6] | ||
|
||
return jnp.array( | ||
H = jnp.block( | ||
[ | ||
[1, 0, 0, 0, z, -y], | ||
[0, 1, 0, -z, 0, x], | ||
[0, 0, 1, y, -x, 0], | ||
[0, 0, 0, 1, 0, 0], | ||
[0, 0, 0, 0, 1, 0], | ||
[0, 0, 0, 0, 0, 1], | ||
[R, Skew.vee(matrix=o_x_R @ R.T)], | ||
[0, 0, 0, 1], | ||
] | ||
) | ||
|
||
return H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.