Skip to content

Commit f98018d

Browse files
author
David Butterworth
committed
Add SampleTimeGenerator() which generates a linear sequence of numbers.
1 parent d8fdf50 commit f98018d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/prpy/util.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,33 @@ def VanDerCorputSequence(lower=0.0, upper=1.0, include_endpoints=True):
10221022
return (scale * val + lower for val in chain(endpoints or [], raw_seq))
10231023

10241024

1025+
def SampleTimeGenerator(start, end, step=1):
1026+
"""
1027+
Generate a linear sequence of values from start to end, with
1028+
specified step size. Works with int or float values.
1029+
1030+
The end value is also returned if it's more than half the
1031+
distance from the previously returned value.
1032+
1033+
For example, on the interval [0.0,5.0], the sequence is:
1034+
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
1035+
1036+
@param float start: The start value of the sequence.
1037+
@param float end: The last value of the sequence.
1038+
@param float step: The step-size between values.
1039+
1040+
@returns generator: A sequence of float values.
1041+
"""
1042+
t = start
1043+
prev_t = 0.0
1044+
while t <= numpy.floor(end):
1045+
yield t
1046+
prev_t = t
1047+
t = t + step
1048+
if (end - float(prev_t)) > (step / 2.0):
1049+
yield float(end)
1050+
1051+
10251052
def GetCollisionCheckPts(robot, traj, include_start=True, start_time=0.,
10261053
first_step=None, epsilon=1e-6):
10271054
"""

0 commit comments

Comments
 (0)