Skip to content

Commit

Permalink
PID Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Feb 7, 2024
1 parent c885c34 commit 020e14c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
26 changes: 23 additions & 3 deletions modules/pid/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function PID:Debug(name: string, parent: Instance?)

local folder = Instance.new("Folder")
folder.Name = name
folder:AddTag("__pidebug__")
folder:AddTag("PIDDebug")

local function Bind(attrName, propName)
folder:SetAttribute(attrName, self[propName])
Expand All @@ -149,12 +149,32 @@ function PID:Debug(name: string, parent: Instance?)
folder:SetAttribute("Output", self._min)

local lastOutput = 0
self.Calculate = function(...)
lastOutput = PID.Calculate(...)
self.Calculate = function(s, sp, pv, ...)
lastOutput = PID.Calculate(s, sp, pv, ...)
folder:SetAttribute("Output", lastOutput)
return lastOutput
end

local delayThread: thread? = nil
folder:SetAttribute("ShowDebugger", false)
folder:GetAttributeChangedSignal("ShowDebugger"):Connect(function()
if delayThread then
task.cancel(delayThread)
end

local showDebugger = folder:GetAttribute("ShowDebugger")

if showDebugger then
delayThread = task.delay(0.1, function()
delayThread = nil
if folder:GetAttribute("ShowDebugger") then
folder:SetAttribute("ShowDebugger", false)
warn("Install the PID Debug plugin: https://create.roblox.com/store/asset/16279661108/PID-Debug")
end
end)
end
end)

folder.Parent = parent or workspace
self._debug = folder
end
Expand Down
2 changes: 1 addition & 1 deletion modules/pid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbxutil/pid",
"version": "2.0.0",
"version": "2.1.0",
"main": "init.lua",
"repository": "github:Sleitnick/RbxUtil",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion modules/pid/wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sleitnick/pid"
description = "PID Controller class"
version = "2.0.0"
version = "2.1.0"
license = "MIT"
authors = ["Stephen Leitnick"]
registry = "https://github.com/UpliftGames/wally-index"
Expand Down

0 comments on commit 020e14c

Please sign in to comment.