Skip to content

Commit 152ea07

Browse files
committed
Moving wrap_to_interval from tsr code to prpy.util. Updating IsAtTrajectoryStart to use this function when comparing two orientations.
1 parent 3274ff2 commit 152ea07

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/prpy/tsr/tsr.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,6 @@
3636
EPSILON = 0.001
3737

3838

39-
def wrap_to_interval(angles, lower=-pi):
40-
"""
41-
Wraps an angle into a semi-closed interval of width 2*pi.
42-
43-
By default, this interval is `[-pi, pi)`. However, the lower bound of the
44-
interval can be specified to wrap to the interval `[lower, lower + 2*pi)`.
45-
46-
If `lower` is an array the same length as angles, the bounds will be
47-
applied element-wise to each angle in `angles`.
48-
49-
See: http://stackoverflow.com/a/32266181
50-
51-
@param angles an angle or 1D array of angles to wrap
52-
@type angles float or numpy.array
53-
@param lower optional lower bound on wrapping interval
54-
@type lower float or numpy.array
55-
"""
56-
return (angles - lower) % (2*pi) + lower
57-
58-
5939
class TSR(object):
6040
""" A Task-Space-Region (TSR) represents a motion constraint. """
6141
def __init__(self, T0_w=None, Tw_e=None, Bw=None,
@@ -82,6 +62,7 @@ def __init__(self, T0_w=None, Tw_e=None, Bw=None,
8262
Bw_interval = Bw_cont[3:6, 1] - Bw_cont[3:6, 0]
8363
Bw_interval = numpy.minimum(Bw_interval, 2*pi)
8464

65+
from prpy.util import wrap_to_interval
8566
Bw_cont[3:6, 0] = wrap_to_interval(Bw_cont[3:6, 0])
8667
Bw_cont[3:6, 1] = Bw_cont[3:6, 0] + Bw_interval
8768

@@ -200,6 +181,7 @@ def rpy_within_bounds(rpy, Bw):
200181
@return check a (3,) vector of True if within and False if outside
201182
"""
202183
# Unwrap rpy to Bw_cont.
184+
from prpy.util import wrap_to_interval
203185
rpy = wrap_to_interval(rpy, lower=Bw[:, 0])
204186

205187
# Check bounds condition on RPY component.
@@ -398,6 +380,7 @@ def sample_xyzrpy(self, xyzrpy=NANBW):
398380
if numpy.isnan(x) else x
399381
for i, x in enumerate(xyzrpy)])
400382
# Unwrap rpy to [-pi, pi]
383+
from prpy.util import wrap_to_interval
401384
Bw_sample[3:6] = wrap_to_interval(Bw_sample[3:6])
402385
return Bw_sample
403386

src/prpy/util.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def IsAtTrajectoryStart(robot, trajectory):
720720
return False
721721

722722
# Compare rotation distance
723-
rot_delta_value = (current_pose[2] - traj_start[2] + numpy.pi) % (2.*numpy.pi) - numpy.pi
723+
rot_delta_value = abs(wrap_to_interval(current_pose[2] - traj_start[2]))
724724
rot_resolution = robot.GetAffineRotationAxisResolution()[2] # Rotation about z?
725725
if rot_delta_value > rot_resolution:
726726
return False
@@ -1152,3 +1152,17 @@ def BodyPointsStateFromTraj(bodypoints, traj, time, derivatives=[0, 1, 2]):
11521152
"""
11531153
return BodyPointsStatesFromTraj(bodypoints, traj, (time,), derivatives)[0]
11541154

1155+
def wrap_to_interval(angles, lower=-numpy.pi):
1156+
"""
1157+
Wraps an angle into a semi-closed interval of width 2*pi.
1158+
By default, this interval is `[-pi, pi)`. However, the lower bound of the
1159+
interval can be specified to wrap to the interval `[lower, lower + 2*pi)`.
1160+
If `lower` is an array the same length as angles, the bounds will be
1161+
applied element-wise to each angle in `angles`.
1162+
See: http://stackoverflow.com/a/32266181
1163+
@param angles an angle or 1D array of angles to wrap
1164+
@type angles float or numpy.array
1165+
@param lower optional lower bound on wrapping interval
1166+
@type lower float or numpy.array
1167+
"""
1168+
return (angles - lower) % (2*numpy.pi) + lower

0 commit comments

Comments
 (0)