Allocating torques to RWAs are accomplished by first defining a “distribution matrix” which contains the spin axes of the individual wheels, and then using this matrix to allocate torques.Each column of the distribution matrix consists of the unit vector for the spin axis of one wheel, resulting in a 3xN matrix for an RWA with N wheels.

In general:

```
tau_RWA = rwaMatrixInv * tau_b + alpha * rwaNullSpace
```

where `tau_b`

is the required torque in the body frame, `rwaMatrixInv`

is the inverse of the distribution matrix, `alpha`

is a row vector of size `m`

where `m`

is the nullity of `rwaMatrix`

.

For a three wheel system, the null space is empty and therefore the second term of the above expression does not apply.There is a unique solution to allocate any torques for a properly oriented RWA.The solution is the one that minimizes the L2 norm of the allocated torques and is a unique solution.

For RWAs with more than three wheels, the null-space presents flexibility in allocating torques to satisfy various conditions.If `alpha`

is selected as a zero vector, the solution minimizes the L2-norm of the allocated torques.`alpha`

can be selected to further optimize the allocation to satisfy other conditions.Minimizing the L-infinity norm of hte torque better uses the capacity of the RWA.However, computing alpha in the general case is non-trivial.Ref [1] describes a method for minimizing the L-infinity norm for four-wheel RWAs.

## Four wheel reaction wheel allocator for pyramid configurations

For a four wheel system, the nullity of `rwaMatrix`

is equal to one and hence `alpha`

is a scalar.i.e.

```
tau_L2 = rwaMatrixInv * tau_b
tau_Linf = tau_L2 + alpha * tau_null
```

where `tau_null`

is the null space of `rwaMatrix`

.

For symmetric 4 wheel configurations, `tau_null`

is equal to `[1, 1, 1, 1]`

and the value of alpha can be computed as:

```
alpha = - (min(tau_L2) + max(tau_L2))/2
```

For non-symmetric pyramid configurations, a different method is used where six separate values are computed as follows:

```
alpha_1 = - (tau_L2(1) + tau_L2(2)) / ( tau_null(1) + tau_null(2) )
alpha_2 = - (tau_L2(1) + tau_L2(3)) / ( tau_null(1) + tau_null(3) )
alpha_3 = - (tau_L2(1) + tau_L2(4)) / ( tau_null(1) + tau_null(4) )
alpha_4 = - (tau_L2(2) + tau_L2(3)) / ( tau_null(2) + tau_null(3) )
alpha_5 = - (tau_L2(2) + tau_L2(4)) / ( tau_null(2) + tau_null(4) )
alpha_6 = - (tau_L2(3) + tau_L2(4)) / ( tau_null(3) + tau_null(4) )
```

The value of alpha that gives the smallest maximum absolute value of `tau_rwa`

is selected.

*Note*

The above algorthms assume that the null space of `rwaMatrix`

is entirely positive (or equal to `[1, 1, 1, 1]`

in case of symmetric RWAs).However, it is possible that some of these may be negative based on how the axes are oriented.In this case, the sign of the corresponding column in `rwaMatrix`

is the be negated and the direction of the torque allocated for that particular wheel has to be reversed.

## References

[1] “Optimal uses of reaction wheels in the pyramid configuration using a new minimum infinity-norm solution”, Link