Skip to content

Commit dd808c2

Browse files
committed
Merge branch 'master' into start_full_configuration
2 parents 08811fd + 9e09666 commit dd808c2

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Unreleased
2929
* ``MoveItPlanner``: ``inverse_kinematics`` takes now instance of ``Configuration`` and ``robot``
3030
* Property :class:`compas_fab.robots.Robot.artist` does not try to scale robot
3131
geometry if links and/or joints are not defined.
32+
* In :class:``compas_fab.robots.constraints.JointConstraint``, added ``tolerance_above`` and
33+
``tolerance_below`` for allowing asymmetrical constraints.
34+
* In :class:``compas_fab.robots.Robot``, changed the ``constraints_from_configuration``
35+
function with ``tolerances_above`` and ``tolerances_below``.
3236

3337
**Removed**
3438

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
attrs>=19.3.0
12
sphinx_compas_theme>=0.4
23
sphinx>=1.6
34
invoke>=0.14

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
@@ -159,35 +159,40 @@ class JointConstraint(Constraint):
159159
The name of the joint this contraint refers to.
160160
value: float
161161
The targeted value for that joint.
162-
tolerance: float
163-
The bound to be achieved is [value - tolerance, value + tolerance]
162+
tolerance_above: float
163+
Tolerance above the targeted joint value, in radians. Defaults to 0.
164+
tolerance_below: float
165+
Tolerance below the targeted joint value, in radians. Defaults to 0.
166+
The bound to be achieved is [value - tolerance_below, value + tolerance_above].
164167
weight: float, optional
165168
A weighting factor for this constraint. Denotes relative importance to
166169
other constraints. Closer to zero means less important. Defaults to 1.
167170
168171
Examples
169172
--------
170173
>>> from compas_fab.robots import JointConstraint
171-
>>> jc = JointConstraint("joint_0", 1.4, 0.1)
174+
>>> jc = JointConstraint("joint_0", 1.4, 0.1, 0.1, 1.0)
172175
173176
"""
174177

175-
def __init__(self, joint_name, value, tolerance=0., weight=1.):
178+
def __init__(self, joint_name, value, tolerance_above=0., tolerance_below=0., weight=1.):
176179
super(JointConstraint, self).__init__(self.JOINT, weight)
177180
self.joint_name = joint_name
178181
self.value = value
179-
self.tolerance = tolerance
182+
self.tolerance_above = abs(tolerance_above)
183+
self.tolerance_below = abs(tolerance_below)
180184

181185
def scale(self, scale_factor):
182186
self.value *= scale_factor
183-
self.tolerance *= scale_factor
187+
self.tolerance_above *= scale_factor
188+
self.tolerance_below *= scale_factor
184189

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

188193
def copy(self):
189194
cls = type(self)
190-
return cls(self.joint_name, self.value, self.tolerance, self.weight)
195+
return cls(self.joint_name, self.value, self.tolerance_above, self.tolerance_below, self.weight)
191196

192197

193198
class OrientationConstraint(Constraint):

src/compas_fab/robots/robot.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -869,33 +869,40 @@ def constraints_from_frame(self, frame_WCF, tolerance_position, tolerances_axes,
869869
oc = self.orientation_constraint_from_frame(frame_WCF, tolerances_axes, group)
870870
return [pc, oc]
871871

872-
def constraints_from_configuration(self, configuration, tolerances, group=None):
872+
def constraints_from_configuration(self, configuration, tolerances_above, tolerances_below, group=None):
873873
"""Returns joint constraints on all joints of the configuration.
874874
875875
Parameters
876876
----------
877877
configuration: :class:`compas_fab.robots.Configuration`
878878
The target configuration.
879-
tolerances: list of float
880-
The tolerances (as +/-) on each of the joints defining the bound in radian
881-
to be achieved. If only one value is passed it will be used to create
882-
bounds for all joint constraints.
879+
tolerances_above: list of float
880+
The tolerances above the targeted configuration's joint value on each
881+
of the joints, defining the upper bound in radian to be achieved.
882+
If only one value is passed, it will be used to create upper bounds
883+
for all joint constraints.
884+
tolerances_below: list of float
885+
The tolerances below the targeted configuration's joint value on each
886+
of the joints, defining the upper bound in radian to be achieved.
887+
If only one value is passed, it will be used to create lower bounds
888+
for all joint constraints.
883889
group: str, optional
884890
The planning group for which we specify the constraint. Defaults to
885891
the robot's main planning group.
886892
887893
Examples
888894
--------
889895
>>> configuration = Configuration.from_revolute_values([-0.042, 4.295, -4.110, -3.327, 4.755, 0.])
890-
>>> tolerances = [math.radians(5)] * 6
896+
>>> tolerances_above = [math.radians(1)] * 6
897+
>>> tolerances_below = [math.radians(1)] * 6
891898
>>> group = robot.main_group_name
892-
>>> robot.constraints_from_configuration(configuration, tolerances, group)
893-
[JointConstraint('shoulder_pan_joint', -0.042, 0.08726646259971647, 1.0), \
894-
JointConstraint('shoulder_lift_joint', 4.295, 0.08726646259971647, 1.0), \
895-
JointConstraint('elbow_joint', -4.11, 0.08726646259971647, 1.0), \
896-
JointConstraint('wrist_1_joint', -3.327, 0.08726646259971647, 1.0), \
897-
JointConstraint('wrist_2_joint', 4.755, 0.08726646259971647, 1.0), \
898-
JointConstraint('wrist_3_joint', 0.0, 0.08726646259971647, 1.0)]
899+
>>> robot.constraints_from_configuration(configuration, tolerances_above, tolerances_below, group)
900+
[JointConstraint('shoulder_pan_joint', -0.042, 0.017453292519943295, 0.017453292519943295, 1.0), \
901+
JointConstraint('shoulder_lift_joint', 4.295, 0.017453292519943295, 0.017453292519943295, 1.0), \
902+
JointConstraint('elbow_joint', -4.11, 0.017453292519943295, 0.017453292519943295, 1.0), \
903+
JointConstraint('wrist_1_joint', -3.327, 0.017453292519943295, 0.017453292519943295, 1.0), \
904+
JointConstraint('wrist_2_joint', 4.755, 0.017453292519943295, 0.017453292519943295, 1.0), \
905+
JointConstraint('wrist_3_joint', 0.0, 0.017453292519943295, 0.017453292519943295, 1.0)]
899906
900907
Raises
901908
------
@@ -917,15 +924,20 @@ def constraints_from_configuration(self, configuration, tolerances, group=None):
917924
if len(joint_names) != len(configuration.values):
918925
raise ValueError("The passed configuration has %d values, the group %s needs however: %d" % (
919926
len(configuration.values), group, len(joint_names)))
920-
if len(tolerances) == 1:
921-
tolerances = tolerances * len(joint_names)
922-
elif len(tolerances) != len(configuration.values):
923-
raise ValueError("The passed configuration has %d values, the tolerances however: %d" % (
924-
len(configuration.values), len(tolerances)))
927+
if len(tolerances_above) == 1:
928+
tolerances_above = tolerances_above * len(joint_names)
929+
elif len(tolerances_above) != len(configuration.values):
930+
raise ValueError("The passed configuration has %d values, the tolerances_above however: %d" % (
931+
len(configuration.values), len(tolerances_above)))
932+
if len(tolerances_below) == 1:
933+
tolerances_below = tolerances_below * len(joint_names)
934+
elif len(tolerances_below) != len(configuration.values):
935+
raise ValueError("The passed configuration has %d values, the tolerances_below however: %d" % (
936+
len(configuration.values), len(tolerances_below)))
925937

