PID
The PID class simulates a PID controller. PID is an acronym for proportional, integral, derivative. PIDs are input feedback loops that try to reach a specific goal by measuring the difference between the input and the desired value, and then returning a new desired input.
A common example is a car's cruise control, which would give a PID the current speed and the desired speed, and the PID controller would return the desired throttle input to reach the desired speed.
Functions
new
PID.
new
(
min:
number
,
--
Minimum value the PID can output
max:
number
,
--
Maximum value the PID can output
kp:
number
,
--
Proportional gain coefficient (P)
ki:
number
,
--
Integral gain coefficient (I)
kd:
number
--
Derivative gain coefficient (D)
) →
PID
Constructs a new PID.
local pid = PID.new(0, 1, 0.1, 0, 0)
Reset
PID:
Reset
(
) →
(
)
Resets the PID to a zero start state.
Calculate
PID:
Calculate
(
setpoint:
number
,
--
The desired point to reach
processVariable:
number
,
--
The measured value of the system to compare against the setpoint
deltaTime:
number
--
Delta time. This is the time between each PID calculation
) →
output:
number
Calculates the new output based on the setpoint and input. For example, if the PID was being used for a car's throttle control where the throttle can be in the range of [0, 1], then the PID calculation might look like the following:
local cruisePID = PID.new(0, 1, ...)
local desiredSpeed = 50
RunService.Heartbeat:Connect(function(dt)
local throttle = cruisePID:Calculate(desiredSpeed, car.CurrentSpeed, dt)
car:SetThrottle(throttle)
end)
Debug
Creates a folder that contains attributes that can be used to tune the PID during runtime within the explorer.
Studio Only
This will only create the folder in Studio. In a real game server, this function will do nothing.
Destroy
PID:
Destroy
(
) →
(
)
Destroys the PID. This is only necessary if calling PID:Debug
.