Skip to content

Commit

Permalink
Small adjustment for auto pitch. Non-functional math changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Dec 17, 2023
1 parent 538ffff commit f3d643f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"src/?.lua"
],
"Lua.workspace.library": [
"e/lib/",
"e/render",
"e/lib/src",
"e/render/src",
"${3rd}/luassert/library",
"${3rd}/busted/library"
]
Expand Down
2 changes: 1 addition & 1 deletion e/lib
38 changes: 21 additions & 17 deletions src/flight/AxisControl.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
require("abstraction/Vehicle")
local s = require("Singletons")
local yfsC, pub, calc, Vec3 = s.constants, s.pub, s.calc, require("math/Vec3")
local SignLargestAxis, SignedRotationAngle, setEngineCommand, LightConstructMassThreshold, PID, nullVec =
local si, Vec3, PID = require("Singletons"), require("math/Vec3"), require("cpml/pid")
local yfsC, pub, calc = si.constants, si.pub, si.calc

local SignLargestAxis, SignedRotationAngle, setEngineCommand,
LightConstructMassThreshold, nullVec =
calc.SignLargestAxis,
calc.SignedRotationAngle,
unit.setEngineCommand, yfsC.flight.lightConstructMassThreshold, require("cpml/pid"), Vec3.zero
unit.setEngineCommand,
yfsC.flight.lightConstructMassThreshold,
Vec3.zero

local rad2deg, deg2rad = 180 / math.pi, math.pi / 180
local rad2deg = 180 / math.pi

local control = {}
control.__index = control
local control = {}
control.__index = control

---@enum ControlledAxis
ControlledAxis = {
ControlledAxis = {
Pitch = 1,
Roll = 2,
Yaw = 3,
}

local finalAcceleration = {} ---@type Vec3[]
local finalAcceleration = {} ---@type Vec3[]
finalAcceleration[ControlledAxis.Pitch] = nullVec
finalAcceleration[ControlledAxis.Roll] = nullVec
finalAcceleration[ControlledAxis.Yaw] = nullVec
finalAcceleration[ControlledAxis.Roll] = nullVec
finalAcceleration[ControlledAxis.Yaw] = nullVec

---@class AxisControl
---@field ReceiveEvents fun()
Expand All @@ -35,8 +39,8 @@ finalAcceleration[ControlledAxis.Yaw] = nullVec
---@field OffsetDegrees fun():number
---@field Apply fun()

local AxisControl = {}
AxisControl.__index = AxisControl
local AxisControl = {}
AxisControl.__index = AxisControl


---Creates a new AxisControl
Expand Down Expand Up @@ -138,14 +142,14 @@ function AxisControl.New(axis)

---@param deltaTime number
function s.AxisFlush(deltaTime)
if targetCoordinate ~= nil then
if targetCoordinate then
-- Positive offset means we're right of target, clock-wise
-- Positive acceleration turns counter-clockwise
-- Positive velocity means we're turning counter-clockwise

local vecToTarget = (targetCoordinate - Current()):Normalize()
local offset = SignedRotationAngle(normal(), reference(), vecToTarget) * rad2deg
axisData.offset = offset
local offset = SignedRotationAngle(normal(), reference(), vecToTarget)
axisData.offset = offset * rad2deg

lightPid:inject(offset)
heavyPid:inject(offset)
Expand All @@ -157,7 +161,7 @@ function AxisControl.New(axis)
v = lightPid:get()
end

finalAcceleration[axis] = normal() * v * deg2rad
finalAcceleration[axis] = normal() * v
end
end

Expand Down
5 changes: 2 additions & 3 deletions src/flight/Waypoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,13 @@ function Waypoint.New(destination, finalSpeed, maxSpeed, margin, pathAlignmentDi
local moveDir, forward = Velocity():Normalize(), upPlane.Forward()

if s.DistanceTo() > 10 and Velocity():Len() > calc.Kph2Mps(50)
and moveDir:AngleToDeg(s.DirectionTo()) <= calc.Clamp(pitchAlignmentThrustLimiter * 10, pitchAlignmentThrustLimiter, 45) --
and BetweenOrEqual(moveDir:AngleToDeg(gravPlane.Up()), 40, 140) -- Prevent flipping backwards
-- Not going vertically
and BetweenOrEqual(gravPlane.Up():AngleToDeg(s.DirectionTo()), 15, 180 - 15)
-- Not reversing or strafing
and BetweenOrEqual(forward:AngleToDeg(s.DirectionTo()), 0, 75)
then
local target = Current() + moveDir * directionMargin
return calc.ProjectPointOnPlane(upPlane.Right(), Current(), target)
return Current() + moveDir * directionMargin
end
end

Expand Down

0 comments on commit f3d643f

Please sign in to comment.