Skip to content

Commit 0a33338

Browse files
authored
Merge pull request #130 from compas-dev/JointConstraint
Joint constraint
2 parents bf2673e + ab82257 commit 0a33338

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Unreleased
1919

2020
* Property :class:`compas_fab.robots.Robot.artist` does not try to scale robot
2121
geometry if links and/or joints are not defined.
22+
* In :class:``compas_fab.robots.constraints.JointConstraint``, added ``tolerance_above`` and
23+
``tolerance_below`` for allowing asymmetrical constraints
2224

2325
**Removed**
2426

src/compas_fab/backends/ros/messages/moveit_msgs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def from_joint_constraint(cls, joint_constraint):
270270
"""Creates a `JointConstraint` from a :class:`compas_fab.robots.JointConstraint`.
271271
"""
272272
c = joint_constraint
273-
return cls(c.joint_name, c.value, c.tolerance, c.tolerance, c.weight)
273+
return cls(c.joint_name, c.value, c.tolerance_above, c.tolerance_below, c.weight)
274274

275275

276276
class VisibilityConstraint(ROSmsg):

src/compas_fab/robots/constraints.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,35 +154,40 @@ class JointConstraint(Constraint):
154154
The name of the joint this contraint refers to.
155155
value: float
156156
The targeted value for that joint.
157-
tolerance: float
158-
The bound to be achieved is [value - tolerance, value + tolerance]
157+
tolerance_above: float
158+
Tolerance above the targeted joint value, in radians. Defaults to 0.
159+
tolerance_below: float
160+
Tolerance below the targeted joint value, in radians. Defaults to 0.
161+
The bound to be achieved is [value - tolerance_below, value + tolerance_above].
159162
weight: float, optional
160163
A weighting factor for this constraint. Denotes relative importance to
161164
other constraints. Closer to zero means less important. Defaults to 1.
162165
163166
Examples
164167
--------
165168
>>> from compas_fab.robots import JointConstraint
166-
>>> jc = JointConstraint("joint_0", 1.4, 0.1)
169+
>>> jc = JointConstraint("joint_0", 1.4, 0.1, 0.1, 1.0)
167170
168171
"""
169172

170-
def __init__(self, joint_name, value, tolerance=0., weight=1.):
173+
def __init__(self, joint_name, value, tolerance_above=0., tolerance_below=0., weight=1.):
171174
super(JointConstraint, self).__init__(self.JOINT, weight)
172175
self.joint_name = joint_name
173176
self.value = value
174-
self.tolerance = tolerance
177+
self.tolerance_above = abs(tolerance_above)
178+
self.tolerance_below = abs(tolerance_below)
175179

176180
def scale(self, scale_factor):
177181
self.value /= scale_factor
178-
self.tolerance /= scale_factor
182+
self.tolerance_above /= scale_factor
183+
self.tolerance_below /= scale_factor
179184

180185
def __repr__(self):
181-
return "JointConstraint('{0}', {1}, {2}, {3})".format(self.joint_name, self.value, self.tolerance, self.weight)
186+
return "JointConstraint('{0}', {1}, {2}, {3}, {4})".format(self.joint_name, self.value, self.tolerance_above, self.tolerance_below, self.weight)
182187

183188
def copy(self):
184189
cls = type(self)
185-
return cls(self.joint_name, self.value, self.tolerance, self.weight)
190+
return cls(self.joint_name, self.value, self.tolerance_above, self.tolerance_below, self.weight)
186191

187192

188193
class OrientationConstraint(Constraint):

0 commit comments

Comments
 (0)