Skip to content

Commit 1f2ec65

Browse files
committed
Elegant!
1 parent 7699823 commit 1f2ec65

File tree

10 files changed

+16
-157
lines changed

10 files changed

+16
-157
lines changed

examples/example_aip_battery_task.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

scripts/reactive_tamp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
class REACTIVE_TAMP:
2222
def __init__(self, cfg) -> None:
23-
2423
self.sim = wrapper.IsaacGymWrapper(
2524
cfg.isaacgym,
2625
cfg.env_type,

scripts/sim.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
@hydra.main(version_base=None, config_path="../src/m3p2i_aip/config", config_name="config_point")
1919
def run_sim(cfg: ExampleConfig):
20-
2120
sim = wrapper.IsaacGymWrapper(
2221
cfg.isaacgym,
2322
cfg.env_type,
@@ -43,7 +42,6 @@ def run_sim(cfg: ExampleConfig):
4342
planner.run_tamp(
4443
torch_to_bytes(sim._dof_state), torch_to_bytes(sim._root_state))
4544
)
46-
# print("task", cfg.task, "action", action)
4745
sim.set_dof_velocity_target_tensor(action)
4846

4947
cfg.suction_active = bytes_to_torch(

src/m3p2i_aip/planners/motion_planner/cost_functions.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ def get_push_cost(self, sim: wrapper, block_goal: torch.tensor):
5454
self.calculate_dist(sim, block_goal)
5555

5656
# Force the robot behind block and goal, align_cost is actually cos(theta)+1
57-
# align_cost = align_weight[robot] * (cos_theta + 1) * 5
5857
align_cost = torch.zeros(self.num_samples, device=self.device)
5958
align_cost[self.cos_theta>0] = self.cos_theta[self.cos_theta>0]
60-
# print('push align', align_cost[:10])
61-
# ori_cost = skill_utils.get_general_ori_cube2goal(block_quat, goal_quaternion)
6259

63-
return 3 * self.dist_cost + 1 * align_cost #+ 10 * ori_cost# [num_envs] 31
60+
return 3 * self.dist_cost + 1 * align_cost
6461

6562
def get_pull_cost(self, sim: wrapper, block_goal: torch.tensor):
6663
self.calculate_dist(sim, block_goal)
@@ -83,16 +80,13 @@ def get_pull_cost(self, sim: wrapper, block_goal: torch.tensor):
8380
# Force the robot to be in the middle between block and goal, align_cost is actually 1-cos(theta)
8481
align_cost = torch.zeros(self.num_samples, device=self.device)
8582
align_cost[self.cos_theta<0] = -self.cos_theta[self.cos_theta<0] # (1 - cos_theta)
86-
# print('pull align', align_cost[-10:])
8783

8884
# Add the cost when the robot is close to the block and moves towards the block
8985
vel_cost = torch.zeros(self.num_samples, device=self.device)
9086
robot_block_close = robot_to_block_dist <= 0.5
9187
vel_cost[flag_towards_block*robot_block_close] = 0.6
9288

93-
# ori_cost = skill_utils.get_general_ori_cube2goal(block_quat, goal_quaternion)
94-
95-
return 3 * self.dist_cost + 3 * vel_cost + 7 * align_cost #+ 10 * ori_cost # [num_envs] 315
89+
return 3 * self.dist_cost + 3 * vel_cost + 7 * align_cost
9690

9791
def get_panda_reach_cost(self, sim, pre_pick_goal):
9892
ee_l_state = sim.get_actor_link_by_name("panda", "panda_leftfinger")
@@ -110,7 +104,6 @@ def get_panda_reach_cost(self, sim, pre_pick_goal):
110104
pre_pick_goal_1[2] += self.pre_height_diff
111105
pre_pick_goal_2[0] -= self.pre_height_diff * self.tilt_cos_theta
112106
pre_pick_goal_2[2] += self.pre_height_diff * (1 - self.tilt_cos_theta ** 2) ** 0.5
113-
# print("1", pre_pick_goal_1, "2", pre_pick_goal_2)
114107
pre_pick_goal[:self.half_samples, :] = pre_pick_goal_1
115108
pre_pick_goal[self.half_samples:, :] = pre_pick_goal_2
116109
reach_cost = torch.linalg.norm(ee_state[:,:3] - pre_pick_goal, axis = 1)

src/m3p2i_aip/planners/motion_planner/m3p2i.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,14 @@ def _multi_modal_exp_util(self, costs):
5454
total_costs_1 = traj_costs[:self.half_K] - torch.min(traj_costs[:self.half_K])
5555
total_costs_2 = traj_costs[self.half_K:] - torch.min(traj_costs[self.half_K:])
5656
total_costs = traj_costs - torch.min(traj_costs)
57-
# print('1', total_costs_1)
58-
# print('2', total_costs_2)
57+
5958
eta_1, exp_1 = self.update_infinite_beta(total_costs_1, self.beta_1, 10, 3)
6059
eta_2, exp_2 = self.update_infinite_beta(total_costs_2, self.beta_2, 10, 3)
6160
eta, exp_ = self.update_infinite_beta(total_costs, self.beta, 10, 3)
62-
# exp_ = torch.exp((-1.0/self.beta) * total_costs)
63-
# eta = torch.sum(exp_)
6461

6562
self.weights_1 = 1 / eta_1 * exp_1
6663
self.weights_2 = 1 / eta_2 * exp_2
6764
self.weights = 1 / eta * exp_
68-
# print('weights', self.weights.size())
6965

7066
def _update_multi_modal_distribution(self, costs, actions):
7167
"""

src/m3p2i_aip/planners/motion_planner/mppi.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __init__(self, cfg: MPPIConfig, dynamics: Callable, running_cost: Callable):
197197
self.eta_min = 0.01 # 1%
198198
self.lambda_mult = 0.1 # Update rate
199199

200-
# covariance update
200+
# Covariance update
201201
self.update_cov = cfg.update_cov # !! weird if set to True
202202
self.step_size_cov = 0.7
203203
self.kappa = 0.005
@@ -233,7 +233,7 @@ def command(self, state):
233233
action = self.U[:self.u_per_command]
234234

235235
elif self.mppi_mode == 'halton-spline':
236-
# shift command 1 time step [T, nu]
236+
# Shift command 1 time step [T, nu]
237237
self.mean_action = self._shift_action(self.mean_action)
238238
if self.multi_modal:
239239
self.mean_action_1 = self._shift_action(self.mean_action_1)
@@ -283,7 +283,7 @@ def _compute_rollout_costs(self, perturbed_actions):
283283
cost_horizon = torch.zeros([K, T], **self.tensor_args)
284284
cost_samples = cost_total
285285

286-
# allow propagation of a sample of states (ex. to carry a distribution), or to start with a single state
286+
# Allow propagation of a sample of states (ex. to carry a distribution), or to start with a single state
287287
if self.state.shape == (K, self.nx):
288288
state = self.state
289289
else:
@@ -314,13 +314,11 @@ def _compute_rollout_costs(self, perturbed_actions):
314314
ee_state = 'None' #(self.ee_l_state[:, :3] + self.ee_r_state[:, :3])/2 if self.ee_l_state != 'None' else 'None'
315315
ee_states.append(ee_state) if ee_state != 'None' else []
316316

317-
# Actions is K x T x nu
318-
# States is K x T x nx
319-
actions = torch.stack(actions, dim=-2)
320-
states = torch.stack(states, dim=-2)
317+
actions = torch.stack(actions, dim=-2) # [K, T, nu]
318+
states = torch.stack(states, dim=-2) # [K, T, nx]
321319
ee_states = torch.stack(ee_states, dim=-2) if ee_states != [] else 'None'
322320

323-
# action perturbation cost
321+
# Action perturbation cost
324322
if self.terminal_state_cost:
325323
c = self.terminal_state_cost(states, actions)
326324
cost_samples += c
@@ -405,7 +403,6 @@ def _compute_total_cost_batch_halton(self):
405403

406404
# Scales action within bounds. act_seq is the same as perturbed actions
407405
act_seq = scale_ctrl(act_seq, self.u_min, self.u_max, squash_fn=self.squash_fn)
408-
# print(act_seq.size())
409406

410407
if self.multi_modal:
411408
act_seq[0, :, :] = self.best_traj_1
@@ -473,8 +470,7 @@ def get_samples(self, sample_shape, **kwargs):
473470
device=self.device,
474471
float_dtype=torch.float32)
475472

476-
# Sample splines from knot points:
477-
# iteratre over action dimension:
473+
# Sample splines from knot points, iterate over action dimension:
478474
knot_samples = self.knot_points.view(sample_shape, self.nu, self.n_knots) # n knots is T/knot_scale (30/4 = 7)
479475
self.samples = torch.zeros((sample_shape, self.T, self.nu), **self.tensor_args)
480476
for i in range(sample_shape):
@@ -502,23 +498,21 @@ def _update_distribution(self, costs, actions):
502498
weighted_seq = self.weights.view(-1, 1, 1) * actions # [K, T, nu]
503499
new_mean = torch.sum(weighted_seq, dim=0)
504500

505-
# Gradient update for the mean
501+
# Update for the mean
506502
self.mean_action = (1.0 - self.step_size_mean) * self.mean_action +\
507503
self.step_size_mean * new_mean
508-
# print(self.mean_action.size()) # [T, nu]
509504

510505
delta = actions - self.mean_action.unsqueeze(0)
511506

512-
#Update Covariance
507+
# Update Covariance
513508
if self.update_cov:
514-
#Diagonal covariance of size AxA
509+
# Diagonal covariance of size AxA
515510
weighted_delta = self.weights * (delta ** 2).T
516511
# cov_update = torch.diag(torch.mean(torch.sum(weighted_delta.T, dim=0), dim=0))
517512
cov_update = torch.mean(torch.sum(weighted_delta.T, dim=0), dim=0)
518513

519514
self.cov_action = (1.0 - self.step_size_cov) * self.cov_action + self.step_size_cov * cov_update
520515
self.cov_action += self.kappa #* self.init_cov_action
521-
# self.cov_action[self.cov_action < 0.0005] = 0.0005
522516
self.scale_tril = torch.sqrt(self.cov_action)
523517

524518
return delta

src/m3p2i_aip/planners/task_planner/isaac_int_req_templates.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/m3p2i_aip/planners/task_planner/isaac_state_action_templates.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ def __init__(self):
170170
self.B[:, :, 2] = np.array([[1, 1, 1], # place
171171
[0, 0, 0],
172172
[0, 0, 0]])
173-
# self.B[:, :, 1] = np.array([[0, 0, 0], # pick
174-
# [1, 1, 1],
175-
# [0, 0, 0]])
176-
# self.B[:, :, 2] = np.array([[0, 0, 0], # place
177-
# [0, 0, 0],
178-
# [1, 1, 1]])
179173
# # Preconditions of the actions above
180174
# ----------------------------------------------------------
181175
self.preconditions = [['cube_at_goal'], ['cube_at_table'], ['cube_at_hand']]

src/m3p2i_aip/planners/task_planner/task_planner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
from m3p2i_aip.utils import skill_utils
44
from m3p2i_aip.planners.task_planner import ai_agent, adaptive_action_selection
5-
from m3p2i_aip.planners.task_planner import isaac_int_req_templates, isaac_state_action_templates
5+
from m3p2i_aip.planners.task_planner import isaac_state_action_templates
66

77
def set_task_planner(cfg):
88
if cfg.env_type == "point_env":

src/m3p2i_aip/utils/isaacgym_utils/isaacgym_wrapper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import List
44
from dataclasses import dataclass, field
55
import m3p2i_aip.utils.isaacgym_utils.actor_utils as actor_utils
6+
67
@dataclass
78
class IsaacGymConfig():
89
dt: float = 0.05 # 0.01
@@ -33,7 +34,6 @@ def parse_isaacgym_config(cfg: IsaacGymConfig, device: str = "cuda:0") -> gymapi
3334
# sim_params.physx.friction_offset_threshold = 0.01
3435
# sim_params.physx.friction_correlation_distance = 0.001
3536

36-
# return the configured params
3737
return sim_params
3838

3939
class IsaacGymWrapper:
@@ -175,7 +175,6 @@ def get_actor_link_by_name(self, actor_name: str, link_name: str):
175175
),
176176
device=self.device,
177177
)
178-
# print(rigid_body_idx)
179178
return self.get_rigid_body_by_rigid_body_index(rigid_body_idx)
180179

181180
def get_actor_contact_forces_by_name(self, actor_name: str, link_name: str):
@@ -221,7 +220,7 @@ def update_dyn_obs(self, i, period=100):
221220
)
222221

223222
def set_initial_joint_pose(self):
224-
# set initial joint poses
223+
# Set initial joint poses
225224
robots = [a for a in self.env_cfg if a.type == "robot"]
226225
for robot in robots:
227226
dof_state = []

0 commit comments

Comments
 (0)