HOWTO thrust control logic

From ODE
Jump to: navigation, search

This article is known to contain outdated information. If you know of correct information, please edit this article! Thank you.

copy-dump from old wiki!

There must be an efficient and well-understood solution for the problem of: "how hard do I push it to get it where it needs to be."

I, MichaelMchenry, do not know what it is.

Example Problem

Givens:

  • A space ship that only travels on one axis (x)
  • the ship has a set maximum rate of forward thrust
  • the ship has a set maximum rate of deceleration.
  • the ship is at position x=0
  • we want the ship to stop at position x=100

Things that might be good to figure out:

  • How fast can the ship be going at it's current position and still be able to stop at x=100?

or

  • If we decelerate at the current time and position, will we stop to far away from x=100?

Example Solutions

Bad Calculus

I have solved this in the past by iteratively (because my calculus is not so good) solving what distance it will take to stop given the mass, velocity, and stopping force involved. If that stopping point is significantly before the target point, I continue to accelerate. Otherwise, I put on the brakes.

This works fine with one of my not-so-hot physics systems with discreet time intervals, and my very simple physics algorithms.

Neural Network

Train a neural network with energy (or mass & velocity) and max thrust inputs to stop on the right spot. Cute, but a bigger waste of processing power than the bad calculus method.

Adaptive System

Expert system that adapts to how well the physics system responds to it's controls. Algorithmically approximates a lot of what the neural network would do.

Owen Jones:

useful formulae

Stopping distance (SD) = mass * (currentspeed^2) / (2 * maximum braking force) and the rearrangements:

Necessary braking force (BF) = mass * (currentspeed^2) / (2 * remaining distance to target)

Maximum stoppable velocity (Vmax) = sqrt( 2 * maximum braking force * remaining distance to target / mass)

turn over point = ( (Distance to target * braking force) - ((initial velocity^2)* mass/2) ) /(accelerating force + braking force)

Control System

Useful for many different types of control, a simple forward-looking feedback loop will usually take care of this. The basic idea is to calculate where you will be some time in the future, if you keep going with the current velocity. Compare that to where you want to be. Apply a force that will attempt to correct the location by changing velocity. This force should be clamped to the maximum force your rockets/engines/whatever can muster. Note that if the body is very heavy (as a space ship) and the force available from the engines is very small, then you need to look much further ahead to avoid overshooting your target position. Some pseudo code:

 curVel = *(Vec3*)dBodyGetLinearVelocity( b );
 curPos = *(Vec3*)dBodyGetPosition( b );
 futurePos = curPos + LOOKAHEAD * curVel;
 desiredPos = YOUR_TARGET_HERE;
 applyForce = (futurePos - desiredPos) * SENSITIVITY;
 clampLength( applyForce, MAX_FORCE );
 dBodyAddForce( b, applyForce );

If your rocket ship must turn to apply force, you should probably apply the dot product between the actual force you want, and the forward vector, in the forward direction. Then you should probably also run a similar control system for rotation to make it point towards your desired goal. The main tweakables are LOOKAHEAD (measured in time step units, i e seconds usually) and SENSITIVITY (start with 1 but you may need to tweak it a lot one way or the other).