Skip to content

Commit 71d776a

Browse files
committed
assigned control joints. needs testing
1 parent 4cc2770 commit 71d776a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pybullet_tree_sim/robot.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464

6565
self.robot_conf = {}
6666
self._generate_robot_urdf()
67+
self._assign_control_joints()
6768
self.setup_robot()
6869

6970
return
@@ -93,9 +94,25 @@ def _generate_robot_urdf(self) -> None:
9394
robot_urdf = robot_urdf.toprettyxml()
9495

9596
# Save the generated URDF
97+
self.robot_urdf: str = robot_urdf
9698
self.robot_urdf_path = os.path.join(self._urdf_tmp_path, "robot.urdf")
9799
xutils.save_urdf(robot_urdf, urdf_path=self.robot_urdf_path)
98100
return
101+
102+
def _assign_control_joints(self) -> None:
103+
self.robot_conf['control_joints'] = []
104+
with open(self.robot_urdf_path) as f:
105+
for line in f:
106+
line = line.strip()
107+
if line.startswith('<joint') and "type=" in line:
108+
log.warn(line)
109+
joint_name = line.split('name="')[1].split('"')[0]
110+
joint_type = line.split('type="')[1].split('"')[0]
111+
if joint_type == 'fixed':
112+
continue
113+
else:
114+
self.robot_conf['control_joints'].append(joint_name)
115+
return
99116

100117
def setup_robot(self):
101118
if self.robot is not None:
@@ -155,7 +172,7 @@ def setup_robot(self):
155172
if self.verbose > 1:
156173
print("Joint Name: ", jointName, "Joint ID: ", jointID)
157174

158-
controllable = True if jointName in self.control_joints else False
175+
controllable = True if jointName in self.robot_conf["control_joints"] else False
159176
if controllable:
160177
self.controllable_joints_idxs.append(i)
161178
self.joint_lower_limits.append(jointLowerLimit)

0 commit comments

Comments
 (0)