# Optimizing engines to produce a certain torque and net force

Say we have $$n$$ engines sitting on a rigid body. Each engine has position $$R_i$$ and points in a certain direction and generates a force in that direction, $$F_i$$. The magnitude of that force ($$k_i$$) follows this constraint: $$0 \leq k_i \leq m_i$$. In other words, the engine can only output so much force.

I want to be able to find the values of $$k$$ that would bring the resultant force $$F$$ and torque $$T$$ closest to a desired value.

Based on the resultant force equation, I know that

$$F = \sum_{i=1}^{n} (k_iF_i)$$

and the torque:

$$T = \sum_{i=1}^{n} (R_i) \times (k_iF_i)$$

where $$R_i$$ is the position of the engine relative to the point of application of the resultant force.

However, I'm unsure of how to best proceed from here.

edit: I solved the problem one way using linear programming and minimizing the absolute value of the difference between each component of the ideal and actual force/torque, not optimizing for fuel. This allowed me to put constraints on the engine's force magnitude.

• Without loss of generality, you can set $R=0$ for a minor simplification. Now each $R_i$ would be defined relative to the reference point. Commented Aug 4, 2020 at 3:10
• @JohnAlexiou You're right, edited my answer. Thanks for the heads up Commented Aug 4, 2020 at 3:13
• This is the jet select problem. It is highly nontrivial. Finding the selection of jet commands that come closest to achieving the desired translational / rotational acceleration at any one instant of time is likely to consume a lot more propellant than would result from an apparently non-optimal selection of jet commands that more or less achieve the same goal. This problem is so nontrivial that papers continue to be written on this subject, 60+ years after the start of the space race. Commented Aug 4, 2020 at 12:11
• @DavidHammen Thank you for the name of this problem, I will do some more research on it. Commented Aug 4, 2020 at 17:07
• @Rubydesic - If you get the solution you want, please post it so it can be useful to other users too. Just add an answer to your own question. Commented Aug 4, 2020 at 20:48

The problem is one of least squares (until the point where the magnitude is capped).

Consider the target force vector $$\vec{F}$$ and the target moment vector $$\vec{T}$$ as the right-hand side $$\boldsymbol{b}$$ of a linear system of equations, and the vector $$\boldsymbol{x}$$ of $$n$$ force magnitudes is the unknowns.

$$\mathbf{A}\;\boldsymbol{x} = \boldsymbol{b}$$

$$[\mathbf{A}]_{6\times n}\; \begin{pmatrix}F_{1}\\ F_{2}\\ \vdots\\ F_{n} \end{pmatrix}_{n\times1} = \begin{pmatrix}\vec{F}\\ \vec{T} \end{pmatrix}_{6\times1} \tag{1}$$

We will get later into what the coefficient matrix $$\mathbf{A}$$ is. For now consider a case where $$n \geq 6$$, and the solution is given by

$$\boldsymbol{x} = \mathbf{A}^\top \left( \mathbf{A} \mathbf{A}^\top \right)^{-1} \boldsymbol{b} \tag{2}$$

Where $$^\top$$ is the matrix transpose.

So what is $$\mathbf{A}$$? There are 6 rows and $$n$$ columns to this matrix, and the first 3 rows is filled with all $$n$$ force direction vectors $$\vec{z}_i$$, and the last 3 rows with all $$n$$ torque directions $$\vec{r}_i \times \vec{z}_i$$.

$$\mathbf{A} = \begin{bmatrix}\vec{z}_{1} & \vec{z}_{2} & \cdots & \vec{z}_{n}\\ \vec{r}_{1}\times\vec{z}_{1} & \vec{r}_{2}\times\vec{z}_{2} & \cdots & \vec{r}_{n}\times\vec{z}_{n} \end{bmatrix}_{6\times n} \tag{3}$$

The result isn't guaranteed to be within the force limits, but it will be the least possible force system overall.

## Reduced Example

Consider a planar example (for simplicity with 3 DOF instead of 6) with $$n=4$$ forces arranged in a rectangle of size $$a$$, $$b$$, and each direction pointing to the next force location.

\begin{aligned} \vec{r}_1 &= \pmatrix{-\tfrac{a}{2} \\ -\tfrac{b}{2} } & \vec{z}_1 &= \pmatrix{1\\0} & \vec{r}_1 \times \vec{z}_1 = \tfrac{b}{2} \\ \vec{r}_2 &= \pmatrix{ \tfrac{a}{2} \\ -\tfrac{b}{2} } & \vec{z}_2 &= \pmatrix{0\\1} & \vec{r}_2 \times \vec{z}_2 = \tfrac{a}{2}\\ \vec{r}_3 &= \pmatrix{ \tfrac{a}{2} \\ \tfrac{b}{2} } & \vec{z}_3 &= \pmatrix{-1\\0} & \vec{r}_3 \times \vec{z}_3 = \tfrac{b}{2} \\ \vec{r}_4 &= \pmatrix{-\tfrac{a}{2} \\ \tfrac{b}{2} } & \vec{z}_4 &= \pmatrix{0\\-1} & \vec{r}_4 \times \vec{z}_4 = \tfrac{a}{2} \\ \end{aligned}

with the target force $$\vec{F}= \pmatrix{3 \\ 2}$$ and moment $$T=\pmatrix{1}$$

$$\boldsymbol{b} = \begin{pmatrix} 3 \\ 2 \\ 1 \end{pmatrix}$$

The coefficient matrix is composed from (3)

$$\mathbf{A} = \begin{bmatrix} 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \\ \tfrac{b}{2} & \tfrac{a}{2} & \tfrac{b}{2} & \tfrac{a}{2}\end{bmatrix}$$

and solution from (2)

$$\pmatrix{F_1 \\ F_2 \\ F_3 \\ F_4} = \begin{bmatrix} 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \\ \tfrac{b}{2} & \tfrac{a}{2} & \tfrac{b}{2} & \tfrac{a}{2}\end{bmatrix}^\top \begin{bmatrix} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & \tfrac{a^2+b^2}{2} \end{bmatrix} ^{-1} \begin{pmatrix} 3 \\ 2 \\ 1 \end{pmatrix} = \pmatrix{\tfrac{3}{2} + \tfrac{b}{a^2+b^2} \\ 1+\tfrac{a}{a^2+b^2} \\ -\tfrac{3}{2}+\tfrac{b}{a^2+b^2} \\ -1+\tfrac{a}{a^2+b^2}}$$

Let us check the result

$$\vec{F}= F_1 \vec{z}_1 + F_2 \vec{z}_2 + F_3 \vec{z}_3 + F_4 \vec{z}_4 = \pmatrix{3\\2} \; \checkmark$$

$$\vec{T} =F_1 (\vec{r}_1 \times \vec{z}_1) + F_2 (\vec{r}_2 \times \vec{z}_2) + F_3 (\vec{r}_3 \times \vec{z}_3) + F_4 (\vec{r}_4 \times \vec{z}_4) = \pmatrix{1} \; \checkmark$$

This method also solves the "Find the forces of the four legs of a table" problem given an arbitrary load on the table surface.

• This is not the way to solve the jet select problem as it does not pay any attention at all to the constraints. This solution can yield negative values for some elements of $x$, or ridiculously large positive values for some elements of $x$. Thrusters cannot fire in reverse (negative values of $x$), nor can they fire above their maximum thrust. The problem gets worse: Even optimal convex hull solutions that do pay attention to constraints can drain propellant at a massive rate. Commented Aug 4, 2020 at 12:21