blob: 49164bf62984edeb6d9caca3616de20ff95d9417 [file] [log] [blame]
James Kuszmaulea314d92019-02-18 19:45:06 -08001\documentclass{article}
2\usepackage[utf8]{inputenc}
3\usepackage{amsmath}
4\DeclareMathOperator{\sgn}{sgn}
5\usepackage{hyperref}
6\usepackage{enumitem}
7\usepackage{commath}
8\usepackage[margin=0.5in]{geometry}
9\title{Spline Math}
10\author{James Kuszmaul}
11\begin{document}
12
13\maketitle
14
15\section{Introductions}
16
17This document describes some of the math going on in computing constraints on
18the maximum velocities in \texttt{trajectory.*}. Some of the thoughts are
19somewhat disorganized and represent a stream-of-consciousness more than actually
20useful documentation.
21
22For a given path, we will have:
23
24\begin{tabular}{r|l}
25Name & Description \\ \hline
26$v_l$, $v_r$ & Left and right wheel velocities \\
27$\theta$ & Robot heading/yaw at a position along the path \\
28$r$ & Robot radius (assuming center of mass in center of robot) \\
29$u_l$, $u_r$ & Left and right wheel voltages \\
30$V_{max}$ & Maximum allowable voltage (typically 12V) \\
31$v_{max}$ & User-specified maximum velocity \\
32$u$ & $\begin{bmatrix} u_l \\ u_r \end{bmatrix}$ \\
33$A$, $B$ & LTI, matrices such that $\begin{bmatrix} \dot{v}_l \\ \dot{v}_r
34\end{bmatrix} = A \begin{bmatrix} v_l \\ v_r \end{bmatrix} + B u$ \\
35$s$ & Distance along the path \\
36\end{tabular}
37
38We are interested in discovering the fastest way to traverse the path in
39question, given constraints on:
40\begin{itemize}
41\item Friction limits of the wheels (assumed to static and time/velocity
42 invariant).
43\item Voltage limits on the motors.
44\item Maximum velocity.
45\end{itemize}
46
47The voltage constraints are essentially provided by the linear dynamics shown
48above:
49
50\begin{align}
51\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
52 A \begin{bmatrix} v_l \\ v_r \end{bmatrix} + B u
53\end{align}
54
55Also, at any given point we must maintain velocities/accelerations that actually
56allow us to follow the path (as opposed to optimizing $v_l$/$v_r$ separately...).
57
58Using the velocities of the individual wheels as a starting point, and
59introducing dummy variables for the velocity/acceleration of the center of the
60robot (corresponding to time derivatives of $s$):
61
62\begin{align*}
63v_c &= \frac{v_l r_r + v_r r_l}{r_r + r_l} \\
64\begin{bmatrix} v_l \\ v_r \end{bmatrix} &=
65 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
66\end{bmatrix} v_c \\
67\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
68 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
69 \end{bmatrix} \dot{v}_c + \begin{bmatrix} - r_l \frac{d^2\theta}{ds^2} v_c
70 \\ r_r \frac{d^2\theta}{ds^2} v_c \end{bmatrix} v_c \\
71\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
72 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
73 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2 \\
74\end{align*}
75
76And finally, we need to know the lateral accelerations of the two wheels as
77part of determining whether we would be breaking friction. Note that, because of
78the general assumptions we are making about the setup of the robot, the lateral
79acceleration on the two wheels will be identical (if they were not identical,
80that would imply the robot was tearing itself apart side-to-side).
81
82\begin{align*}
83a_{lat} &= \frac{d\theta}{ds} v_c^2 \\
84\end{align*}
85
86Finally, we need to be combine the lateral/longitudinal accelerations of each
87wheel to determine whether the wheel would break friction. While technically
88there is only one expression for this, as a practical matter we have a bit of
89leeway in defining exactly what the relationship should be (e.g., if we want
90separate max longitudinal/lateral accelerations, we can create an ellipse; we
91could also just create a raw rectangle and decouple the two, although that would
92probably be a particularly poor approximation of the actual dynamics). For now
93we will say that our friction is limited by some nonnegative convex function
94$g(a_{lat}, a_{lng}) \le 1$ for any given wheel.
95
96Summarizing our equations and constraints, we have:
97
98\begin{align*}
99v_c &= \frac{v_l r_r + v_r r_l}{r_r + r_l} \\
100a_{lat} &= \frac{d\theta}{ds} v_c^2 \\
101g(a_{lat}, \dot{v}_l) &\le 1 \\
102g(a_{lat}, \dot{v}_r) &\le 1 \\
103\abs{u_l} &\le V_{max} \\
104\abs{u_r} &\le V_{max} \\
105\begin{bmatrix} v_l \\ v_r \end{bmatrix} &= \begin{bmatrix} 1 - r_l
106 \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
107\end{bmatrix} v_c \\
108\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
109 A \begin{bmatrix} v_l \\ v_r \end{bmatrix} + B \begin{bmatrix} u_l \\ u_r
110 \end{bmatrix} \\
111\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
112 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
113 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2 \\
114\end{align*}
115
116With $v_l$, $v_r$, $u_l$, and $u_r$ free at all $s$ except the start and end, at
117which the velocities must
118be zero (technically, we could make do with allowing non-zero velocities, but
119then we could end up in situations that would be impossible to solve--because
120the splines have differentiable curvature, any of the splines we use will always
121have some valid velocity profile, but depending on the curvature, that velocity
122may be arbitrarily small).
123
124We can provide an upper limit on the goal velocity at any given point with the
125min of the specified max velocity and the lateral-acceleration limited velocity.
126This also gives an initial pass of the longitudinal accelerations that would be
127required to follow this profile.
128
129\begin{align*}
130v_{lat} &= \min (v_{max}, \sqrt{\frac{a_{lat,max}}{\frac{d\theta}{ds}}}) \\
131\dot{v}_{lat} &= \begin{cases} 0 & v_{lat} = v_{max} \\
132-\frac12 \sqrt{\frac{a_{lat,max}}{\frac{d\theta}{ds}^3}} \frac{d^2\theta}{ds^2}
133v_{lat} & v_{lat} \ne v_{max} \\
134\end{cases} \\
135&= \begin{cases} 0 & v_{lat} = v_{max} \\
136-\frac12 \frac{a_{lat,max}}{\frac{d\theta}{ds}^2} \frac{d^2\theta}{ds^2}
137 & v_{lat} \ne v_{max} \\
138\end{cases} \\
139\end{align*}
140
141If we start to consider accounting also for longitudinal accelerations, we can
142start with:
143
144\begin{align}
145\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
146 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
147 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2 \\
148(r_r + r_l)
149\left[ \begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
150 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
151 \end{bmatrix} \frac{\dot{v}_l r_r + \dot{v}_r r_l}{r_r + r_l} + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
152 \right] \\
153\begin{bmatrix}
154r_l + r_l r_r \frac{d\theta}{ds} & -r_l + r_lr_l \frac{d\theta}{ds} \\
155-r_r - r_r r_r \frac{d\theta}{ds} & r_r - r_r r_l \frac{d\theta}{ds} \\
156\end{bmatrix}
157\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
158 \begin{bmatrix} -r_l \\ r_r \end{bmatrix} (r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2 \\
159\begin{bmatrix}
1601 + r_r \frac{d\theta}{ds} & -1 + r_l \frac{d\theta}{ds} \\
161-1 - r_r \frac{d\theta}{ds} & 1 - r_l \frac{d\theta}{ds} \\
162\end{bmatrix}
163\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
164 \begin{bmatrix} -1 \\ 1 \end{bmatrix} (r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2 \\
165\begin{bmatrix}
1661 + r_r \frac{d\theta}{ds} & -1 + r_l \frac{d\theta}{ds} \\
1671 + r_r \frac{d\theta}{ds} & -1 + r_l \frac{d\theta}{ds} \\
168\end{bmatrix}
169\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
170 -(r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2 \\
171(1 + r_r \frac{d\theta}{ds}) \dot{v}_l + (-1 + r_l \frac{d\theta}{ds}) \dot{v}_r &=
172 -(r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2 \\
173%(1 + r \frac{d\theta}{ds}) \dot{v}_l + (-1 + r \frac{d\theta}{ds}) (2\dot{v}_c -
174%\dot{v}_l) &=
175% -2 r \frac{d^2\theta}{ds^2} v_c^2 \\
176%2 \dot{v}_l + 2(-1 + r \frac{d\theta}{ds}) \dot{v}_c
177% &= -2 r \frac{d^2\theta}{ds^2} v_c^2 \\
178%\dot{v}_l &= (1 - r \frac{d\theta}{ds}) \dot{v}_c - 2 r \frac{d^2\theta}{ds^2} v_c^2 \\
179%\dot{v}_r &= (1 + r \frac{d\theta}{ds}) \dot{v}_c + 2 r \frac{d^2\theta}{ds^2} v_c^2 \\
180\begin{bmatrix}
1811 & 0 \\
1820 & 1 \\
183-1 & 0 \\
1840 & -1 \\
185\end{bmatrix}
186\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &\le g'(v_c, s) \\
187\begin{bmatrix}
1881 & 0 \\
1890 & 1 \\
190-1 & 0 \\
1910 & -1 \\
192\end{bmatrix} \left(
193\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
194\end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
195\right) &\le g'(v_c, s)
196\end{align}
197
198Note how we have a linear relationship between $\dot{v}_l$ and $\dot{v}_r$,
199where the slope of the line between the two is constant at any given point on
200the path, but the y-intercept and the max/min bounds get tighter with speed.
201Furthermore, the velocity along the path ($v_c$) is a linear function of the
202wheel velocities $v_l$ and $v_r$. Thus, we can state, at any given point on the
203path, a lower velocity along the path will not decrease our acceleration
204bounds (if we are travelling in a straight line, then our speed does not affect
205the straight-line acceleration limits).
206
207We also can introduce the voltage constraints:
208
209\begin{align}
210\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
211 A \begin{bmatrix} v_l \\ v_r \end{bmatrix} + B \begin{bmatrix} u_l \\ u_r
212 \end{bmatrix} \\
213\begin{bmatrix} \dot{v}_l \\ \dot{v}_r \end{bmatrix} &=
214 A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
215 \end{bmatrix} v_c + B \begin{bmatrix} u_l \\ u_r \end{bmatrix} \\
216\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
217 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
218 &= A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
219 \end{bmatrix} v_c + B \begin{bmatrix} u_l \\ u_r \end{bmatrix} \\
220\end{align}
221
222With these constraints, we can no longer guarantee that the set of feasible
223velocities at any given point along the path is contiguous. However, we can
224guarantee that at any given point there will be at most 2 contiguous sets of
225valid velocities---in the case where there are two separate sets of allowable
226velocities, then one corresponds to the lower velocities which start at zero and
227go up until we can no longer use our finite available voltage to track the path.
228The second zone can occur at higher velocities where we are going so fast that
229the deceleration from the Back-EMF of the motor is enough to slow us down, but
230not so fast that we would lose friction.
231
232This divergence does technically create a bit of a challenge--if it were to,
233e.g., split into arbitrarily many possible paths than that would complicate the
234optimization problem substantially. However, because:
235\begin{enumerate}
236\item We only split into two branches at once; and
237\item we should only have a limited number of branchings for a given N-spline
238\footnote{I'll leave this as an exercise to the reader/my future self. However,
239logically, a spline with a given number of points can only have so many features
240and so should be able to have a very finite number of branchings.}.
241\end{enumerate}
242
243It should not actually be an issue to exhaustively attempt to plan for all
244possible branchings, knowing that the path of ``always follow the slower
245branch'' will always provide a feasible path, and choose whatever feasible plan
246is fastest.
247
248Once we choose which branch to take, it is a relatively simple matter of
249exercising the existing method. Essentially, taking the set of feasible
250velocities/accelerations as a starting point we do a forwards and backwards pass
251(order is unimportant)) where we start at our initial/terminal velocity, and
252accelerate forwards/decelerate backwards as hard as possible for each pass. If
253attempting to accelerate as hard as possible on the forwards pass (or,
254conversely, decelerate on the backwards) results in us violating the feasible
255velocity bounds, we can simply set the velocity at that point for that pass to
256the highest feasible velocity. We can guarantee that the pass in the opposite
257direction will \emph{not} get stuck at that same point because if that would
258suggest we had different physics going backwards than forwards, which is not the
259case\footnote{I'm too lazy to spell this logic out more carefully, and I don't
260think it is wrong. That is not guaranteed, however.}.
261
262\section{Specialization for Friction Circle}
263
264As our particular friction circle, we will attempt to use a straight
265ellipse\footnote{Note that this has numerical stability issues due to the
266infinite slope near zero}.
267With a $a_{lat,max}$ and $a_{lng,max}$ for the maximum lateral and longitudinal
268accelerations, i.e.:
269
270\begin{align*}
271g(a_{lat}, a_{lng}) &= \left(\frac{a_{lat}}{a_{lat,max}}\right)^2
272 + \left(\frac{a_{lng}}{a_{lng,max}}\right)^2 \\
273\end{align*}
274
275We care about turning this into a function of the path geometry and the current
276velocity that returns the max longitudinal acceleration and lets us calculate
277the friction-limited maximum acceleration, $v_{c,fmax}$. In order to do so, we
278note that, in order to be at the edge of a feasible velocity, we observe that,
279at any given $v_c$, we will have two pairs of constraints on the center-of-mass
280longitudinal acceleration that both must be met,
281corresponding to the fact that the each wheel creates an upper/lower bound
282on the valid accelerations of the center-of-mass of the robot, but at high
283$\frac{d^2\theta}{ds^2}v_c^2$, the constraints from each wheel may not overlap.
284Thus, we care about the $v_c$ such that the pairs of constraints \emph{just
285barely} overlap. This will happen when one constraint from the right wheel and
286one from the left are just on the edge of being violated; furthermore, of the
287four possible left/right pairings (+/- of left/right), only two pairs correspond
288to being on the edge of overlapping (the other two pairs correspond to, e.g.,
289having the upper acceleration limit in the same spot, as occurs when driving
290straight; in such a situation, there are plenty of valid accelerations, we just
291happen to start slipping both wheels at the same time). Which pair to look at is
292determined by the signs on $\dot{v}_c$--if they are the same (as would occur
293when going nearly straight), then we care about when the opposite limits
294overlap (e.g., upper limit on the left, lower on the right).
295
296\begin{align*}
297\dot{v}_l, \dot{v}_r &\le a_{lng, max} \sqrt{1 - \left(\frac{a_{lat}}{a_{lat,max}}\right)^2} \\
298\dot{v}_l, \dot{v}_r &\le a_{lng, max} \sqrt{1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2} \\
299 \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds} \\
300 -1 + r_l \frac{d\theta}{ds} \\ -1 - r_r \frac{d\theta}{ds}
301 \end{bmatrix} \dot{v}_c &\le \begin{bmatrix} r_l \\ -r_r \\ -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
302 + a_{lng, max} \sqrt{1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2} \\
3030 &= \pm \{r_l,r_r\} \frac{d^2\theta}{ds^2} v_{c,fmax}^2 + a_{lng, max} \sqrt{1 -
304 \left(\frac{\frac{d\theta}{ds}v_{c,fmax}^2}{a_{lat,max}}\right)^2} \\
305\left(\frac{d^2\theta}{ds^2} \frac{\{r_l,r_r\}v_{c,fmax}^2}{a_{lng, max}}\right)^2 &=
306 1 - \left(\frac{\frac{d\theta}{ds}v_{c,fmax}^2}{a_{lat,max}}\right)^2 \\
307v_{c,fmax} &= \min_{r \in \{r_l, r_r\}}
308\left(\left(\frac{d^2\theta}{ds^2} \frac{r}{a_{lng, max}}\right)^2 +
309 \left(\frac{\frac{d\theta}{ds}}{a_{lat,max}}\right)^2\right)^{-\frac14} \\
310\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
311\end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
312&= \begin{bmatrix}\pm 1 \\ \pm 1\end{bmatrix}
313 a_{lng, max} \sqrt{1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2} \\
314K_2 \dot{v}_c + K_1 v_c^2
315&= \begin{bmatrix}\pm 1 \\ \pm 1\end{bmatrix}
316 a_{lng, max} \sqrt{1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2} \\
317K_2' K_2 \dot{v}_c + K_2' K_1 v_c^2
318&= K_2' \begin{bmatrix}\pm 1 \\ \pm 1\end{bmatrix}
319 a_{lng, max} \sqrt{1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2} \\
320K_2' K_1 v_c^2
321&= K_2' \begin{bmatrix}\pm 1 \\ \pm 1\end{bmatrix}
322 a_{lng, max} \sqrt{1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2} \\
323\left(\frac{K_2' K_1 v_c^2}{K_2' \begin{bmatrix} 1 \\ \pm 1\end{bmatrix}a_{lng,max}}\right)^2
324&= 1 - \left(\frac{\frac{d\theta}{ds}v_c^2}{a_{lat,max}}\right)^2 \\
325v_c &= \min \left(
326\left(\frac{K_2'K_1}{K_2' \begin{bmatrix} 1 \\ \pm 1\end{bmatrix}a_{lng, max}}\right)^2 +
327 \left(\frac{\frac{d\theta}{ds}}{a_{lat,max}}\right)^2
328 \right)^{-\frac14}
329\end{align*}
330
331Where the $\pm 1$ term will have opposite signs of the two coefficients of
332$K_2$ have the same sign, and will have the same sign of the coefficients of
333$K_2$ have opposite signs.
334
335$K_2'$ refers to a transformed version of $K_2$ such that $K_2'K_2 = 0$ (see
336below for exact definition).
337
338\section{Calculating Feasible Voltage Velocities}
339
340Given:
341
342\begin{align*}
343\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
344 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
345 &= A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
346 \end{bmatrix} v_c + B \begin{bmatrix} u_l \\ u_r \end{bmatrix} \\
347\abs{u} &\le V_{max} \\
348\norm{B^{-1} \left(\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
349 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
350 - A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
351 \end{bmatrix} v_c\right) }_\infty \le V_{max} \\
352\end{align}
353
354This is a linear program for fixed $v_c$. We wish to determine the limits of
355$v_c$ for which the linear program will have a solution.
356
357In order to analyze this linear program in $\dot{v}_c$, it is useful to know the
358signs of the coefficients of $\dot{v}_c$, which in this case are
359$B^{-1} \begin{bmatrix}1 - r_l\frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}\end{bmatrix}$
360
361If either coefficient is zero, then for any given
362$v_c$, then the linear program
363becomes trivial, as the term with $\dot{v}_c$ will drop out of one of the rows
364and so the other row will be guaranteed to be valid for some $\dot{v}_c$ while
365the row with the dropped $\dot{v}_c$ will either be valid or not. If $B$ were
366the identity matrix, then this would
367correspond to situations where one wheel is stationary and the
368acceleration of that wheel is not affected by the overall acceleration along the
369path. Determining the limits of allowable velocities is then an issue of
370calculating the point at which the stationary wheel goes from being controllable
371to not, for a given overall velocity.
372
373Otherwise, the edge of feasibility will occur
374when the pair of constraints (where one pair is for the left voltage, one for
375the right) cross and so we will have each voltage as $\pm V_{max}$; if
376the signs of the coefficients differ, then we will have
377$u_l = u_r$. Otherwise, $u_l = -u_r$.
378
379For $u_l = u_r$, attempting to maximize $v_c$:
380\begin{align*}
381B^{-1} \left(\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
382 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
383 - A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
384 \end{bmatrix} v_c\right) &= \pm \begin{bmatrix} V_{max} \\ V_{max} \end{bmatrix} \\
385\begin{pmatrix} 1 + r_r\frac{d\theta}{ds} \\ r_l\frac{d\theta}{ds} - 1
386 \end{pmatrix}\left(
387\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
388 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
389 - A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
390 \end{bmatrix} v_c &= \pm B \begin{bmatrix} V_{max} \\ V_{max} \end{bmatrix}
391 \right) \\
392(r_l \frac{d\theta}{ds} - 1) (1 + r_r \frac{d\theta}{ds}) \dot{v}_c +
393 \begin{bmatrix} -r_l - r_lr_r\frac{d\theta}{ds} \\ -r_r +
394 r_lr_r\frac{d\theta}{ds} \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
395 - \begin{bmatrix} 1 + r_r \frac{d\theta}{ds} & 0 \\ 0 & r_l \frac{d\theta}{ds} - 1
396 \end{bmatrix} A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
397 \end{bmatrix} v_c &=
398 \begin{bmatrix} 1 + r_r \frac{d\theta}{ds} & 0 \\ 0 & r_l \frac{d\theta}{ds} - 1
399 \end{bmatrix} B
400 \begin{bmatrix} \pm V_{max} \\ \pm V_{max} \end{bmatrix}
401\end{align*}
402
403\begin{align*}
404 -(r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2
405 - ((1 + r_r\frac{d\theta}{ds})(A_{11}(1 - r_l\frac{d\theta}{ds}) + A_{12}(1 + r_r\frac{d\theta}{ds}))
406 + (r_l\frac{d\theta}{ds} - 1)(A_{12}(1 - r_l\frac{d\theta}{ds}) + A_{11}(1 + r_r\frac{d\theta}{ds}))
407 ) v_c &= \\
408 \pm V_{max}\frac{d\theta}{ds}(B_{12}r_l + B_{11}r_l + B_{11}r_r + B_{12}r_r) \\
409 (r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2 +
410 \frac{d\theta}{ds}( A_{11} (-r_l - r_r) + A_{12}(r_r + r_l) +
411 r_r(A_{11}(1 - r_l\frac{d\theta}{ds}) + A_{12}(1 + r_r\frac{d\theta}{ds})) +
412 r_l(A_{12}(1 - r_l\frac{d\theta}{ds}) + A_{11}(1 + r_r\frac{d\theta}{ds}))
413 ) v_c &= \\
414 (r_l + r_r) \frac{d^2\theta}{ds^2} v_c^2 +
415 \frac{d\theta}{ds}( (r_l + r_r) (A_{12} - A_{11}) +
416 A_{11}(r_l + r_r) + A_{12}(r_l + r_r) +
417 A_{12}\frac{d\theta}{ds}(r_r^2 - r_l^2)) v_c &= \\
418 (r_l + r_r) \left( \frac{d^2\theta}{ds^2} v_c^2 +
419 \frac{d\theta}{ds}A_{12}\left(2 +
420 \frac{d\theta}{ds}(r_r - r_l)\right) v_c\right) &= \\
421 \pm V_{max}(r_l + r_r)\frac{d\theta}{ds}(B_{11} + B_{12}) \\
422 \frac{d^2\theta}{ds^2} v_c^2 +
423 \frac{d\theta}{ds}A_{12}\left(2 + \frac{d\theta}{ds}(r_r - r_l)\right) v_c =
424 \pm V_{max}\frac{d\theta}{ds}(B_{11} + B_{12}) \\
425\end{align*}
426
427Note that when I eliminate parts of $A$ and $B$ I am taking advantage of the
428fact that different rows of $A$ and $B$ are just reordered version of one
429another (i.e., each is of the format $\begin{bmatrix} a & b \\ b & a
430\end{bmatrix}$).
431
432In the final equation, we then execute the quadratic formula for $v_c$.
433Note that if you write
434the quadratic formula out there will be up to 4 real solutions (the two
435solutions to the quadratic formula by the two $\pm V_{max}$ results); because
436of the placement of the $\pm V_{max}$, then
4370, 1, or 3 of the solutions will be greater than zero \footnote{The basic format of
438the quadratic formula
439in this case will be $b \pm \sqrt{b^2 \pm k}$ or some equivalent, and
440$0 < \abs{k} \le b^2$ ($\abs{k} \le b^$ is necessary to have 4 real solutions;
441and $k = 0$ only if
442$b$ also is zero, or if $V_{max} = 0$, which are not particularly
443relevant corner cases). If $b$ is positive,
444then 3 will be positive ($b +$ anything is positive, and since
445$\sqrt{b^2 - k} \le b$, $b - \sqrt{b^2 - k} \ge 0$, while $b - \sqrt{b^2 + k}
446\le 0$). A similar argument holds for negative $b$. If $b = 0$, then if there
447are four real solutions, all four are zero. If there are not four real
448solutions, then $\abs{k} > b^2$ and we have two real solutions. In this case,
449because $\sqrt{b^2 + k} > b$, we will have one positive and one negative
450solution.}. The zero positive solution case is not particularly interesting, as
451it only applies at zero curvature (which cannot apply here, as we already stated
452that $\abs{r\frac{d\theta}{ds}} > 1$ (or, if we have zero $V_{max}$). The one
453or three provide us our cutoffs for where there may be a gap in allowable
454accelerations.
455
456For situations where the coefficients have the same sign, attempting to maximize $v_c$:
457
458\begin{align*}
459(r_l \frac{d\theta}{ds} - 1) (1 + r_r \frac{d\theta}{ds}) \dot{v}_c +
460 \begin{bmatrix} -r_l - r_lr_r\frac{d\theta}{ds} \\ -r_r +
461 r_lr_r\frac{d\theta}{ds} \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
462 - \begin{bmatrix} 1 + r_r \frac{d\theta}{ds} & 0 \\ 0 & r_l \frac{d\theta}{ds} - 1
463 \end{bmatrix} A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
464 \end{bmatrix} v_c &=
465 \begin{bmatrix} 1 + r_r \frac{d\theta}{ds} & 0 \\ 0 & r_l \frac{d\theta}{ds} - 1
466 \end{bmatrix} B
467 \begin{bmatrix} \pm V_{max} \\ \mp V_{max} \end{bmatrix}
468\end{align*}
469
470\begin{align*}
471 (r_l + r_r) \left( \frac{d^2\theta}{ds^2} v_c^2 +
472 \frac{d\theta}{ds}A_{12}\left(2 +
473 \frac{d\theta}{ds}(r_r - r_l)\right) v_c\right) &=
474 \pm V_{max}(B_{11} - B_{12})(2 + \frac{d\theta}{ds}(r_r - r_l)) \\
475 \frac{d^2\theta}{ds^2} v_c^2 +
476 \frac{d\theta}{ds}A_{12}\left(2 +
477 \frac{d\theta}{ds}(r_r - r_l)\right) v_c &=
478 \pm V_{max}\frac{(B_{11} - B_{12})(2 + \frac{d\theta}{ds}(r_r - r_l))}{r_r + r_l}\\
479\end{align*}
480
481Where the same basic rules apply to the quadratic formula solutions.
482
483Considering situations where one of the rows in the equations disappear,
484we end up with the $\dot{v}_c$ term disappearing and
485we must solve the following equation for whichever row of $B^{-1}$ $B^{-1}_N$
486causes the $\dot{v}_c$ term to disappear:
487\begin{align*}
488B^{-1} &= \frac{1}{B_{11}^2 - B_{12}^2}\begin{bmatrix} B_{11} & -B_{12} \\
489 -B_{12} & B_{11} \end{bmatrix} \\
490B^{-1}_N\left(
491 \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
492 - A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\
493 1 + r_r \frac{d\theta}{ds} \end{bmatrix} v_c \right)
494 &= \pm V_{max} \\
495\end{align*}
496
497
498Trying to be more general:
499\begin{align*}
500B^{-1} \left(\begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
501 \end{bmatrix} \dot{v}_c + \begin{bmatrix} -r_l \\ r_r \end{bmatrix} \frac{d^2\theta}{ds^2} v_c^2
502 - A \begin{bmatrix} 1 - r_l \frac{d\theta}{ds} \\ 1 + r_r \frac{d\theta}{ds}
503 \end{bmatrix} v_c\right) &= \pm \begin{bmatrix} V_{max} \\ V_{max} \end{bmatrix} \\
504B^{-1} \left(K_2 \dot{v}_c + K_1 v_c^2 - A K_2 v_c\right) &=
505 \pm \begin{bmatrix} V_{max} \\ V_{max} \end{bmatrix} \\
506K_2' &= K_2^T \begin{bmatrix} 0 & 1 \\ -1 & 0 \end{bmatrix} \\
507K_2' \left(K_2 \dot{v}_c + K_1 v_c^2 - A K_2 v_c\right) &=
508 K_2' B \begin{bmatrix} \pm 1 \\ \pm 1 \end{bmatrix} V_{max} \\
509K_2' \left(K_2 \dot{v}_c + K_1 v_c^2 - A K_2 v_c\right) &=
510 K_2' B \begin{bmatrix} \pm 1 \\ \pm 1 \end{bmatrix} V_{max} \\
511K_2' \left(K_1 v_c^2 - A K_2 v_c\right) &=
512 K_2' B \begin{bmatrix} \pm 1 \\ \pm 1 \end{bmatrix} V_{max} \\
513 \end{align*}
514
515The quadratic formula coefficients:
516\begin{align*}
517a v_c^2 + b v_c + c &= 0 \\
518a &= K_2'K_1 \\
519b &= -K_2'AK_2 \\
520c &= -K_2' B \begin{bmatrix} \pm 1 \\ \pm 1 \end{bmatrix} V_{max} \\
521b^2 - 4 ac &= (K_2'AK_2)^2 + 4K_2'K_1 K_2'B \begin{bmatrix} \pm 1 \\ \pm 1 \end{bmatrix} V_{max} \\
522\end{align*}
523
524%Interestingly, the solutions for both basically devolve to:
525%\begin{align*}
526% \frac{d^2\theta}{ds^2} v_c^2 + 2 \frac{d\theta}{ds} A_{12} v_c
527% = \pm V_{max}\max(\abs{\frac{d\theta}{ds}}, 1)(B_{11} + B_{12}) \\
528%\end{align*}
529%
530%While not overly interesting, the moments when we will have a split in
531%feasibility will be at:
532%
533%\begin{align*}
534%0 < \abs{4V_{max}\max(\abs{\frac{d\theta}{ds}}, 1)(B_{11} +
535%B_{12})\frac{d^2\theta}{ds^2}} &\le \abs{2\frac{d\theta}{ds} A_{12}} \\
536%\abs{\frac{d\theta}{ds}} &\le 1 : \\
537%0 < \abs{2V_{max}(B_{11} + B_{12})\frac{d^2\theta}{ds^2}} &\le
538%\abs{\frac{d\theta}{ds} A_{12}} \\
539%\abs{\frac{d\theta}{ds}} &> 1 : \\
540%0 < \abs{2V_{max}(B_{11} + B_{12})\frac{d^2\theta}{ds^2}} &\le \abs{A_{12}} \\
541%\end{align*}
542%
543%Note that, in general, $A_{12}$ will be relatively small when compared to
544%$2V_{max}(B_{11} + B_{12})$.
545
546%\begin{align*}
547%B_{12} = B_{21} &, B_{11} = B_{22} \\
548%2 r \frac{d^2\theta}{ds^2} v_c^2 &= \pm 2V_{max}r\frac{d\theta}{ds} (B_{12} - B_{11}) \\
549%v_c &= \sqrt{\pm\frac{V_{max}\frac{d\theta}{ds}}{\frac{d^2\theta}{ds^2}} (B_{12} - B_{11})} \\
550%\end{align*}
551%
552%\begin{align*}
553%\begin{bmatrix} 1 - r^2 \frac{d\theta}{ds}^2 \\ 1 - r^2 \frac{d\theta}{ds}^2
554% \end{bmatrix} \dot{v}_c + \begin{bmatrix} -1 - r\frac{d\theta}{ds} \\ 1 -
555% r\frac{d\theta}{ds} \end{bmatrix} r \frac{d^2\theta}{ds^2} v_c^2
556% - A \begin{bmatrix} 1 - r^2 \frac{d\theta}{ds}^2 \\ 1 - r^2 \frac{d\theta}{ds}^2
557% \end{bmatrix} v_c &= B
558% \begin{bmatrix} \mp V_{max} (1 + r\frac{d\theta}{ds}) \\ \pm V_{max} (1 -
559% r\frac{d\theta}{ds}) \end{bmatrix} \\
560% 2 r \frac{d^2\theta}{ds^2} v_c^2
561% &= \pm V_{max}(B_{21} - B_{22} - B_{11} + B_{12}) \\
562% r \frac{d^2\theta}{ds^2} v_c^2
563% &= \pm V_{max}(B_{12} - B_{11}) \\
564%v_c &= \sqrt{\pm \frac{V_{max}}{r\frac{d^2\theta}{ds^2}} (B_{12} - B_{11})} \\
565%\end{align*}
566
567\end{document}