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

Robot infra and env #7

Merged
merged 24 commits into from
Jan 21, 2024
Merged

Robot infra and env #7

merged 24 commits into from
Jan 21, 2024

Conversation

Leo428
Copy link
Collaborator

@Leo428 Leo428 commented Jan 11, 2024

In this PR, I added:

  1. Functionalities to command robotiq gripper in robot servers
  2. The base Franka + robotiq Gym environment
  3. All the realsense camera supports
  4. Relative coordinate transformation Gym env wrapper that enables all the cool results
  5. peg insert, pcb insert, and cable routing Gym envs.

Soon Charles will add in a new cleaner spacemouse utils and wrappers.

Thank you for reviewing! Happy New Year!

Copy link
Member

@youliangtan youliangtan left a comment

Choose a reason for hiding this comment

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

I made some code changes to this PR. Overall, this PR should be good to go. Robot env is usually very custom to individual setup, thus there is a limit on how this serl_robot_infra can be a generic library.

The best way for us is to document this, so that user knows how to create their own robot env, and then run it. User can optionally choose to utilize existing env_wrappers or utils in their custom robot env.

serl_robot_infra/README.md Show resolved Hide resolved
serl_robot_infra/README.md Show resolved Hide resolved
serl_robot_infra/franka_env/envs/franka_robotiq_env.py Outdated Show resolved Hide resolved
@Leo428
Copy link
Collaborator Author

Leo428 commented Jan 11, 2024

Thank you @youliangtan so much for the cleanups and suggestions! I will test the updated code on the robot tomorrow and make more improvements.

@youliangtan
Copy link
Member

I created a renamed edgeml, -> agentlace. Not sure if this is a better name 😅

Updated the name in this commit too: 3fa119d

self.action_scale = (0.02, 0.2, 1)

def crop_image(self, image):
return image[90:390, 170:470, :]
Copy link
Collaborator

Choose a reason for hiding this comment

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

crop_image() should be optional

Comment on lines 15 to 46
self._TARGET_POSE = np.array(
[
0.5668657154487453,
0.002050321710641817,
0.05462772570641611,
# 0.9998817571282431,-0.010581843089284471,0.008902600824764906,0.0067260729646395475
3.1279511,
0.0176617,
0.0212859,
]
)
self.resetpos[:3] = self._TARGET_POSE[:3]
self.resetpos[2] += 0.04
self.resetpos[3:] = euler_2_quat(self._TARGET_POSE[3:])

# Bouding box
self.xyz_bounding_box = gym.spaces.Box(
self._TARGET_POSE[:3]
- np.array([self.random_xy_range, self.random_xy_range, 0.005]),
self._TARGET_POSE[:3]
+ np.array([self.random_xy_range, self.random_xy_range, 0.05]),
dtype=np.float32,
)
rpy_delta_range = np.array([0.05, 0.05, self.random_rz_range])
self.rpy_bounding_box = gym.spaces.Box(
self._TARGET_POSE[3:] - rpy_delta_range,
self._TARGET_POSE[3:] + rpy_delta_range,
dtype=np.float32,
)

self._REWARD_THRESHOLD = [0.005, 0.005, 0.001, 0.1, 0.1, 0.1]
self.action_scale = (0.02, 0.2, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

like i said in the PR comments, we should probably get another python file and use a ConfigDict to encompass all experiment-related parameters, when we launch our experiments, we should only need python --config xxx.py

Comment on lines 52 to 82
# requests.post(self.url + "pcb_compliance_mode")
self.update_currpos()
reset_pose = copy.deepcopy(self.currpos)
reset_pose[2] += 0.03
self.interpolate_move(reset_pose, timeout=1.5)

# time.sleep(2)
requests.post(self.url + "precision_mode")
time.sleep(1) # wait for mode switching

reset_pose = self.resetpos.copy()
self.interpolate_move(reset_pose, timeout=1)

# perform random reset
if self.randomreset: # randomize reset position in xy plane
reset_pose[:2] += np.random.uniform(
-self.random_xy_range, self.random_xy_range, (2,)
)
euler_random = self._TARGET_POSE[3:].copy()
euler_random[-1] += np.random.uniform(
-self.random_rz_range, self.random_rz_range
)
reset_pose[3:] = euler_2_quat(euler_random)
self.interpolate_move(reset_pose, timeout=1)

if jpos:
requests.post(self.url + "precision_mode")
print("JOINT RESET")
requests.post(self.url + "jointreset")

requests.post(self.url + "pcb_compliance_mode")
Copy link
Collaborator

Choose a reason for hiding this comment

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

fix this

Comment on lines 21 to 39
]
)
self.resetpos[:3] = self._TARGET_POSE[:3]
self.resetpos[2] += 0.1
self.resetpos[3:] = euler_2_quat(self._TARGET_POSE[3:])

