Skip to content

Commit 1f838e2

Browse files
committed
Generate pose macros in URDF
1 parent 71d9a44 commit 1f838e2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

clearpath_generator_common/clearpath_generator_common/semantic_description/generator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from clearpath_generator_common.common import BaseGenerator
3333
from clearpath_generator_common.description.writer import XacroWriter
3434
from clearpath_generator_common.semantic_description.manipulators import (
35+
ManipulatorPoseMacro,
3536
ManipulatorSemanticDescription
3637
)
3738

@@ -75,6 +76,14 @@ def generate_arms(self) -> None:
7576
path=arm_semantic_description.path,
7677
)
7778

79+
for pose in arm.poses:
80+
pose_macro = ManipulatorPoseMacro(arm, pose)
81+
self.xacro_writer.write_macro(
82+
macro=pose_macro.macro(),
83+
parameters=pose_macro.parameters(),
84+
blocks=pose_macro.blocks(),
85+
)
86+
7887
self.xacro_writer.write_macro(
7988
macro='{0}'.format(arm_semantic_description.model),
8089
parameters=arm_semantic_description.parameters,
@@ -101,6 +110,14 @@ def generate_grippers(self) -> None:
101110
path=gripper_semantic_description.path,
102111
)
103112

113+
for pose in arm.gripper.poses:
114+
pose_macro = ManipulatorPoseMacro(arm.gripper, pose)
115+
self.xacro_writer.write_macro(
116+
macro=pose_macro.macro(),
117+
parameters=pose_macro.parameters(),
118+
blocks=pose_macro.blocks(),
119+
)
120+
104121
self.xacro_writer.write_macro(
105122
macro='{0}'.format(gripper_semantic_description.model),
106123
parameters=gripper_semantic_description.parameters,

clearpath_generator_common/clearpath_generator_common/semantic_description/manipulators.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,31 @@
2929
# Redistribution and use in source and binary forms, with or without
3030
# modification, is not permitted without the express permission
3131
# of Clearpath Robotics.
32-
from clearpath_config.manipulators.types.manipulator import BaseManipulator
32+
from clearpath_config.manipulators.types.manipulator import (
33+
BaseManipulator,
34+
ManipulatorPose
35+
)
36+
37+
38+
class ManipulatorPoseMacro():
39+
40+
def __init__(self, manipulator: BaseManipulator, pose: ManipulatorPose) -> None:
41+
self.manipulator = manipulator
42+
self.pose = pose
43+
44+
def macro(self) -> str:
45+
return f"{self.manipulator.MANIPULATOR_MODEL}_group_state"
46+
47+
def parameters(self) -> dict:
48+
str_joints = [f'{joint:.4f}' for joint in self.pose.joints]
49+
return {
50+
'name': self.manipulator.name,
51+
'group_state': self.pose.name,
52+
'joint_positions': f"{{[{', '.join(str_joints)}]}}"
53+
}
54+
55+
def blocks(self) -> str:
56+
return None
3357

3458

3559
class ManipulatorSemanticDescription():

0 commit comments

Comments
 (0)