Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/path_segment_8py_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 02:20:58 2016
Кодировка:

Поисковые слова: arp 220
lsst.tcc: python/tcc/mov/pathSegment.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pathSegment.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 import math
4 import coordConv
5 
6 __all__ = ["PathSegment"]
7 
8 class PathSegment(object):
9  """!A path segment of constant jerk
10 
11  Includes a few tid-bits of extra information, including the maximum |velocity|
12  during the segment, and optionally the position extremes during the segment
13  """
14  PosOvertravel = 1e-4 # amount to increase pMin or decrease pMax if that limit occurs partway through
15  # a move (rather than at an endpoint). This is to make sure one can move away from a limit.
16  # I think the main concern is roundoff error leading to pMin or pMax being slightly off,
17  # though I'm not positive. Certainly the checkSegment already includes the starting point
18  # when checking limits, which ought to suffice.
19  # In the old TCC it was 0.01 degrees, but I doubt there was justification for that.
20  # I'll assume roundoff error is the only issue and so use a much smaller value.
21 
22  def __init__(self, pA, vA, pB, vB, dt, doPos):
23  """!Construct a PathSegment
24 
25  @param[in] pA position of starting point at time t = 0 (deg)
26  @param[in] vA velocity of starting point at time t = 0 (deg/sec)
27  @param[in] pB position of ending point at time t = dt (deg)
28  @param[in] vB velocity of ending point at time t = dt (deg/sec)
29  @param[in] dt duration of motion (sec)
30  @param[in] doPos compute minimum and maximum position?
31 
32  @throw RuntimeError if computations would overflow (|dt| too small or |pA-pB| too big).
33 
34  Fields include all named arguments plus:
35  - aA acceleration of starting point at time t = 0 (deg/sec^2)
36  - j jerk (deg/sec^3)
37  - pMin mimimum position during the interval (deg) (None if doPos false);
38  increased by PosOvertravel if it occurs during the move (not at an endpoint).
39  - pMax maximum position during the interval (deg) (None if doPos false);
40  decreased by PosOvertravel if it occurs during the move (not at an endpoint).
41  - vPeak maximum |velocity| during the interval (deg/sec)
42  - aPeak maximum |acceleration| during the interval (deg/sec^2)
43 
44  History:
45  2013-12-06 ROwen convert from mov_path.for
46  """
47  self.pA = pA
48  self.vA = vA
49  self.pB = pB
50  self.vB = vB
51  self.dt = dt
52 
53  dt_sq = dt * dt
54 
55  # crude test for overflow of vx, aA, and j;
56  # assumes |numerator| < sqrt(bignum),
57  # tests |denominator| > sqrt(smallnum)
58  if abs(dt) < 1.0:
59  if dt_sq * dt_sq < coordConv.DoubleMin:
60  raise RuntimeError("dt=%r too small" % (dt,))
61 
62  # compute aA, j and aB
63  vx = (pB - pA) / dt
64  aA = (3.0 * vx - (2.0 * vA + vB)) * 2.0 / dt
65  j = (((vA + vB) / 2.0) - vx) * (12.0 / dt_sq)
66  aB = aA + (j * dt)
67 
68  #+
69  # compute maximum |velocity| (vPeak);
70  # this may occur at the endpoints or at time t_vex = - aA/j
71  #-
72  # compute t_vex and vex = v(t_vex);
73  # if t_vex is out of the range [0, dt), set t_vex = 0, so that vex = vA
74  if abs(aA) < abs(j * dt):
75  t_vex = max(-aA / j, 0.0)
76  else:
77  t_vex = 0.0
78  vex = vA + t_vex * (aA + (t_vex / 2.0) * j)
79 
80  self.aA = aA
81  self.j = j
82  self.pMin = None
83  self.pMax = None
84  self.vPeak = max(abs(vA), abs(vB), abs(vex))
85  self.aPeak = max(abs(aA), abs(aB))
86 
87  #+
88  # If desired, compute minimum and maximum position (pMin and pMax)
89  #-
90  # pMin and pMax may occur at the endpoints or at times t_pex1 or t_pex2
91  # (the two solutions to the quadratic equation v(t) = 0).
92  # Note that lim (j->0) t_pexArr = - vA / aA, yet the equation used below
93  # is ill-behaved at small j. Also, it's hard to distinguish the cases
94  # t_pexArr out of the range [0,dt], and t_pexArr unevaluatable.
95  # Rather than try, I simply use - vA / aA whenever the standard
96  # equation would not give me a reasonable answer
97  # (hence either t_pexArr = an endpoint, or =[0] - vA / aA;
98  # in the former case, - vA / aA simply won't give a maximal position).
99  if doPos:
100  t_pexArr = [0]*2
101  numArr = [0]*2
102  pexArr = [0]*2
103 
104  # compute the two times t_pexArr, and positions pexArr = p(t_pexArr);
105  # if a t_pexArr is out of range [0, dt), set it to 0 (so its pexArr = pA)
106  if abs(vA) < abs(aA * dt):
107  t_pex_zeroj = max(-vA / aA, 0.0)
108  else:
109  t_pex_zeroj = 0.0
110  sqrt_arg = (aA * aA) - (2.0 * vA * j)
111  if sqrt_arg < 0.0:
112  t_pexArr[0] = 0.0
113  t_pexArr[1] = 0.0
114  else:
115  sqrt_val = math.sqrt(sqrt_arg)
116  numArr[0] = -aA - sqrt_val
117  numArr[1] = -aA + sqrt_val
118  for branch in range(2):
119  if abs(numArr[branch]) < abs(j * dt):
120  t_pexArr[branch] = max(0.0, numArr[branch] / j)
121  else:
122  t_pexArr[branch] = t_pex_zeroj
123  for branch in range(2):
124  pexArr[branch] = pA + t_pexArr[branch] * (vA + (t_pexArr[branch] / 2.0) \
125  * (aA + (t_pexArr[branch] / 3.0) * j))
126 
127  self.pMin = min(pA, pB, pexArr[0] + self.PosOvertravel, pexArr[1] + self.PosOvertravel)
128  self.pMax = max(pA, pB, pexArr[0] - self.PosOvertravel, pexArr[1] - self.PosOvertravel)
129 
130  def __repr__(self):
131  return "PathSegment(pA=%s, vA=%s, pB=%s, vB=%s, dt=%s, doPos=%s)" % \
132  (self.pA, self.vA, self.pB, self.vB, self.dt, self.doPos)
133 
A path segment of constant jerk.
Definition: pathSegment.py:8
def __init__
Construct a PathSegment.
Definition: pathSegment.py:22