# Bouding box
self.xyz_bounding_box = gym.spaces.Box(
self._TARGET_POSE[:3]
- np.array([self.random_xy_range, self.random_xy_range, 0]),
self._TARGET_POSE[:3]
+ np.array([self.random_xy_range, self.random_xy_range, 0.1]),
dtype=np.float32,
)
rpy_delta_range = np.array([0.01, 0.01, self.random_rz_range])
self.rpy_bounding_box = gym.spaces.Box(
self._TARGET_POSE[3:] - rpy_delta_range,
self._TARGET_POSE[3:] + rpy_delta_range,
dtype=np.float32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

abstract this away in config file

serl_robot_infra/franka_env/envs/relative_env.py Outdated Show resolved Hide resolved
serl_robot_infra/franka_env/envs/relative_env.py Outdated Show resolved Hide resolved
serl_robot_infra/franka_env/envs/relative_env.py Outdated Show resolved Hide resolved
serl_robot_infra/franka_env/envs/relative_env.py Outdated Show resolved Hide resolved
@jianlanluo
Copy link
Collaborator

Can someone address my comment on putting env/experiment related config into a separate config file?

then we can just python --config PATH_TO_CONFIG.py

Signed-off-by: youliang <[email protected]>
@youliangtan
Copy link
Member

@Leo428 @charlesxu0124 In 752ded1. I briefly try to split out the config by having custom configs in both peg and pcb insertion examples:

  • examples/async_pcb_insert_drq/config.py and examples/async_peg_insert_drq/config.py.
  • we dont have an example of cable routing in the examples, so retain the config in the franka_cable_route.py for now
  • This is just the first iteration of organizing the config, most likely need another round of cleanup
  • did some cleans and fixes . definitely need to try test on robot


def go_to_rest(self, jpos=False):
# TODO: Implement this
return NotImplementedError
Copy link
Member

@youliangtan youliangtan Jan 18, 2024

Choose a reason for hiding this comment

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

I noticed that go_to_rest is not impl here added this TODO. Not sure if this is giving an issue.

Also I make the workspace boundary configurable in the config class. Best if we can test it on the robot to ensure everything still works fine.

@jianlanluo
Copy link
Collaborator

@youliangtan @Leo428 @charlesxu0124

are the required config changes done?

@youliangtan
Copy link
Member

Yes done. will need @Leo428 help to simply test it out the experiments to make sure things are not breaking.

@jianlanluo
Copy link
Collaborator

@Leo428 @charlesxu0124 can you test it tomorrow? then I believe we can close this PR

@Leo428
Copy link
Collaborator Author

Leo428 commented Jan 21, 2024

We are testing it right now along with BC baseline.

@Leo428
Copy link
Collaborator Author

Leo428 commented Jan 21, 2024

We refactor, fixed some minor mistakes, and tested the env config files. They should be good to merge now.

@Leo428
Copy link
Collaborator Author

Leo428 commented Jan 21, 2024

Once we merge this one, I will add BC training eval scripts, pick and place task, and vice agent (if it works) in the next PR.

@Leo428
Copy link
Collaborator Author

Leo428 commented Jan 21, 2024

@youliangtan hi youliang, can you take a look and merge it? Thanks

Copy link
Member

@youliangtan youliangtan left a comment

Choose a reason for hiding this comment

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

All good! Thanks for the commit

@youliangtan youliangtan merged commit 707d5f3 into main Jan 21, 2024
1 check passed
@youliangtan youliangtan deleted the robot_infra_and_env branch January 21, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants