Skip to content

Commit 7b89344

Browse files
committed
current updates for cindy code review
1 parent 9c33742 commit 7b89344

File tree

8 files changed

+104
-84
lines changed

8 files changed

+104
-84
lines changed

main.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pybullet_tree_sim.camera import Camera
33
from pybullet_tree_sim.time_of_flight import TimeOfFlight
44
from pybullet_tree_sim.pruning_environment import PruningEnv
5+
from pybullet_tree_sim.robot import Robot
56
from pybullet_tree_sim.tree import Tree
67
from pybullet_tree_sim.utils.pyb_utils import PyBUtils
78
from pybullet_tree_sim.utils.camera_helpers import get_fov_from_dfov
@@ -20,13 +21,27 @@ def main():
2021
"camera0": {
2122
'sensor': Camera(pbutils, sensor_name="realsense_d435i"),
2223
'tf_frame': "mock_pruner__camera0",
24+
},
25+
'tof0': {
26+
'sensor': TimeOfFlight(pbutils, sensor_name="vl6180"),
27+
'tf_frame': "mock_pruner__tof0",
28+
},
29+
'tof1': {
30+
'sensor': TimeOfFlight(pbutils, sensor_name="vl6180"),
31+
'tf_frame': "mock_pruner__tof1",
2332
}
2433
}
2534

35+
robots = {
36+
'pruning_robot': Robot(
37+
pbclient=pbutils.pbclient,
38+
sensor_config=sensor_config,
39+
position = [0, 1, 0],
40+
orientation = [0, 0, 0, 1])
41+
}
2642

27-
2843
penv = PruningEnv(
29-
pbutils=pbutils, load_robot=True, sensor_config=sensor_config, robot_pos=[0, 2, 0], verbose=True,
44+
pbutils=pbutils, robots=robots, verbose=True,
3045
)
3146

3247

@@ -48,25 +63,25 @@ def main():
4863
pbutils.pbclient.stepSimulation()
4964
time.sleep(0.1)
5065

51-
time.sleep(30)
52-
66+
# time.sleep(30)
67+
robot = penv.robots['pruning_robot']
5368
# Simulation loop
5469
while True:
5570
try:
56-
tof0_view_matrix = penv.robot.get_view_mat_at_curr_pose(camera=penv.robot.sensors['mock_pruner__camera0'])
57-
rgbd = penv.pbutils.get_rgbd_at_cur_pose(type="robot", view_matrix=view_matrix)
71+
sensor_view_matrix = robot.get_view_mat_at_curr_pose(camera=robot.sensors['mock_pruner__camera0'])
72+
rgbd = penv.pbutils.get_rgbd_at_cur_pose(camera=robot.sensors['mock_pruner__camera0'], type="robot", view_matrix=sensor_view_matrix)
5873
keys_pressed = penv.get_key_pressed()
59-
action = penv.get_key_action(keys_pressed=keys_pressed)
74+
action = penv.get_key_action(robot=robot, keys_pressed=keys_pressed)
6075
action = action.reshape((6, 1))
61-
jv, jacobian = penv.robot.calculate_joint_velocities_from_ee_velocity_dls(end_effector_velocity=action)
62-
penv.robot.action = jv
63-
singularity = penv.robot.set_joint_velocities(penv.robot.action)
76+
joint_vel, jacobian = robot.calculate_joint_velocities_from_ee_velocity_dls(end_effector_velocity=action)
77+
robot.action = joint_vel
78+
singularity = robot.set_joint_velocities(robot.action)
6479
penv.pbutils.pbclient.stepSimulation()
6580
time.sleep(0.01)
6681
except KeyboardInterrupt:
6782
break
6883

69-
# penv.deactivate_tree(tree_id_str="LPy_envy_tree1")
84+
# penv.deactivate_tree(tree_id_str="LPy_tree1")
7085
penv.pbutils.pbclient.disconnect()
7186
return
7287

pybullet_tree_sim/pruning_environment.py

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,45 @@ class PruningEnv(gym.Env):
5555

