-
Notifications
You must be signed in to change notification settings - Fork 7
feat(env): tilburg hand controller integration #172
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 17 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9480784
- work in progress hand integration
khaledmohamed00 bc9c6e1
- refactor the hand module
khaledmohamed00 cb70eed
refactor(hand integration)
khaledmohamed00 14f7f3a
refactor(hand module)
khaledmohamed00 e1db295
feat(hand): enable Binary and vector action
khaledmohamed00 d5403a8
refafix(hand) : refactor and fix action and observation space for bot…
khaledmohamed00 8855f06
fix(hand): add get_pos_vector and set_pos_vector to Handcontol class
khaledmohamed00 2a0a00f
refactor(hand): fix pyformat, pylint and pytest
khaledmohamed00 2511e7b
fix(hand): make default value in TilburgHandControl class instead of …
khaledmohamed00 e95c1f4
Merge commit 'b877f82f3b00b68fafe99f51a609100c8110da45' into gamal/ti…
khaledmohamed00 a1e8294
refactor(hand): fix pyformat, pylint and pytest
khaledmohamed00 5ab655c
refactor(hand): beteter handling of default grasp value and add tilbu…
khaledmohamed00 ac8d35f
fix(env): fix some of the requersted changes
khaledmohamed00 00ba9f1
refactor(envs, hand, examples): address the requested changes
khaledmohamed00 f6a2e65
refactor(envs): fix pyformat, pylint and pytest
khaledmohamed00 7bb2d36
refactor(examples):
khaledmohamed00 75fc5ca
refactor(examples): pyformat, pylint and pytest
khaledmohamed00 9a20d99
refactor(hand): python protocol interface
juelg c35304f
refactor(hand): rename to remove control in name
juelg a1518d2
refactor(hand): previous renaming in code
juelg 550541e
Merge branch 'master' into gamal/tilburg-hand
juelg 51fec0d
fix: imports for renamed rcs package
juelg f53303d
fix: remaining qarts renamed
juelg a0f4260
fix(examples): import of hand example
juelg a7c0232
style: python format
juelg 3b0e9f8
fix(env creators): gripper config types
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import logging | ||
| from typing import Union | ||
|
|
||
| from rcsss.control.fr3_desk import FCI, Desk, DummyResourceManager | ||
| from rcsss.control.utils import load_creds_fr3_desk | ||
| from rcsss.envs.base import ControlMode, RelativeTo, RobotInstance | ||
| from rcsss.envs.factories import fr3_hw_env, fr3_sim_env | ||
| from rcsss.envs.utils import ( | ||
| default_fr3_hw_robot_cfg, | ||
| default_fr3_sim_gripper_cfg, | ||
| default_fr3_sim_robot_cfg, | ||
| default_mujoco_cameraset_cfg, | ||
| default_tilburg_hw_hand_cfg, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
| ROBOT_IP = "192.168.101.1" | ||
| ROBOT_INSTANCE = RobotInstance.SIMULATION | ||
|
|
||
|
|
||
| """ | ||
| Create a .env file in the same directory as this file with the following content: | ||
| FR3_USERNAME=<username on franka desk> | ||
| FR3_PASSWORD=<password on franka desk> | ||
|
|
||
| When you use a real FR3 you first need to unlock its joints using the following cli script: | ||
|
|
||
| python -m rcsss fr3 unlock <ip> | ||
|
|
||
| or put it into guiding mode using: | ||
|
|
||
| python -m rcsss fr3 guiding-mode <ip> | ||
|
|
||
| When you are done you lock it again using: | ||
|
|
||
| python -m rcsss fr3 lock <ip> | ||
|
|
||
| or even shut it down using: | ||
|
|
||
| python -m rcsss fr3 shutdown <ip> | ||
| """ | ||
|
|
||
|
|
||
| def main(): | ||
| resource_manger: FCI | DummyResourceManager | ||
| if ROBOT_INSTANCE == RobotInstance.HARDWARE: | ||
| user, pw = load_creds_fr3_desk() | ||
| resource_manger = FCI(Desk(ROBOT_IP, user, pw), unlock=False, lock_when_done=False) | ||
| else: | ||
| resource_manger = DummyResourceManager() | ||
| with resource_manger: | ||
| if ROBOT_INSTANCE == RobotInstance.HARDWARE: | ||
| env_rel = fr3_hw_env( | ||
| ip=ROBOT_IP, | ||
| control_mode=ControlMode.CARTESIAN_TQuart, | ||
| robot_cfg=default_fr3_hw_robot_cfg(), | ||
| collision_guard="lab", | ||
| gripper_cfg=default_tilburg_hw_hand_cfg(), | ||
| max_relative_movement=0.5, | ||
| relative_to=RelativeTo.LAST_STEP, | ||
| ) | ||
| else: | ||
| env_rel = fr3_sim_env( | ||
| control_mode=ControlMode.CARTESIAN_TQuart, | ||
| robot_cfg=default_fr3_sim_robot_cfg(), | ||
| collision_guard=False, | ||
| gripper_cfg=default_fr3_sim_gripper_cfg(), | ||
| camera_set_cfg=default_mujoco_cameraset_cfg(), | ||
| max_relative_movement=0.5, | ||
| relative_to=RelativeTo.LAST_STEP, | ||
| ) | ||
| env_rel.get_wrapper_attr("sim").open_gui() | ||
|
|
||
| env_rel.reset() | ||
| print(env_rel.unwrapped.robot.get_cartesian_position()) # type: ignore | ||
| close_action: Union[int, list[float]] | ||
| open_action: Union[int, list[float]] | ||
| if default_tilburg_hw_hand_cfg().binary_action: | ||
| close_action = 0 | ||
| open_action = 1 | ||
| else: | ||
| template = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0] | ||
| value = 0.5 | ||
| close_action = [value * val for val in template] | ||
| open_action = [0.0] * len(template) | ||
|
|
||
| for _ in range(10): | ||
| for _ in range(10): | ||
| # move 1cm in x direction (forward) and close gripper | ||
| act = {"tquart": [0.01, 0, 0, 0, 0, 0, 1], "hand": close_action} | ||
| obs, reward, terminated, truncated, info = env_rel.step(act) | ||
| if truncated or terminated: | ||
| logger.info("Truncated or terminated!") | ||
| return | ||
| from time import sleep | ||
|
|
||
| sleep(5) | ||
| for _ in range(10): | ||
| # move 1cm in negative x direction (backward) and open gripper | ||
| act = {"tquart": [-0.01, 0, 0, 0, 0, 0, 1], "hand": open_action} | ||
| obs, reward, terminated, truncated, info = env_rel.step(act) | ||
| if truncated or terminated: | ||
| logger.info("Truncated or terminated!") | ||
| return | ||
|
|
||
|
|
||
| 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
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
Empty file.
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,68 @@ | ||
| from typing import Optional | ||
|
|
||
|
|
||
| class HandControl: | ||
| """ | ||
| Base class for hand control. | ||
| This class provides an interface for hand control, but does not implement any functionality. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| pass | ||
juelg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def grasp(self, value: Optional[float] = None): | ||
| self.value = value # to pass pylint | ||
juelg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| message = "This method should be overridden by subclasses." | ||
| raise NotImplementedError(message) | ||
|
|
||
| def set_zero_pos(self): | ||
| message = "This method should be overridden by subclasses." | ||
| raise NotImplementedError(message) | ||
|
|
||
| def disconnect(self): | ||
| message = "This method should be overridden by subclasses." | ||
| raise NotImplementedError(message) | ||
|
|
||
| def get_pos_vector(self): | ||
| message = "This method should be overridden by subclasses." | ||
| raise NotImplementedError(message) | ||
|
|
||
| def set_pos_vector(self, values: list[float]): | ||
| self.values = values # to pass pylint | ||
| message = "This method should be overridden by subclasses." | ||
| raise NotImplementedError(message) | ||
|
|
||
|
|
||
| class Hand: | ||
juelg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Hand Class | ||
| This class provides an interface for hand control. | ||
| It allows for grasping, resetting, and disconnecting from the hand. | ||
| """ | ||
|
|
||
| def __init__(self, hand: HandControl): | ||
| self._hand = hand | ||
|
|
||
| def grasp(self, value: Optional[float] = None): | ||
| self._hand.grasp(value) | ||
|
|
||
| def reset(self): | ||
| self._hand.set_zero_pos() | ||
|
|
||
| def get_state(self): | ||
| pass | ||
|
|
||
| def disconnect(self): | ||
| self._hand.disconnect() | ||
|
|
||
| def get_normalized_joints_poses(self): | ||
| self._hand.get_pos_vector() | ||
|
|
||
| def set_normalized_joints_poses(self, values: list): | ||
| self._hand.set_pos_vector(values) | ||
|
|
||
| def open(self): | ||
| self.reset() | ||
|
|
||
| def __del__(self): | ||
| self._hand.disconnect() | ||
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,11 @@ | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class THConfig(BaseModel): | ||
| """Config for the Tilburg hand""" | ||
|
|
||
| binary_action: bool = True | ||
juelg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| calibration_file_path: str = os.path.join(Path.home(), "tilburg_hand/calibration.json") | ||
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.