-
Notifications
You must be signed in to change notification settings - Fork 7
feat(sim): support for camera robot lab scene #165
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f2bea3b
feature(sim): added lab empty world and lab sim env with digit hand
suman1209 a58b1a0
refactor(grasp_demo): refactored to correct linting issues
suman1209 be73b5d
refactor(grasp_demo): refactored to correct linting issues
suman1209 f2bc850
Merge remote-tracking branch 'origin/nava/digit_grippers' into nava/d…
suman1209 a28e192
feature(sim): added lab empty world and lab sim env with digit hand
suman1209 bf64b73
refactor(grasp_demo): refactored to correct linting issues
suman1209 34021cd
feat(sim): separated grasp_demo script from the grasp_demo_lab script
suman1209 3889c3d
fix(merge): merge commit
suman1209 3dfb4a5
feat(grasp): pickup script for grasp added
suman1209 7efb329
feat(grasp_demo_lab): unified cube pose randomizer and separated the …
suman1209 4a181c6
fix(sim): random cube placement in lab scene fixed
suman1209 0f1f266
feat(grasp_lab_demo): added second robot cam pose setter
suman1209 f2d2925
fix(grasp_demo_lab): removed side camera feature and refactored
suman1209 35fe651
refactor(grasp_demo_lab): resolved pylint issues
suman1209 1021a27
chore: fix naming consistency between envs
juelg a7d21ec
refactor(envs): move default configs to utils
juelg 14875ed
refactor(envs): tcp extraction before env creation
juelg 76cdd06
fix(control): joint reset also sets controllers
juelg feaa1ca
feat(env): camera robot
juelg 70607c4
refactor(lab env): flexible camera robot joint position
juelg 80e2c7c
feat(sim fr3): make convergence callback registration optional
juelg 2d905eb
fix(sim): allow string path in tcp offset getter
juelg 977c04e
refactor(sim envs): simple and lab pick up share more code
juelg b1491e7
fix(py lint): type annotations and imports
juelg 7014c60
fix(hw fr3): default register convergence callback
juelg 2dda995
tests(env): fixed collision tests
juelg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import logging | ||
| import sys | ||
| from typing import Any, cast | ||
|
|
||
| import gymnasium as gym | ||
| import mujoco | ||
| import numpy as np | ||
| from rcsss._core.common import Pose | ||
| import rcsss.envs.base | ||
| from rcsss.envs.base import FR3Env, GripperWrapper | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
|
|
||
| class PickUpDemo: | ||
| def __init__(self, env: gym.Env): | ||
| self.env = env | ||
| self.unwrapped: FR3Env = cast(FR3Env, self.env.unwrapped) | ||
| self.home_pose = self.unwrapped.robot.get_cartesian_position() | ||
|
|
||
| def _action(self, pose: Pose, gripper: float) -> dict[str, Any]: | ||
| return {"xyzrpy": pose.xyzrpy(), "gripper": gripper} | ||
|
|
||
| def get_object_pose(self, geom_name) -> Pose: | ||
| model = self.env.get_wrapper_attr("sim").model | ||
| data = self.env.get_wrapper_attr("sim").data | ||
|
|
||
| geom_id = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_GEOM, geom_name) | ||
| obj_pose_world_coordinates = Pose( | ||
| translation=data.geom_xpos[geom_id], rotation=data.geom_xmat[geom_id].reshape(3, 3) | ||
| ) | ||
| return self.env.unwrapped.robot.to_pose_in_robot_coordinates(obj_pose_world_coordinates) | ||
|
|
||
| def generate_waypoints(self, start_pose: Pose, end_pose: Pose, num_waypoints: int) -> list[Pose]: | ||
| waypoints = [] | ||
| for i in range(num_waypoints + 1): | ||
| t = i / (num_waypoints + 1) | ||
| waypoints.append(start_pose.interpolate(end_pose, t)) | ||
| return waypoints | ||
|
|
||
| def step(self, action: np.ndarray) -> dict: | ||
| return self.env.step(action) | ||
|
|
||
| def plan_linear_motion(self, geom_name: str, delta_up: float, num_waypoints: int = 200) -> list[Pose]: | ||
| end_eff_pose = self.unwrapped.robot.get_cartesian_position() | ||
| goal_pose = self.get_object_pose(geom_name=geom_name) | ||
| goal_pose *= Pose(translation=np.array([0, 0, delta_up]), quaternion=np.array([1, 0, 0, 0])) | ||
| return self.generate_waypoints(end_eff_pose, goal_pose, num_waypoints=num_waypoints) | ||
|
|
||
| def execute_motion(self, waypoints: list[Pose], gripper: float = GripperWrapper.BINARY_GRIPPER_OPEN) -> dict: | ||
| for i in range(1, len(waypoints)): | ||
| # calculate delta action | ||
| # delta_action = waypoints[i] * waypoints[i - 1].inverse() | ||
| pose = rcsss.common.Pose(translation=waypoints[i].translation(), | ||
| rpy_vector=np.array([-3.14159265e+00, 1.57009246e-16, 0])) | ||
|
|
||
| # act = self._action(delta_action, gripper) | ||
| act = self._action(pose, gripper) | ||
|
|
||
| obs = self.step(act) | ||
| ik_success = obs[-1]["ik_success"] | ||
| if not obs[-1]["ik_success"]: | ||
| trans_source, rot_source = waypoints[i - 1].translation(), waypoints[i - 1].rotation_rpy().as_vector() | ||
| trans_dest, rot_des = waypoints[i].translation(), waypoints[i].rotation_rpy().as_vector() | ||
| msg = (f"ik success: {ik_success} when attempting to move from trans: {trans_source}, rot: {rot_source}\n " | ||
| f"to trans: {trans_dest} rot: {rot_des}!") | ||
| logger.warning(msg) | ||
| assert False, msg | ||
| return obs | ||
|
|
||
| def approach(self, geom_name: str): | ||
| waypoints = self.plan_linear_motion(geom_name=geom_name, delta_up=0.2, num_waypoints=50) | ||
| self.execute_motion(waypoints=waypoints, gripper=GripperWrapper.BINARY_GRIPPER_OPEN) | ||
|
|
||
| def grasp(self, geom_name: str): | ||
|
|
||
| waypoints = self.plan_linear_motion(geom_name=geom_name, delta_up=0, num_waypoints=50) | ||
| self.execute_motion(waypoints=waypoints, gripper=GripperWrapper.BINARY_GRIPPER_OPEN) | ||
|
|
||
| self.step(self._action(Pose(), GripperWrapper.BINARY_GRIPPER_CLOSED)) | ||
|
|
||
| waypoints = self.plan_linear_motion(geom_name=geom_name, delta_up=0.2, num_waypoints=50) | ||
| self.execute_motion(waypoints=waypoints, gripper=GripperWrapper.BINARY_GRIPPER_CLOSED) | ||
|
|
||
| def move_home(self): | ||
| end_eff_pose = self.unwrapped.robot.get_cartesian_position() | ||
| waypoints = self.generate_waypoints(end_eff_pose, self.home_pose, num_waypoints=10) | ||
| self.execute_motion(waypoints=waypoints, gripper=GripperWrapper.BINARY_GRIPPER_CLOSED) | ||
|
|
||
| def pickup(self, geom_name: str): | ||
| self.approach(geom_name) | ||
| self.grasp(geom_name) | ||
| self.move_home() | ||
|
|
||
|
|
||
| def main(): | ||
| # env = gym.make( | ||
| # "rcs/SimplePickUpSimDigitHand-v0", | ||
| # render_mode="human", | ||
| # delta_actions=True | ||
| # ) | ||
|
|
||
| env = gym.make( | ||
| "rcs/FR3LabPickUpSimDigitHand-v0", | ||
| render_mode="human", | ||
| delta_actions=False, | ||
| robot2_cam_pose=[0.1243549, -1.4711298, 1.2246249, -1.9944441, 0.0872650, 1.3396115, 2.1275465], | ||
| ) | ||
| env.reset() | ||
| controller = PickUpDemo(env) | ||
| controller.pickup("yellow_box_geom") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.