0
\$\begingroup\$

Say you have two objects in a vacuum with no forces acting on them.

The objects may or may not be moving.

Object A's acceleration is not equal in all directions, and object B may change its acceleration over time.

Knowns:
A position
A velocity
A acceleration
A max acceleration for a given vector
B position
B velocity
B acceleration

So for object A, how can I iteratively calculate the the direction of thrust needed to go to B's position and match B's velocity in the smallest amount of time?

\$\endgroup\$
6
  • \$\begingroup\$ Do you need the solution to 'just work' (using a naive method) or to be optimized? If yes, what parameter should be optimized and does it have to be the best optimization possible? \$\endgroup\$ – Sacha Dec 4 '20 at 14:56
  • \$\begingroup\$ optimized for time would be ideal, but 'just working' would be a great start. fuel/electricity economy would be a nice to have as well but im just trying to get the basics here first \$\endgroup\$ – Ryan Tuosto Dec 4 '20 at 15:01
  • \$\begingroup\$ The cubic Bezier approach I linked you to previously might also be useful here. In that model, the acceleration of A will be an affine function of time (a line segment in acceleration space). You can then check whether that line segment fits wholly within the envelope of your allowed acceleration in each direction. If it doesn't, extend your time horizon. If it fits "with room" then you can shorten your time horizon. \$\endgroup\$ – DMGregory Dec 4 '20 at 18:02
  • \$\begingroup\$ I don't think I understood that approach because I'm not trying to plot a course over time, I'm just trying to instruct the object how to move 'right now'. I'm sure you can get one from the other but I just don't quite understand how. I'm much more comfortable reading code than math notation so that's probably where I'm getting lost. \$\endgroup\$ – Ryan Tuosto Dec 5 '20 at 14:49
  • \$\begingroup\$ @DMGregory I am able to get all of the positions, velocities, and the control points - how do I get what the current acceleration vector should be from that \$\endgroup\$ – Ryan Tuosto Dec 5 '20 at 15:11
0
\$\begingroup\$

An easy to implement solution (naive algorithm)

The idea is to first get A to match B's velocity. Once it's done, both objects will be stationary with respect to the other or, if you take A as the origin of your frame, B will be stationary in your frame and it becomes a problem of perform a rendez-vous with a stationary target (accelerate towards it, then decelerate before meeting it).

An more optimized solution

You'll need to use a state-space representation.
Write your system into equations using Newton's second law for both objects, then write using state-space representation and plug a suitable controller onto it.

First, let's model the system.
Variables with A (resp. B) subscript are relative to object A (resp. B). For state-space representation, I'm using the same notation as in the Wikipedia linked page.

Our goal is a rendez-vous, which means bringing A at B's position and with zero relative velocity. Using \$X = x_B - x_A\$, our target is \$X = 0\$ and \$\dot{X} = 0\$.
Using Newton's second law, we can write

  • \$T_A = m_A.\ddot{x}_A\$
  • \$\ddot{X} = \ddot{x}_B - 1/m_A.T_A\$

The state vector is equal to the output vector \$y = x = \begin{pmatrix} X \\ \dot{X} \end{pmatrix} \$
Then the system equation is \$\dot{x} = \begin{pmatrix} \dot{X} \\ \ddot{X} \end{pmatrix} = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} x + \begin{pmatrix} 0 \\ -1/m_A \end{pmatrix} T_A + \begin{pmatrix} 0 \\ 1 \end{pmatrix} \ddot{x}_B \$

Oops, it's not linear, it's affine because of object B's acceleration. Depending on what is expected for \$\ddot{x}_B\$ you have several options:

  • Mainly zero, B will only use its thrusters sporadically: you can ignore \$\ddot{x}_B\$ in the system equation.
  • Its value is low compared to the other terms in the equation: you can also ignore it, but it might cause a steady-state error with a linear controller.
  • Its value is not negligeable but can be considered constant with respect to time: you can add a 'virtual' constant input to make it look like it's linear. The system equation becomes: \$\dot{x} = \begin{pmatrix} \dot{X} \\ \ddot{X} \end{pmatrix} = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} x + \begin{pmatrix} 0 & 0 \\ -1/m_A & \ddot{x}_B \end{pmatrix} \begin{pmatrix} T_A \\ 1 \end{pmatrix}\$
  • Its value is not negligeable and time-dependant: expect a steady-state error, or a divergence.

In the first 3 cases, a linear controller such as a PID could do the trick. In the last case, you either have to use a higher-order controller, or use a modified PID to account for the non-linearity (in that case, the controller will not be linear).

\$\endgroup\$
3
  • \$\begingroup\$ could you elaborate on why a PID may not work if B is changing its acceleration too much? \$\endgroup\$ – Ryan Tuosto Dec 4 '20 at 15:35
  • \$\begingroup\$ A PID is simple and efficient for stady setpoints, but can easily fail to track a moving set point (there can be too much overshoot or a non-zero steady-state error in that case). You know higher-order controllers in this case. Actually I'm not even sure a PID would be enough even with a constant acceleration from B. I'll check and edit the answer. \$\endgroup\$ – Sacha Dec 4 '20 at 15:39
  • \$\begingroup\$ They denote the derivative: X dot is the derivative of X and X dot dot is X derivated twice. Since X is x_b - x_a, X dot is be the speed of b minus the speed of a and X dot dot is the acceleration of b minus the acceleration of a. \$\endgroup\$ – Sacha Dec 5 '20 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.