5656
def __init__(
5757
self,
58-
# angle_threshold_perp: float = 0.52,
59-
# angle_threshold_point: float = 0.52,
6058
pbutils: PyBUtils,
61-
sensor_config: dict,
62-
# cam_width: int = 424,
63-
# cam_height: int = 240,
64-
evaluate: bool = False,
65-
# distance_threshold: float = 0.05,
66-
max_steps: int = 1000,
59+
# max_steps: int = 1000,
6760
make_trees: bool = False,
6861
name: str = "PruningEnv",
69-
num_trees: int | None = None,
62+
# num_trees: int | None = None,
7063
renders: bool = False,
7164
tree_count: int = 10,
7265
# tree_urdf_path: str | None = None,
7366
# tree_obj_path: str | None = None,
7467
verbose: bool = True,
75-
load_robot: bool = True,
76-
robot_type: str = "ur5",
77-
robot_pos: ArrayLike = np.array([0, 0, 0]),
78-
robot_orientation: ArrayLike = np.array([0, 0, 0, 1]),
68+
# load_robot: bool = True,
69+
robots: dict = {},
70+
# robot_type: str = "ur5",
71+
# robot_pos: ArrayLike = np.array([0, 0, 0]),
72+
# robot_orientation: ArrayLike = np.array([0, 0, 0, 1]),
7973
# use_ik: bool = True,
8074
#
8175
) -> None:
8276
"""Initialize the Pruning Environment
8377
8478
Parameters
8579
----------
86-
cam_width (int): Pixel width of the camera
87-
cam_height (int): Pixel height of the camera
88-
evaluate (bool): Is this environment for evaluation
89-
max_steps (int): Maximum number of steps in a single run
90-
name (str): Name of the environment (default="PruningEnv")
91-
renders (bool): Whether to render the environment
92-
tree_count (int): Number of trees to be loaded
80+
...
9381
"""
9482
super().__init__()
9583
self.pbutils = pbutils
9684

9785
# Pybullet GUI variables
9886
self.render_mode = "rgb_array"
9987
self.renders = renders
100-
self.eval = evaluate
88+
# self.eval = evaluate
10189

10290
# Gym variables
10391
self.name = name
104-
self.step_counter = 0
105-
self.global_step_counter = 0
92+
# self.step_counter = 0
93+
# self.global_step_counter = 0
10694
# self.max_steps = max_steps
10795
self.tree_count = tree_count
108-
self.is_goal_state = False
96+
# self.is_goal_state = False
10997

11098

11199

@@ -138,18 +126,19 @@ def __init__(
138126
self.debouce_time = 0.5
139127
self.last_button_push_time = time.time()
140128

141-
# Load Robot
142-
if load_robot:
143-
self.robot = Robot(pbclient=self.pbutils.pbclient)
129+
# Load Robots
130+
self.robots = robots
131+
# if load_robot:
132+
# self.robot = Robot(pbclient=self.pbutils.pbclient)
144133
# self.ur5 = self.load_robot(
145134
# type=robot_type, robot_pos=robot_pos, robot_orientation=robot_orientation, randomize_pose=False
146135
# )
147-
136+
148137
# Load all sensor attributes. # TODO: Load only the required sensor attributes
149138
self._load_sensor_attributes()
150139

151-
self.sensor_config = sensor_config
152-
self._assign_tf_frame_to_sensors(self.sensor_config)
140+
log.warn(self.robots['pruning_robot'].sensors)
141+
# self.sensor_config = sensor_config
153142
# log.warning(self.sensor_attributes)
154143
return
155144

@@ -169,13 +158,6 @@ def _load_sensor_attributes(self):
169158
self.sensor_attributes[key] = value
170159
return
171160

172-
def _assign_tf_frame_to_sensors(self, sensor_config: dict):
173-
for sensor_name, conf in sensor_config.items():
174-
sensor = conf['sensor']
175-
sensor.tf_frame = conf['tf_frame']
176-
log.warn(f"{sensor.params}")
177-
sensor.tf_frame_index = self.robot.robot_conf['joint_info']['mock_pruner__base--camera0']['id']
178-
return
179161

180162
def load_robot(self, type: str, robot_pos: ArrayLike, robot_orientation: ArrayLike, randomize_pose: bool = False):
181163
"""Load a robot into the environment. Currently only UR5 is supported. TODO: Add Panda"""
@@ -468,7 +450,7 @@ def compute_deprojected_point_mask(self):
468450
# point_mask = np.expand_dims(point_mask_resize, axis=0).astype(np.float32)
469451
return point_mask
470452

471-
def is_reachable(self, vertex: Tuple[np.ndarray], base_xyz: np.ndarray) -> bool:
453+
def is_reachable(self, robot: Robot, vertex: Tuple[np.ndarray], base_xyz: np.ndarray) -> bool:
472454
# if vertex[3] != "SPUR":
473455
# return False
474456
ur5_base_pos = np.array(base_xyz)
@@ -479,7 +461,7 @@ def is_reachable(self, vertex: Tuple[np.ndarray], base_xyz: np.ndarray) -> bool:
479461
if dist >= 0.98: # TODO: is this for the UR5? Should it be from a parameter file?
480462
return False
481463

482-
j_angles = self.robot.calculate_ik(vertex[0], None)
464+
j_angles = robot.calculate_ik(vertex[0], None)
483465
# env.ur5.set_joint_angles(j_angles)
484466
# for _ in range(100):
485467
# pyb.con.stepSimulation()
@@ -509,7 +491,7 @@ def get_key_pressed(self, relevant=None) -> list:
509491
keys_pressed.append(key)
510492
return keys_pressed
511493

512-
def get_key_action(self, keys_pressed: list) -> np.ndarray:
494+
def get_key_action(self, robot: Robot, keys_pressed: list) -> np.ndarray:
513495
"""Return an action based on the keys pressed."""
514496
action = np.array([0.0, 0.0, 0, 0.0, 0.0, 0.0])
515497
if keys_pressed:
@@ -540,9 +522,9 @@ def get_key_action(self, keys_pressed: list) -> np.ndarray:
540522
if ord("p") in keys_pressed:
541523
if time.time() - self.last_button_push_time > self.debouce_time:
542524
# Get view and projection matrices
543-
view_matrix = self.ur5.get_view_mat_at_curr_pose(pan=0, tilt=0, xyz_offset=[0, 0, 0])
525+
view_matrix = robot.get_view_mat_at_curr_pose(camera=robot.sensors['camera0']['sensor'])
544526
log.warning(f"button p pressed")
545-
rgb, depth = self.pbutils.get_rgbd_at_cur_pose(type="robot", view_matrix=view_matrix)
527+
rgb, depth = self.pbutils.get_rgbd_at_cur_pose(camera=robot.sensors['camera0']['sensor'], type="robot", view_matrix=view_matrix)
546528
# log.debug(f'depth:\n{depth}')
547529
depth = -1 * depth.reshape((self.cam_width * self.cam_height, 1), order="F")
548530
world_points = self.deproject_pixels_to_points(

pybullet_tree_sim/robot.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Robot:
2222
def __init__(
2323
self,
2424
pbclient,
25+
sensor_config: dict = {},
2526
# robot_type: str,
2627
# robot_urdf_path: str,
2728
# tool_link_name: str,
@@ -32,7 +33,7 @@ def __init__(
3233
# robot_collision_filter_idxs,
3334
# init_joint_angles: Optional[list] = None,
3435
position=(0, 0, 0),
35-
orientation=(0, 0, 0, 1),
36+
orientation=(0, 0, 0, 1),
3637
randomize_pose=False,
3738
verbose=1
3839
# **kwargs
@@ -58,8 +59,10 @@ def __init__(
5859
# [0.063179, 0.077119, 0.0420027])
5960
self.verbose = verbose
6061

61-
self.joints = None
62+
6263
self.robot = None
64+
self.joints = None
65+
self.sensors = {}
6366
# self.robot_conf["control_joints"] = control_joints
6467
# self.robot_collision_filter_idxs = robot_collision_filter_idxs
6568
#
@@ -79,6 +82,9 @@ def __init__(
7982
self._assign_control_joints()
8083
self.setup_robot()
8184

85+
self._assign_tf_frame_to_sensors(sensor_config)
86+
log.warn(self.sensors)
87+
8288
self.action = None
8389

8490
return
@@ -130,6 +136,14 @@ def _generate_robot_urdf(self) -> None:
130136
xutils.save_urdf(robot_urdf, urdf_path=self.robot_urdf_path)
131137

132138
return
139+
140+
def _assign_tf_frame_to_sensors(self, sensor_config: dict):
141+
for sensor_name, conf in sensor_config.items():
142+
sensor = conf['sensor']
143+
sensor.tf_frame = conf['tf_frame']
144+
log.warn(f"{sensor.params}")
145+
sensor.tf_frame_index = self.robot_conf['joint_info']['mock_pruner__base--camera0']['id']
146+
return
133147

134148
def _assign_control_joints(self) -> None:
135149
self.robot_conf["control_joints"] = []
@@ -241,8 +255,8 @@ def setup_robot(self):
241255
)
242256
# self.joints[info.name] = info
243257

244-
import pprint as pp
245-
pp.pprint(self.robot_conf)
258+
# import pprint as pp
259+
# pp.pprint(self.robot_conf)
246260

247261
self.set_joint_angles_no_collision(self.init_joint_angles)
248262
self.pbclient.stepSimulation()
@@ -280,12 +294,17 @@ def _assign_collision_links(self):
280294
for i in range(num_joints):
281295
info = self.pbclient.getJointInfo(self.robot, i)
282296
child_link_name = info[12].decode('utf-8')
283-
297+
log.info(f"{child_link_name}, {i}")
284298
# This is kinda hacky, but it works for now. TODO: make better?
285-
if child_link_name.endswith('base'):
286-
self.robot_collision_filter_idxs.append((i, i-1))
287-
# self.robot_conf["joint_info"].update({child_link_name: i})
288-
log.warn(self.robot_collision_filter_idxs)
299+
# if child_link_name.endswith('base'):
300+
# self.robot_collision_filter_idxs.append((i, i-1))
301+
# log.warn(f'{child_link_name}, {i}')
302+
# if child_link_name.endswith('tool0'):
303+
# log.warn(f'{child_link_name}, {i}')
304+
# # self.robot_conf["joint_info"].update({child_link_name: i})
305+
# self.robot_collision_filter_idxs.append((25, 2))
306+
307+
# log.warn(self.robot_collision_filter_idxs)
289308
# log.warn()
290309
return
291310

pybullet_tree_sim/sensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def main():
4747

4848
sensor = Sensor(sensor_name="vl53l8cx", sensor_type="tof")
4949
print(sensor.params)
50+
51+
sensor = Sensor(sensor_name="vl6180", sensor_type="tof")
52+
print(sensor.params)
5053

5154
return
5255

pybullet_tree_sim/urdf/base_mounts/cart/macro/cart_macro.urdf.xacro

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33

44
<xacro:macro name="cart_macro" params="cart_prefix:='cart__' cart_parent:='world' mesh_base_path">
55
<!-- ================== -->
6-
<!-- Materials -->
6+
<!-- Cart Maacro -->
77
<!-- ================== -->
88
<material name="LightGrey">
99
<color rgba="0.7 0.7 0.7 1.0"/>
1010
</material>
11-
12-
<!-- ================== -->
13-
<!-- Properties -->
14-
<!-- ================== -->
1511
<xacro:property name="cart_mass" value="20.0"/>
1612
<xacro:property name="cart_collision_box_x" value='0.5'/>
1713
<xacro:property name="cart_collision_box_y" value='0.5'/>
@@ -24,14 +20,14 @@
2420

2521
<link name="${cart_prefix}cart">
2622
<visual>
27-
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
23+
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 ${cart_collision_box_z}"/>
2824
<geometry>
2925
<mesh filename="${mesh_base_path}/base_mounts/cart/cart.obj"/>
3026
</geometry>
3127
<material name="LightGrey"/>
3228
</visual>
3329
<collision>
34-
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
30+
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 -${cart_collision_box_z / 2}"/>
3531
<geometry>
3632
<box size="${cart_collision_box_x} ${cart_collision_box_y} ${cart_collision_box_z}"/>
3733
</geometry>

pybullet_tree_sim/urdf/end_effectors/dovetail_mount/macro/dovetail_mount_macro.urdf.xacro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106

107107

108108
<xacro:macro name="dovetail_mount_macro" params="parent_link dovetail_male_mount_prefix dovetail_female_mount_prefix mesh_base_path">
109+
<!-- =================== -->
110+
<!-- Dovetail Mount -->
111+
<!-- =================== -->
109112
<xacro:dovetail_male_mount_macro
110113
parent_link="${parent_link}"
111114
dovetail_male_mount_prefix="${dovetail_male_mount_prefix}"

0 commit comments

Comments
 (0)