Arbitrary thruster burn solving

Started by
0 comments, last by Vexal 9 years, 1 month ago

Hi,

I am attempting to make a system where an AI unit can move itself with an arbitrary set of thrusters. All movement in the engine my engine is controlled by the physics engine -- to move or rotate an object, a force vector must be applied on the object.

Objects have a list of Thrusters (a thruster is not necessarily a piece of hardware like on a ship -- it's just a designator for where a force can be applied relative to an object).

At the end of each frame, the net force on an object is summed up to find the net force and acceleration.

A thruster has:

x, y, z offset (in local object coordinates)

x, y, z direction (in local object coordinates)

current magnitude (in absolute force units)

maximum magnitude (in absolute force units)

Most of the code interacts with the thrusters by setting their percentage activated.

Currently I have an AI ship that can follow the player and hover, as well as keep itself level when balls are thrown at it, by firing off the correct thrusters to keep its angular and linear velocity a set amount, and its pitch a set amount.

However, I have hard-coded the thrusters to be used at this point. But I would like to be able to have an arbitrary set of thruster objects pointing in arbitrary directions with arbitrary maximum magnitudes and the AI calculate which thrusters to fire and at what percentage to get closest to its target position, angle, linear velocity, and angular velocity, at the end of each frame.

I'm not great at math and not sure where to start with solving for the thruster percentages. What is most confusing to me is, for example, the fact that the ship can fire off a back-right thruster, which will turn it left and also propel it forward.

Advertisement

In case anyone is interested, I solved this problem. I use linear programming to optimize for the minimum sum of the absolute values of the difference between "attained force / torque this frame (per dimension)", and "required force / toque this frame", where required force this frame is the force required to get the ship to a set target velocity / rotational velocity. The variables are the percentage of each thruster; the coefficients are the force and torque the thruster has in each dimension. The thrusters are constrained between 0 and 1.

This page has a really great explanation on how to minimize absolute value even though it itself is not linear: http://lpsolve.sourceforge.net/5.5/absolute.htm

Compiling LPSolve library with VC++14 worked fine.

If anyone has questions about the details of this feel free to ask.

This topic is closed to new replies.

Advertisement