---
# System prepended metadata

title: Mōvi Pro Pan/Tilt Limits Math & Physics
tags: ['July 27, 2023']

---

But Seriously we need a name for this!

Derivation of Mōvi Pro Pan/Tilt limits and smoothing 

## Math Behind the Smoothing Function

https://www.desmos.com/calculator/fqh08ohwcq

The following relationships are established from 1-D kinematics:

$$v^2 = v_o^2+2ax$$

- $v$ is the velocity at the current position
- $v_o$ is the initial velocity
- $a$ is the acceleration
- $x$ is the distance from the starting position

Rewriting the function in terms of a scaling factor, where $v_{adj} = v/v_o$, normalized about 1, and given that the acceleration is negative since we are slowing down:

$$v_{adj}^2 = 1 - 2ax$$

$$v_{adj} = \sqrt{1 - 2ax}$$

Further generalizing this expression:

$$v_{adj} = \sqrt{1 - f(a, x)}$$

Where to stop in the least amount of distance given an acceleration:

$$f(a, x) = 2ax$$

If the acceleration is desired be smoother (non-linear), a quadratic function can be used:

$$f(a, x) = 2ax - \frac{a^2}{1 - 2as_s}$$

## High-level overview of how this is implemented in the code:

Constants are defined by letters: [$lim_{max}$, $lim_{min}$, $c_{st}$, $c_{sm}$, $a$]

Changing values are defined by symbols: [$θ$, $θ_{max}$, $θ_{min}$, $θ_{stop}$, $θ_{smooth}$, $\dot{θ}$, $\dot{θ}_{adj}$, $\dot{θ}_{in}$]

**User & gimbal-provided provided values and their respective allowable ranges:**

$lim_{max} \rightarrow [lim_{min}, \pi]$ is the max limit in rad (converted from °) || `int16_t max_lim`

$lim_{min} \rightarrow [-\pi, lim_{max}]$ is the min limit in rad (converted from °) || `int16_t min_lim`

$c_{st} \rightarrow [0, 1]$ is the stopping coefficient (computed from %) || `uint8_t stop_percent`

$c_{sm} \rightarrow [0, 1]$ is the smoothing coefficient (computed from %) || `uint8_t s_percent`

$θ \rightarrow [0, 2\pi]$ is the current position of the gimbal || `float prt_t2[axis]`

**Calculated values:**

$θ_{max} = lim_{max} - θ$ is the distance from the max limit in rad

$θ_{min} = θ - lim_{min}$ is the distance from the min limit in rad

$θ_{stop} = (lim_{max} - lim_{min})* c_{st} / 2$ is the distance defined to come to a full stop

$θ_{smooth} = (1 - c_{sm})/(1 + c_{sm}) * θ_{stop}$ is the distance to transition to the smoothing function

$a = (1 + c_{sm})/2θ_{stop}$ is the acceleration needed to come to a full stop

**Conditional calculated values:**

If the gimbal is within $θ_{stop}$ from the max limit ($θ_{max} \le θ_{stop}$):

$θ_{lim} = θ_{stop} - θ_{max}$ is the distance past the start of the curve in the max limit direction

Else if the gimbal is within $θ_{stop}$ from the max limit ($θ_{min} \le θ_{stop}$):

$θ_{lim} = θ_{stop} - θ_{min}$ is the distance past the start of the curve in the min limit direction

**Adjusted velocity calculations:**

Once the either of the above are true, the adjusted angular velocity is computed: 

$\dot{θ}_{adj} = \sqrt{1 - 2aθ_{lim}}$

Then, once $θ_{lim} > θ_{smooth}$:

$\dot{θ}_{adj} = \sqrt{1 - 2aθ_{lim} + a^2(θ_{lim} - θ_{smooth})^2/c_{sm}}$

The commanded gimbal rate then becomes $\dot{θ}$, where $\dot{θ}_{in}$ is the original commanded rate: 

$\dot{θ} = \dot{θ}_{adj}\dot{θ}_{in}$