926938
constraints = []
927-
for name, value, tolerance in zip(joint_names, configuration.values, tolerances):
928-
constraints.append(JointConstraint(name, value, tolerance))
939+
for name, value, tolerance_above, tolerance_below in zip(joint_names, configuration.values, tolerances_above, tolerances_below):
940+
constraints.append(JointConstraint(name, value, tolerance_above, tolerance_below))
929941
return constraints
930942

931943
# ==========================================================================
@@ -1254,9 +1266,10 @@ def plan_motion(self, goal_constraints, start_configuration=None,
12541266
1.0
12551267
>>> # Example with joint constraints (to the UP configuration)
12561268
>>> configuration = Configuration.from_revolute_values([0.0, -1.5707, 0.0, -1.5707, 0.0, 0.0])
1257-
>>> tolerances = [math.radians(5)] * 6
1269+
>>> tolerances_above = [math.radians(5)] * len(configuration.values)
1270+
>>> tolerances_below = [math.radians(5)] * len(configuration.values)
12581271
>>> group = robot.main_group_name
1259-
>>> goal_constraints = robot.constraints_from_configuration(configuration, tolerances, group)
1272+
>>> goal_constraints = robot.constraints_from_configuration(configuration, tolerances_above, tolerances_below, group)
12601273
>>> trajectory = robot.plan_motion(goal_constraints, start_configuration, group, planner_id='RRT')
12611274
>>> trajectory.fraction
12621275
1.0

0 commit comments

Comments
 (0)