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

Add prismatic joint #416

Merged

Conversation

fantaosha
Copy link
Contributor

Motivation and Context

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@fantaosha fantaosha added the enhancement New feature or request label Jan 2, 2023
@fantaosha fantaosha self-assigned this Jan 2, 2023
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 2, 2023
@fantaosha fantaosha force-pushed the taoshaf.robot.prismatic_joint branch from 26d2a70 to e9fd82c Compare January 2, 2023 04:55
Copy link
Contributor

@luisenp luisenp left a comment

Choose a reason for hiding this comment

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

Left some comments to address.

if prismatic_axis.ndim == 1:
prismatic_axis = prismatic_axis.view(-1, 1)

if prismatic_axis.ndim != 2 or prismatic_axis.shape != (3, 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

Here similar comment as I had for RevoluteJoint on using numel().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored. And now the error message is "The prismatic axis must have 3 elements."

super().__init__(name, parent, child, origin, dtype)
self._axis[3] = 1

def _translation_impl(self, angle: torch.Tensor) -> torch.Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

The code in _translation_impl and relative_pose of these 3 classes is exactly the same except for one number, so you can just have a base class _PrismaticJointAxis that defines a member variable self._axis_idx: Optional[int] = None, which gets overridden by all base classes. Then we have

def _translation_impl(self, angle: torch.Tensor) -> torch.Tensor:
    self._check_angle_shape(angle)
    trans = angle.new_zeros(angle.shape[0], 3)
    trans[:, self._axis_idx] = angle
    return trans

def relative_pose(self, angle: torch.Tensor) -> torch.Tensor:
    self._check_angle_shape(angle)
    ret = angle.new_empty(angle.shape[0], 3, 4)
    ret[:, :, :3] = self.origin[:, :, :3]
    ret[:, :, 3] = angle * self.origin[:, :, self._axis_idx] + self.origin[:, :, 3]
    return ret

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored. Thanks!

return 1

@abc.abstractmethod
def _translation_impl(self, angle: torch.Tensor) -> torch.Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as in RevoluteJoint regarding a translation() method, with similar structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.

return 1

@abc.abstractmethod
def _translation_impl(self, angle: torch.Tensor) -> torch.Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe translation() and rotation() (in the other class) should be called translate() and rotate()?

Copy link
Contributor Author

@fantaosha fantaosha Mar 1, 2023

Choose a reason for hiding this comment

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

I think noun should be better than verb since the outputs are 3x3 or 3x1 tensors, which are transformations.

@fantaosha fantaosha force-pushed the taoshaf.robot.prismatic_joint branch from 635c542 to 99ccd46 Compare January 23, 2023 18:43
name: str,
revolute_axis: torch.Tensor,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just axis, I am guessing revolute is implied from the class name.

Copy link
Member

@mhmukadam mhmukadam left a comment

Choose a reason for hiding this comment

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

Looks good. Besides comments here, my other comments are similar to the revolute joint PR so we can follow here what we decide there.

Comment on lines 260 to 264
if prismatic_axis.ndim == 1:
prismatic_axis = prismatic_axis.view(-1, 1)

if prismatic_axis.ndim != 2 or prismatic_axis.shape != (3, 1):
raise ValueError("The prismatic axis must be a 3-D vector.")
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine this logic of "checking if the input is a valid vector of correct length, and unsqueezing it into a vertical vector if it's 1-D" would be very commonly used, not just within the robot model module. Should this be a piece of logic that can be standardized and deduplicated within an utils of some sort?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we anticipate this to be used outside robot model, it would be useful to make an utility function. Otherwise, we should at least delegate this repeated logic to the super class.

fantaosha and others added 2 commits March 1, 2023 16:25
* add link

* add id to joint

* add id to link

* add robot model

* add name to robot

* backup

* refactor joint

* refactor link

* add robot model

* robot model works

* a minior refactor of joint

* add ancestor to links

* update dof computation

* add forward kinematics function

* Add differentiable forward kinematics (#420)

* fixed a bug in FixedJoint

* add angle_ids

* add jacobians to FK

* forward kinematics works

* rename FK

* add tests for differentiable kinematics

* rename tests

* simplify the computation of origin

* add jacobian tests for forward kinematics

* fixed a bug for vectorize=True in SE3

* improve the efficiency of forward kinematics

* add tests for backward propagation

* update lie group load paths

* Add device to robot model (#422)

* add device to robot model

* Refactor Joint.dof as a property (#423)

* refactor joint dof

* add virtual end-effector for tests

* seems to work after name changes

* rename parent->parent_link and child->child_link

* rename angle_ids -> ancestor_active_joint_ids

* refactor tests with torch.testing.assert_close

* small refactoring of the code

* add Robot.get_links()

* remove some setters for link and joint

* made some functions private for encapsulation

* consolidate if block and classmethod->staticmethod

* refactor set_robot_from_urdf_file

* rename ancestor_active_joint_ids -> ancestor_non_fixed_joint_ids

* id=-1 -> id=None

* refactor the code for simplicity

* move link into joint
@fantaosha fantaosha merged commit a2a104f into taoshaf.robot.revolute_joint Mar 1, 2023
fantaosha added a commit that referenced this pull request Mar 8, 2023
* add prismatic joint

* refactor prismatic joint

* Add robot model (#417)

* add link

* add id to joint

* add id to link

* add robot model

* add name to robot

* backup

* refactor joint

* refactor link

* add robot model

* robot model works

* a minior refactor of joint

* add ancestor to links

* update dof computation

* add forward kinematics function

* Add differentiable forward kinematics (#420)

* fixed a bug in FixedJoint

* add angle_ids

* add jacobians to FK

* forward kinematics works

* rename FK

* add tests for differentiable kinematics

* rename tests

* simplify the computation of origin

* add jacobian tests for forward kinematics

* fixed a bug for vectorize=True in SE3

* improve the efficiency of forward kinematics

* add tests for backward propagation

* update lie group load paths

* Add device to robot model (#422)

* add device to robot model

* Refactor Joint.dof as a property (#423)

* refactor joint dof

* add virtual end-effector for tests

* seems to work after name changes

* rename parent->parent_link and child->child_link

* rename angle_ids -> ancestor_active_joint_ids

* refactor tests with torch.testing.assert_close

* small refactoring of the code

* add Robot.get_links()

* remove some setters for link and joint

* made some functions private for encapsulation

* consolidate if block and classmethod->staticmethod

* refactor set_robot_from_urdf_file

* rename ancestor_active_joint_ids -> ancestor_non_fixed_joint_ids

* id=-1 -> id=None

* refactor the code for simplicity

* move link into joint
fantaosha added a commit that referenced this pull request Mar 10, 2023
* add revolute joint

* refactor revolute joint

* add parent and child to joint

* update the path to load so3 and se3

* Add prismatic joint (#416)

* add prismatic joint

* refactor prismatic joint

* Add robot model (#417)

* add link

* add id to joint

* add id to link

* add robot model

* add name to robot

* backup

* refactor joint

* refactor link

* add robot model

* robot model works

* a minior refactor of joint

* add ancestor to links

* update dof computation

* add forward kinematics function

* Add differentiable forward kinematics (#420)

* fixed a bug in FixedJoint

* add angle_ids

* add jacobians to FK

* forward kinematics works

* rename FK

* add tests for differentiable kinematics

* rename tests

* simplify the computation of origin

* add jacobian tests for forward kinematics

* fixed a bug for vectorize=True in SE3

* improve the efficiency of forward kinematics

* add tests for backward propagation

* update lie group load paths

* Add device to robot model (#422)

* Refactor Joint.dof as a property (#423)

* refactor joint dof

* add virtual end-effector for tests

* seems to work after name changes

* rename parent->parent_link and child->child_link

* rename angle_ids -> ancestor_active_joint_ids

* refactor tests with torch.testing.assert_close

* small refactoring of the code

* add Robot.get_links()

* remove some setters for link and joint

* made some functions private for encapsulation

* consolidate if block and classmethod->staticmethod

* refactor set_robot_from_urdf_file

* rename ancestor_active_joint_ids -> ancestor_non_fixed_joint_ids

* id=-1 -> id=None

* refactor the code for simplicity

* move link into joint

* simplify the code

* minor revision to be consistent with Lie group refatcoring

* fixed a CI error

* move files to labs
@mhmukadam mhmukadam deleted the taoshaf.robot.prismatic_joint branch June 23, 2023 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants