Skip to content

Commit 42e1234

Browse files
committed
beginning of major URDF refactor
1 parent 71d776a commit 42e1234

File tree

19 files changed

+766
-1814
lines changed

19 files changed

+766
-1814
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ urdf generic launch CLI test:
2525

2626
## Installation
2727

28+
#### Requirements
29+
ur, linear_slider, franka-emika
30+
2831
#### General use
2932
```
3033
python -m pip install .

main.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
2-
2+
from pybullet_tree_sim.camera import Camera
3+
from pybullet_tree_sim.time_of_flight import TimeOfFlight
34
from pybullet_tree_sim.pruning_environment import PruningEnv
45
from pybullet_tree_sim.tree import Tree
56
from pybullet_tree_sim.utils.pyb_utils import PyBUtils
@@ -11,16 +12,23 @@
1112
from zenlog import log
1213

1314

14-
def main():
15-
# TODO: CLI args?
16-
cam_dfov = 65
17-
cam_height = 8
18-
cam_width = 8
15+
def main():
16+
pbutils = PyBUtils(renders=False)
17+
18+
# Init sensors
19+
sensor_config = {
20+
"camera0": {
21+
'sensor': Camera(pbutils, sensor_name="realsense_d435i"),
22+
'tf_frame': "mock_pruner__camera0",
23+
}
24+
}
25+
1926

20-
pbutils = PyBUtils(renders=True, cam_width=cam_width, cam_height=cam_height, dfov=cam_dfov)
27+
2128
penv = PruningEnv(
22-
pbutils=pbutils, load_robot=True, robot_pos=[0, 1, 0], verbose=True, cam_width=cam_width, cam_height=cam_height
29+
pbutils=pbutils, load_robot=True, sensor_config=sensor_config, robot_pos=[0, 2, 0], verbose=True,
2330
)
31+
2432

2533
penv.activate_shape(shape="cylinder", radius=2 * 0.0254, height=2.0, orientation=[0, np.pi / 2, 0])
2634
# penv.load_tree(
@@ -43,14 +51,14 @@ def main():
4351
# Simulation loop
4452
while True:
4553
try:
46-
view_matrix = penv.ur5.get_view_mat_at_curr_pose(0, 0, [0, 0, 0])
54+
tof0_view_matrix = penv.robot.get_view_mat_at_curr_pose(camera=penv.robot.sensors['mock_pruner__camera0'])
4755
rgbd = penv.pbutils.get_rgbd_at_cur_pose(type="robot", view_matrix=view_matrix)
4856
keys_pressed = penv.get_key_pressed()
4957
action = penv.get_key_action(keys_pressed=keys_pressed)
5058
action = action.reshape((6, 1))
51-
jv, jacobian = penv.ur5.calculate_joint_velocities_from_ee_velocity_dls(end_effector_velocity=action)
52-
penv.ur5.action = jv
53-
singularity = penv.ur5.set_joint_velocities(penv.ur5.action)
59+
jv, jacobian = penv.robot.calculate_joint_velocities_from_ee_velocity_dls(end_effector_velocity=action)
60+
penv.robot.action = jv
61+
singularity = penv.robot.set_joint_velocities(penv.robot.action)
5462
penv.pbutils.pbclient.stepSimulation()
5563
time.sleep(0.01)
5664
except KeyboardInterrupt:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cart_prefix: cart__
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
base_type: linear_slider
2-
base_parent: world
32
base_prefix: linear_slider__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
eef_type: mock_pruner
2-
eef_parent: ur5e__
2+
eef_parent: ur5e__ # TODO: take care of __ in urdf
33
eef_prefix: mock_pruner__
44
tof0_offset_x: "0.02"
55
tof1_offset_x: "-0.02"

pybullet_tree_sim/config/robot/robot.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
robot_stack:
2+
# - farm-ng
3+
- cart
24
# - linear_slider
35
- ur5e
46
- mock_pruner
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
arm_type: ur5e
2-
# arm_parent: tool0
3-
arm_prefix: ur5e__
4-
tf_prefix: ur5e__
1+
ur_prefix: ur5e__
52
ur_type: ur5e

pybullet_tree_sim/pruning_environment.py

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
# angle_threshold_perp: float = 0.52,
5959
# angle_threshold_point: float = 0.52,
6060
pbutils: PyBUtils,
61+
sensor_config: dict,
6162
# cam_width: int = 424,
6263
# cam_height: int = 240,
6364
evaluate: bool = False,
@@ -106,23 +107,7 @@ def __init__(
106107
self.tree_count = tree_count
107108
self.is_goal_state = False
108109

109-
# sensor types
110-
self.sensor_attributes = {} # TODO: Load sensor types from config files
111-
camera_configs_path = os.path.join(CONFIG_PATH, "camera")
112-
camera_configs_files = glob.glob(os.path.join(camera_configs_path, "*.yaml"))
113-
for file in camera_configs_files:
114-
yamlcontent = yutils.load_yaml(file)
115-
for key, value in yamlcontent.items():
116-
self.sensor_attributes[key] = value
117-
118-
tof_configs_path = os.path.join(CONFIG_PATH, "tof")
119-
tof_configs_files = glob.glob(os.path.join(tof_configs_path, "*.yaml"))
120-
for file in tof_configs_files:
121-
yamlcontent = yutils.load_yaml(file)
122-
for key, value in yamlcontent.items():
123-
self.sensor_attributes[key] = value
124-
125-
# log.warning(self.sensor_attributes)
110+
126111

127112
# self.cam_width = cam_width
128113
# self.cam_height = cam_height
@@ -149,24 +134,47 @@ def __init__(
149134
"SUPPORT": None,
150135
}
151136

152-
# Tree parameters
153-
# self.tree_goal_pos = None
154-
# self.tree_goal_or = None
155-
# self.tree_goal_normal = None
156-
# self.tree_urdf_path: str | None = None
157-
# self.tree_pos = np.zeros(3, dtype=float)
158-
# self.tree_orientation = np.zeros(3, dtype=float)
159-
# self.tree_scale: float = 1.0
160-
161137
self.trees = {}
162138
self.debouce_time = 0.5
163139
self.last_button_push_time = time.time()
164140

165-
# UR5 Robot
141+
# Load Robot
166142
if load_robot:
167-
self.ur5 = self.load_robot(
168-
type=robot_type, robot_pos=robot_pos, robot_orientation=robot_orientation, randomize_pose=False
169-
)
143+
self.robot = Robot(pbclient=self.pbutils.pbclient)
144+
# self.ur5 = self.load_robot(
145+
# type=robot_type, robot_pos=robot_pos, robot_orientation=robot_orientation, randomize_pose=False
146+
# )
147+
148+
# Load all sensor attributes. # TODO: Load only the required sensor attributes
149+
self._load_sensor_attributes()
150+
151+
self.sensor_config = sensor_config
152+
self._assign_tf_frame_to_sensors(self.sensor_config)
153+
# log.warning(self.sensor_attributes)
154+
return
155+
156+
def _load_sensor_attributes(self):
157+
self.sensor_attributes = {}
158+
camera_configs_path = os.path.join(CONFIG_PATH, "camera")
159+
camera_configs_files = glob.glob(os.path.join(camera_configs_path, "*.yaml"))
160+
for file in camera_configs_files:
161+
yamlcontent = yutils.load_yaml(file)
162+
for key, value in yamlcontent.items():
163+
self.sensor_attributes[key] = value
164+
tof_configs_path = os.path.join(CONFIG_PATH, "tof")
165+
tof_configs_files = glob.glob(os.path.join(tof_configs_path, "*.yaml"))
166+
for file in tof_configs_files:
167+
yamlcontent = yutils.load_yaml(file)
168+
for key, value in yamlcontent.items():
169+
self.sensor_attributes[key] = value
170+
return
171+
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']
170178
return
171179

172180
def load_robot(self, type: str, robot_pos: ArrayLike, robot_orientation: ArrayLike, randomize_pose: bool = False):
@@ -182,7 +190,7 @@ def load_robot(self, type: str, robot_pos: ArrayLike, robot_orientation: ArrayLi
182190
# randomize_pose=randomize_pose,
183191
# verbose=self.verbose,
184192
# )
185-
robot = Robot()
193+
robot = Robot(pbclient=self.pbutils.pbclient)
186194

187195
else:
188196
raise NotImplementedError(f"Robot type {type} not implemented")
@@ -208,7 +216,7 @@ def load_tree( # TODO: Clean up Tree init vs create_tree, probably not needed.
208216
if tree_urdf_path is not None:
209217
if not os.path.exists(tree_urdf_path):
210218
raise OSError(
211-
f"There do not seem to be any files of that name, please check your path. Given path was {tree_urdf_path}"
219+
f"There do not seem to be any files of that name, please check your path: {tree_urdf_path}"
212220
)
213221

214222
# Get tree object
@@ -567,10 +575,6 @@ def get_key_action(self, keys_pressed: list) -> np.ndarray:
567575
keys_pressed = []
568576
return action
569577

570-
def run_sim(self) -> int:
571-
572-
return 0
573-
574578

575579
def main():
576580
# data = np.zeros((cam_width, cam_height), dtype=float)

0 commit comments

Comments
 (0)