Let cursor aim turn as hard as the keys (0.4.5)
- Rate loop gets an integral term with anti-windup, so held turns reach the commanded rate instead of settling below it (rateIntegralGain) - Cursor past full deflection asks for more pull than planned; a measured angle of attack limiter caps it at the wings' stall limit, like holding the key without stalling - Lift margin is now configurable (liftMargin, default 0.95, was a fixed 0.85) and also sets the angle of attack limit - fullDeflectionDegrees defaults to 20 (was 30) - Cursor aim options are settable in game with /aero - /aero cursor_debug shows commanded vs actual pitch rate, planned pull, lift limit and stall ratio above the hotbar Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
80bb63d44f
commit
dec28c5a01
8 files changed
+198
-13
No files matched your search
+1
-1
@@ -12,7 +12,7 @@ mapping_version=2023.09.03-1.20.1
|
||||
mod_id=improved_aerodynamics
|
||||
mod_name=VS: Improved Aerodynamics
|
||||
mod_license=MIT
|
||||
mod_version=0.4.3
|
||||
mod_version=0.4.5
|
||||
azurelib_version=3.2.7
|
||||
mod_group_id=dev.lumareth.improvedaerodynamics
|
||||
mod_authors=Lumareth
|
||||
|
||||
@@ -215,7 +215,7 @@ public final class Config {
|
||||
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_FULL_DEFLECTION_DEGREES = BUILDER.comment("Angle of the cursor from the gun reticle at which the virtual pilot turns as hard as it can: the maximum bank",
|
||||
"sideways, the full pitch rate up or down. Closer than that it turns more gently, so the reticle settles onto",
|
||||
"the cursor. How fast the craft can turn is worked out from the craft itself")
|
||||
.defineInRange("fullDeflectionDegrees", 30.0, 5.0, 90.0);
|
||||
.defineInRange("fullDeflectionDegrees", 20.0, 5.0, 90.0);
|
||||
|
||||
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_DEADZONE_DEGREES = BUILDER.comment("Radius around the gun reticle in degrees inside which the pilot stops steering towards the cursor. The reticle",
|
||||
"then settles this far from the cursor. Outside it the command grows from zero, there is no jump at the edge")
|
||||
@@ -235,6 +235,14 @@ public final class Config {
|
||||
"higher follows the cursor tighter and can start to oscillate")
|
||||
.defineInRange("rateGain", 5.0, 0.5, 40.0);
|
||||
|
||||
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_RATE_INTEGRAL_GAIN = BUILDER.comment("How fast the pilot builds up extra deflection when the craft keeps turning slower than asked, so a held turn",
|
||||
"reaches the rate it asks for. 0 turns it off, high values can make the nose overshoot")
|
||||
.defineInRange("rateIntegralGain", 4.0, 0.0, 40.0);
|
||||
|
||||
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_LIFT_MARGIN = BUILDER.comment("Share of the wings' stall limit the pilot uses: of the lift they can make before stalling when it plans a turn,",
|
||||
"and of the stall angle of attack, which it never pulls past. 1 flies right at the edge of the stall")
|
||||
.defineInRange("liftMargin", 0.95, 0.5, 1.0);
|
||||
|
||||
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_PUSH_FACTOR = BUILDER.comment("A cursor below the gun reticle pushes the nose down. This is how much of the pull rate that may be, since",
|
||||
"negative g is harder on the craft and the pilot")
|
||||
.defineInRange("pushFactor", 0.4, 0.0, 1.0);
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import dev.lumareth.improvedAerodynamics.exhaust.NozzleCommands;
|
||||
import dev.lumareth.improvedAerodynamics.flight.ControlMode;
|
||||
import dev.lumareth.improvedAerodynamics.flight.CursorAimDebug;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
@@ -23,7 +24,8 @@ import java.util.List;
|
||||
* /improvedaerodynamics (or /aero) to read and change the most important server config values in game.
|
||||
* {@code /aero} lists them, {@code /aero <option>} shows one, {@code /aero <option> <value>} sets and saves it.
|
||||
* The config options need operator rights, except for the owner of a singleplayer world, who may use them without cheats.
|
||||
* {@code /aero controls keyboard|cursor_aim} is open to every player and picks how they fly.
|
||||
* {@code /aero controls keyboard|cursor_aim} is open to every player and picks how they fly, and
|
||||
* {@code /aero cursor_debug} shows them what cursor aim is doing.
|
||||
* All of them are read live, so changes apply immediately.
|
||||
*/
|
||||
public final class ConfigCommands {
|
||||
@@ -68,7 +70,20 @@ public final class ConfigCommands {
|
||||
new Option<>("flap_slew_degrees", Config.FLAP_SLEW_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("flap_takeoff_max_speed", Config.FLAP_TAKEOFF_MAX_SPEED, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("flap_landing_max_speed", Config.FLAP_LANDING_MAX_SPEED, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("lookahead_seconds", Config.LOOKAHEAD_SECONDS, DoubleArgumentType.doubleArg(), Double.class));
|
||||
new Option<>("lookahead_seconds", Config.LOOKAHEAD_SECONDS, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_enabled", Config.CURSOR_AIM_ENABLED, BoolArgumentType.bool(), Boolean.class),
|
||||
new Option<>("cursor_aim_full_deflection_degrees", Config.CURSOR_AIM_FULL_DEFLECTION_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_deadzone_degrees", Config.CURSOR_AIM_DEADZONE_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_max_roll_rate_degrees", Config.CURSOR_AIM_MAX_ROLL_RATE_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_max_bank_degrees", Config.CURSOR_AIM_MAX_BANK_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_bank_gain", Config.CURSOR_AIM_BANK_GAIN, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_rate_gain", Config.CURSOR_AIM_RATE_GAIN, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_rate_integral_gain", Config.CURSOR_AIM_RATE_INTEGRAL_GAIN, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_lift_margin", Config.CURSOR_AIM_LIFT_MARGIN, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_push_factor", Config.CURSOR_AIM_PUSH_FACTOR, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_reverse_turn_degrees", Config.CURSOR_AIM_REVERSE_TURN_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_stalled_pitch_factor", Config.CURSOR_AIM_STALLED_PITCH_FACTOR, DoubleArgumentType.doubleArg(), Double.class),
|
||||
new Option<>("cursor_aim_min_speed", Config.CURSOR_AIM_MIN_SPEED, DoubleArgumentType.doubleArg(), Double.class));
|
||||
|
||||
private ConfigCommands() {
|
||||
}
|
||||
@@ -93,6 +108,7 @@ public final class ConfigCommands {
|
||||
root.then(SeedgenCommands.node().requires(ConfigCommands::mayUse));
|
||||
root.then(NozzleCommands.node().requires(ConfigCommands::mayUse));
|
||||
root.then(controlsNode());
|
||||
root.then(CursorAimDebug.node());
|
||||
LiteralCommandNode<CommandSourceStack> node = event.getDispatcher().register(root);
|
||||
event.getDispatcher().register(Commands.literal("aero")
|
||||
.executes(context -> mayUse(context.getSource()) ? list(context.getSource()) : denied(context.getSource()))
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ImprovedAerodynamics {
|
||||
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.ControlMode.class);
|
||||
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.FlapInteraction.class);
|
||||
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.DeflectionSync.class);
|
||||
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.CursorAimDebug.class);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.SPEC);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.CLIENT_SPEC);
|
||||
// Own file name: the default one is taken by Config.CLIENT_SPEC
|
||||
|
||||
@@ -46,6 +46,9 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
||||
// Lift the wings could make at the edge of the stall in the airflow of the last substep, NaN without the improved
|
||||
// flight model, which has no stall
|
||||
private double maxLift = Double.NaN;
|
||||
// Highest stall ratio (angle of attack over stall angle) of any wing in the last substep, NaN without the improved
|
||||
// flight model
|
||||
private double wingStallRatio = Double.NaN;
|
||||
private final Map<Long, NodeState> nodeStates = new ConcurrentHashMap<>();
|
||||
// Every ship's node states by node position, for the control surface animation on the server thread
|
||||
private static final Map<Long, NodeState> ALL_NODE_STATES = new ConcurrentHashMap<>();
|
||||
@@ -81,6 +84,15 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
||||
double controlRate = Double.NaN;
|
||||
// Cursor aim is rolling the craft over to reach a cursor far below the nose
|
||||
boolean reversing;
|
||||
// Cursor aim's integral of the turn rate error (angular acceleration, ship axes), so it reaches the rate it asks for
|
||||
final Vector3d rateIntegral = new Vector3d();
|
||||
// What cursor aim did last, for /aero cursor_debug: rates in rad/s, lift as load factor (g)
|
||||
volatile double debugCommandedPitch;
|
||||
volatile double debugActualPitch;
|
||||
volatile double debugMaxPull;
|
||||
volatile double debugLoadFactor = Double.NaN;
|
||||
volatile double debugStallRatio = Double.NaN;
|
||||
volatile boolean debugActive;
|
||||
// Share of the pull cursor aim keeps, eased down while the wings are stalled
|
||||
double stallEase = 1.0;
|
||||
// Which way pitch and yaw input turn the craft (+1 or -1 for nose up and nose right), learned from the measured
|
||||
@@ -258,6 +270,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
||||
if (commit) {
|
||||
wingStalled = false;
|
||||
maxLift = improved ? 0.0 : Double.NaN;
|
||||
wingStallRatio = Double.NaN;
|
||||
for (NodeState state : nodeStates.values()) {
|
||||
state.pitchResponseBuilding.zero();
|
||||
state.yawResponseBuilding.zero();
|
||||
@@ -283,6 +296,12 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
||||
if (s.type() == SurfaceType.WING || s.type() == SurfaceType.CONTROL_SURFACE && s.wingGroup()) {
|
||||
maxLift += ImprovedAero.maxLift(s, v, w, r, flap, weight, tuning);
|
||||
}
|
||||
if (s.type() == SurfaceType.WING) {
|
||||
double ratio = ImprovedAero.stallRatio(s, v, w, r, flap, tuning);
|
||||
if (!Double.isNaN(ratio) && !(ratio <= wingStallRatio)) {
|
||||
wingStallRatio = ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WariumAero.evaluate(s, v, w, r, input, weight, out);
|
||||
@@ -392,7 +411,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
||||
}
|
||||
// Cursor aim, if the pilot has it on, supplies the inputs the pilot is not giving with the keys
|
||||
NodeData effective = CursorPilot.apply(state, node, rotation, inertia, w, worldVelocity.length(), wingStalled,
|
||||
liftAcceleration, dt);
|
||||
liftAcceleration, wingStallRatio, dt);
|
||||
state.pitch = moveTowards(state.pitch, effective.pitch(), step);
|
||||
state.yaw = moveTowards(state.yaw, effective.yaw(), step);
|
||||
state.roll = moveTowards(state.roll, effective.roll(), step);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package dev.lumareth.improvedAerodynamics.flight;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.mcreator.valkyrienwarium.entity.SeatEntityEntity;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* {@code /aero cursor_debug} toggles a line above the hotbar that shows what cursor aim is doing for the player's control
|
||||
* node: the pitch rate it asks for and the one the craft makes, the pull it plans with, the most lift the wings can make
|
||||
* (as load factor) and how close they fly to the stall (1 is the stall). Open to every player, like /aero controls.
|
||||
*/
|
||||
public final class CursorAimDebug {
|
||||
private static final int INTERVAL_TICKS = 4;
|
||||
private static final Set<UUID> PLAYERS = new HashSet<>();
|
||||
|
||||
private CursorAimDebug() {
|
||||
}
|
||||
|
||||
public static LiteralArgumentBuilder<CommandSourceStack> node() {
|
||||
return Commands.literal("cursor_debug")
|
||||
.requires(source -> source.getEntity() instanceof ServerPlayer)
|
||||
.executes(context -> {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
boolean on = PLAYERS.add(player.getUUID());
|
||||
if (!on) {
|
||||
PLAYERS.remove(player.getUUID());
|
||||
}
|
||||
context.getSource().sendSuccess(() -> Component.literal("Cursor aim debug " + (on ? "on" : "off")), false);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerTick(TickEvent.ServerTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END || PLAYERS.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MinecraftServer server = event.getServer();
|
||||
if (server.getTickCount() % INTERVAL_TICKS != 0 || !ModList.get().isLoaded("valkyrien_warium")) {
|
||||
return;
|
||||
}
|
||||
for (UUID id : PLAYERS) {
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(id);
|
||||
if (player != null) {
|
||||
player.displayClientMessage(Component.literal(line(player)), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String line(ServerPlayer player) {
|
||||
Entity vehicle = player.getVehicle();
|
||||
if (!(vehicle instanceof SeatEntityEntity)) {
|
||||
return "Cursor aim: not in a seat";
|
||||
}
|
||||
AimBasis basis = AimBasis.of(vehicle.level(), vehicle.blockPosition());
|
||||
AeroState.NodeState state = basis != null ? AeroState.nodeState(basis.nodePos().asLong()) : null;
|
||||
if (state == null || !state.debugActive) {
|
||||
return "Cursor aim: not flying (off, too slow or no physics)";
|
||||
}
|
||||
return String.format(Locale.ROOT, "pitch %5.1f/%5.1f deg/s plan %5.1f lift %4.1fg stall %4.2f",
|
||||
Math.toDegrees(state.debugActualPitch), Math.toDegrees(state.debugCommandedPitch),
|
||||
Math.toDegrees(state.debugMaxPull), state.debugLoadFactor, state.debugStallRatio);
|
||||
}
|
||||
}
|
||||
@@ -39,8 +39,14 @@ final class CursorPilot {
|
||||
private static final double MANUAL_OVERRIDE = 0.05;
|
||||
// Gravity of VS
|
||||
private static final double GRAVITY = 10.0;
|
||||
// Share of the stall limited lift the pilot plans with, so it does not ride the stall
|
||||
private static final double LIFT_MARGIN = 0.85;
|
||||
// Cursor beyond full deflection: the pull command grows to this many times the planned rate by 1.5 times the full
|
||||
// deflection angle, and the angle of attack limit decides how much of it the craft gets
|
||||
private static final double OVERDRIVE = 2.5;
|
||||
private static final double OVERDRIVE_END = 1.5;
|
||||
// Pitch rate (rad/s) the angle of attack limiter takes off per unit of stall ratio over the limit
|
||||
private static final double ALPHA_GAIN = 4.0;
|
||||
// The rate integral may make up for this much rate error (rad/s) worth of acceleration
|
||||
private static final double MAX_ERROR_FOR_INTEGRAL = 0.5;
|
||||
// Bank the pilot rolls to at full sideways deflection even when the wings cannot hold the turn level
|
||||
private static final double MIN_BANK = Math.toRadians(20.0);
|
||||
// Smallest pull allowed, as a share of the turn rate, when gravity takes most of the lift
|
||||
@@ -57,12 +63,14 @@ final class CursorPilot {
|
||||
* @return the node with the pilot's wanted inputs in place of the keys, or the node itself if cursor aim is off
|
||||
*/
|
||||
static NodeData apply(AeroState.NodeState state, NodeData node, Quaterniondc rotation, Matrix3dc inertia, double[] w,
|
||||
double speed, boolean wingStalled, double liftAcceleration, double dt) {
|
||||
double speed, boolean wingStalled, double liftAcceleration, double stallRatio, double dt) {
|
||||
if (!Config.CURSOR_AIM_ENABLED.get()) {
|
||||
return node;
|
||||
}
|
||||
CursorAimRegistry.Aim aim = CursorAimRegistry.get(node.key());
|
||||
if (aim == null) {
|
||||
state.rateIntegral.zero();
|
||||
state.debugActive = false;
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -106,6 +114,8 @@ final class CursorPilot {
|
||||
// Too slow for the rate loop: the cursor moves the surfaces directly, rudder towards it (which also steers on
|
||||
// the ground) and elevator up or down, so the controls follow the cursor while taxiing and rotating
|
||||
state.reversing = false;
|
||||
state.rateIntegral.zero();
|
||||
state.debugActive = false;
|
||||
double pitch = clamp(state.pitchSign * saturate(vertical / fullAngle) - state.trimOutput, -1.0, 1.0);
|
||||
double yaw = state.yawSign * saturate(sideways / fullAngle);
|
||||
return withInputs(node, pitch, yaw, 0.0);
|
||||
@@ -113,7 +123,8 @@ final class CursorPilot {
|
||||
|
||||
// What this craft can do right now. Lift: pitch rate at the highest usable lift (a = L / m, rate = a / v), and
|
||||
// the bank whose level turn needs that load factor. Without a stall model only the control limit applies
|
||||
double usableLift = LIFT_MARGIN * liftAcceleration;
|
||||
double liftMargin = Config.CURSOR_AIM_LIFT_MARGIN.get();
|
||||
double usableLift = liftMargin * liftAcceleration;
|
||||
double liftRate = usableLift > 0.0 ? usableLift / speed : Double.POSITIVE_INFINITY;
|
||||
double controlRate = state.controlRate > 0.0 ? state.controlRate : Double.POSITIVE_INFINITY;
|
||||
double maxTurn = Math.min(liftRate, controlRate);
|
||||
@@ -162,8 +173,12 @@ final class CursorPilot {
|
||||
// plus a pull towards the cursor. Past 90 degrees of bank the level turn pull would only dive, so it is left out
|
||||
double pitchStick = saturate(vertical / fullAngle);
|
||||
double push = Config.CURSOR_AIM_PUSH_FACTOR.get();
|
||||
// A cursor past full deflection asks for everything: more pull than planned, which the angle of attack limiter
|
||||
// below cuts to the most the wings can give, like holding the key, only without stalling
|
||||
double overdrive = 1.0 + (OVERDRIVE - 1.0) * smoothstep(vertical / fullAngle, 1.0, OVERDRIVE_END);
|
||||
double pullLimit = maxPull * overdrive;
|
||||
// While rolling into a reversal the cursor is still below the nose, pushing there would only work against it
|
||||
double pitchRate = pitchStick >= 0.0 ? maxPull * pitchStick : state.reversing ? 0.0 : maxTurn * pitchStick * push;
|
||||
double pitchRate = pitchStick >= 0.0 ? pullLimit * pitchStick : state.reversing ? 0.0 : maxTurn * pitchStick * push;
|
||||
double cosBank = Math.cos(bank);
|
||||
if (cosBank > 0.0) {
|
||||
double sinBank = Math.sin(bank);
|
||||
@@ -173,10 +188,19 @@ final class CursorPilot {
|
||||
// the stall would make the craft buck in and out of the stall
|
||||
double stallTarget = wingStalled ? Config.CURSOR_AIM_STALLED_PITCH_FACTOR.get() : 1.0;
|
||||
state.stallEase += (stallTarget - state.stallEase) * Math.min(1.0, dt / STALL_EASE_SECONDS);
|
||||
pitchRate = clamp(pitchRate, -maxTurn * push, maxPull);
|
||||
pitchRate = clamp(pitchRate, -maxTurn * push, pullLimit);
|
||||
if (pitchRate > 0.0) {
|
||||
pitchRate *= state.stallEase;
|
||||
}
|
||||
// Angle of attack limiter: the wings may go up to the lift margin's share of their stall angle, no further. Measured,
|
||||
// so it holds whatever the lift estimate gets wrong
|
||||
double actualPitch = w[0] * r[0] + w[1] * r[1] + w[2] * r[2];
|
||||
if (Double.isFinite(stallRatio)) {
|
||||
double alphaCap = actualPitch + ALPHA_GAIN * (liftMargin - stallRatio);
|
||||
if (pitchRate > alphaCap) {
|
||||
pitchRate = alphaCap;
|
||||
}
|
||||
}
|
||||
// Close to the reticle the nose follows the cursor with the rudder
|
||||
double yawRate = maxTurn * saturate(sideways / fullAngle) * (1.0 - blend);
|
||||
|
||||
@@ -186,7 +210,10 @@ final class CursorPilot {
|
||||
rollRate * f[1] + pitchRate * r[1] - yawRate * u[1],
|
||||
rollRate * f[2] + pitchRate * r[2] - yawRate * u[2]);
|
||||
Vector3d error = wanted.sub(w[0], w[1], w[2]);
|
||||
Vector3d acceleration = error.mul(Config.CURSOR_AIM_RATE_GAIN.get());
|
||||
double rateGain = Config.CURSOR_AIM_RATE_GAIN.get();
|
||||
// Proportional on the rate error plus its integral: holding a turn needs a steady deflection against the craft's
|
||||
// damping and stability, which the proportional part alone only gives while the craft falls short of the rate
|
||||
Vector3d acceleration = error.mul(rateGain, new Vector3d()).add(state.rateIntegral);
|
||||
Vector3d torque = inertia.transform(acceleration, new Vector3d());
|
||||
|
||||
double[] inputs = solve(state.pitchResponse, state.yawResponse, state.rollResponse, torque);
|
||||
@@ -194,7 +221,25 @@ final class CursorPilot {
|
||||
return node;
|
||||
}
|
||||
|
||||
double pitch = clamp(inputs[0] - state.trimOutput, -1.0, 1.0);
|
||||
double rawPitch = inputs[0] - state.trimOutput;
|
||||
boolean saturated = Math.abs(rawPitch) > 1.0 || Math.abs(inputs[1]) > 1.0 || Math.abs(inputs[2]) > 1.0;
|
||||
if (!saturated) {
|
||||
// Only while the surfaces have room left, so the integral cannot wind up against full deflection
|
||||
state.rateIntegral.add(error.mul(Config.CURSOR_AIM_RATE_INTEGRAL_GAIN.get() * dt, new Vector3d()));
|
||||
double limit = rateGain * MAX_ERROR_FOR_INTEGRAL;
|
||||
if (state.rateIntegral.length() > limit) {
|
||||
state.rateIntegral.normalize(limit);
|
||||
}
|
||||
}
|
||||
|
||||
state.debugCommandedPitch = pitchRate;
|
||||
state.debugActualPitch = actualPitch;
|
||||
state.debugMaxPull = maxPull;
|
||||
state.debugLoadFactor = liftAcceleration / GRAVITY;
|
||||
state.debugStallRatio = stallRatio;
|
||||
state.debugActive = true;
|
||||
|
||||
double pitch = clamp(rawPitch, -1.0, 1.0);
|
||||
double yaw = clamp(inputs[1], -1.0, 1.0);
|
||||
double roll = clamp(inputs[2], -1.0, 1.0);
|
||||
return withInputs(node, pitch, yaw, roll);
|
||||
|
||||
@@ -191,6 +191,25 @@ final class ImprovedAero {
|
||||
return LIFT_CONSTANT * s.pressure() * weight * s.fluidFactor() * planeSpeedSq * lift * tuning.liftScale();
|
||||
}
|
||||
|
||||
/**
|
||||
* How close the surface flies to its stall: its angle of attack (camber and flaps included, positive pulling) over
|
||||
* the angle at which it starts to stall, so 1 is the edge of the stall. Only meaningful for horizontal surfaces,
|
||||
* NaN without airflow in the surface's plane.
|
||||
*/
|
||||
static double stallRatio(AeroSurface s, double[] v, double[] w, double[] r, double flap, Tuning tuning) {
|
||||
double vx = v[0] + w[1] * r[2] - w[2] * r[1];
|
||||
double vy = v[1] + w[2] * r[0] - w[0] * r[2];
|
||||
double vz = v[2] + w[0] * r[1] - w[1] * r[0];
|
||||
double u = vx * s.facingX() + vz * s.facingZ();
|
||||
if (u * u + vy * vy < 1.0E-4) {
|
||||
return Double.NaN;
|
||||
}
|
||||
double flapShift = FLAP_ALPHA_FACTOR * flap;
|
||||
double alpha = Math.atan2(-vy, Math.abs(u)) + Math.toRadians(s.type().camber) + flapShift;
|
||||
double critical = criticalAngle(s, tuning, vortexFactor(s, tuning)) + FLAP_STALL_GAIN * flapShift;
|
||||
return alpha / critical;
|
||||
}
|
||||
|
||||
private static double vortexFactor(AeroSurface s, Tuning tuning) {
|
||||
return tuning.vortex() && (s.type() == SurfaceType.WING || s.wingGroup() && s.type().controllable)
|
||||
? VortexLift.factor(s.aspectRatio()) : 0.0;
|
||||
|
||||
Reference in new issue
Block a user