Skip to content

Commit

Permalink
change the logic to determine whether an object is grasped successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
cc299792458 committed Oct 6, 2024
1 parent 41659f5 commit ab09a09
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 6 additions & 4 deletions tossingbot/envs/pybullet/tasks/toss_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self,
"workspace_length": 0.3,
"workspace_width": 0.4,
"workspace_position": [0.4, 0],
"workspace_thickness": 0.001,
"box_length": 0.25,
"box_width": 0.15,
"box_height": 0.1,
Expand Down Expand Up @@ -233,7 +234,7 @@ def load_workspace(self, length=0.3, width=0.4, height=0.02, position=[0.3, 0.0]
width (float): Width of the workspace.
position (list): Center position [x, y] of the workspace.
"""
thickness = 0.001
thickness = self.scene_config['workspace_thickness']
color = [0.8, 0.8, 0.8, 1.0]
self.workspace_ids = []

Expand Down Expand Up @@ -348,7 +349,7 @@ def reset_objects(self, init=False, margin=0.1):
p.removeBody(object_id)

self.object_ids = []
thickness = 0.001
thickness = self.scene_config['workspace_thickness']

for i in range(self.objects_config['n_object']):
object_type = random.randint(0, len(self.objects_config['object_types']) - 1)
Expand Down Expand Up @@ -418,7 +419,7 @@ def pre_simulation_process(self, action):

# Retrieve the depth value from the visual observation
# grasp_z = self.visual_observation['depth_heightmap'][pixel_y, pixel_x]
thickness = 0.001
thickness = self.scene_config['workspace_thickness']
grasp_z = 0.02 + thickness

# Define the grasp pose (position and yaw orientation), post grasp pose, throw pose, and throw velocity
Expand Down Expand Up @@ -679,7 +680,8 @@ def check_grasp_success(self):
if grasp_success:
object_ids = [
object_id for object_id in self.object_ids
if pose_distance(self.get_object_pose(object_id), self.robot.get_tcp_pose())[0] < 0.02
if pose_distance(self.get_object_pose(object_id), self.robot.get_tcp_pose())[0] < 0.1
and self.get_object_pose(object_id)[0][2] > 0.02 + self.scene_config['workspace_thickness'] + 0.001
]
assert len(object_ids) <= 1, "There should be exactly 1 object grasped."
if len(object_ids) == 0:
Expand Down
5 changes: 3 additions & 2 deletions tossingbot/experiments/toss_objects/grasp_heurstic.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def plot_throw_success(throw_success_history, target_positions):
use_gui = True
n_rotations = 1
phi_deg = 45 # Set phi_deg to 45 degrees
total_episodes = 100 # Reduced to a smaller number of episodes for heuristic testing
total_episodes = 100

# Create list to track the history of grasp successes, throw successes, and object poses
grasp_success_history = []
Expand All @@ -124,7 +124,8 @@ def plot_throw_success(throw_success_history, target_positions):
env = TossObjects(
use_gui=use_gui,
scene_config={'box_length': 0.15},
camera_config={'n_rotations': n_rotations}
objects_config={"object_types": ['ball', 'cube']},
camera_config={'n_rotations': n_rotations},
)

# Networks
Expand Down
8 changes: 4 additions & 4 deletions tossingbot/experiments/toss_objects/test_physics_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
n_rotations = 1
phi_deg = 45

total_episodes = 10 # Only test for 10 episodes
total_episodes = 100 # Test for 100 episodes

# Lists to track the success rates for the 10 episodes
# Lists to track the success rates
grasp_success_history = []
throw_success_history = []

Expand Down Expand Up @@ -96,5 +96,5 @@
avg_throw_success = np.mean(throw_success_history) if throw_success_history else 0.0

# Print final results
print(f"Average Grasp Success Rate: {avg_grasp_success:.3f}")
print(f"Average Throw Success Rate (for successful grasps): {avg_throw_success:.3f}")
print(f"Average Grasp Success Rate: {avg_grasp_success:.3f}") # Average Grasp Success Rate: 1.000
print(f"Average Throw Success Rate (for successful grasps): {avg_throw_success:.3f}") # Average Throw Success Rate (for successful grasps): 0.980
3 changes: 2 additions & 1 deletion tossingbot/experiments/toss_objects/train_physics_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def plot_success_rates(avg_grasp_success_history, avg_throw_success_history):
grasp_criterion = nn.CrossEntropyLoss()

# Optionally load the model
start_episode = load_model(agent, optimizer, log_dir)
start_episode = 0
# start_episode = load_model(agent, optimizer, log_dir, 'phyiscs_agent')

# Main loop
obs, info = env.reset()
Expand Down

0 comments on commit ab09a09

Please sign in to comment.