Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
PWM page improvements
  • Loading branch information
klutvott123 committed Oct 28, 2021
commit 51d92671e1bcf6ee3fcfa6bcd18fe2b91579b34f
30 changes: 19 additions & 11 deletions src/SCRIPTS/BF/PAGES/pwm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ local inc = { x = function(val) x = x + val return x end, y = function(val) y =
local labels = {}
local fields = {}

local gyroSampleRateKhz

if apiVersion >= 1.043 then
gyroSampleRateKhz = assert(loadScript("BOARD_INFO/"..mcuId..".lua"))().gyroSampleRateHz / 1000
end

local escProtocols = { [0] = "PWM", "OS125", "OS42", "MSHOT" }

if apiVersion >= 1.020 then
Expand All @@ -37,23 +43,24 @@ if apiVersion >= 1.043 then
escProtocols[#escProtocols + 1] = "DISABLED"
end

labels[#labels + 1] = { t = "System Config", x = x, y = inc.y(lineSpacing) }
if apiVersion >= 1.031 and apiVersion <= 1.040 then
fields[#fields + 1] = { t = "32kHz Sampling", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 1, vals = { 9 }, table = { [0] = "OFF", "ON" }, upd = function(self) self.updateRateTables(self) end }
fields[#fields + 1] = { t = "32kHz Sampling", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 1, vals = { 9 }, table = { [0] = "OFF", "ON" }, upd = function(self) self.updateRateTables(self) end }
end

if apiVersion >= 1.016 then
if apiVersion <= 1.042 then
fields[#fields + 1] = { t = "Gyro Update", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 1, max = 32, vals = { 1 }, table = {}, upd = function(self) self.updatePidRateTable(self) end, mult = -1 }
fields[#fields + 1] = { t = "PID Loop", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 1, max = 16, vals = { 2 }, table = {}, mult = -1 }
end
fields[#fields + 1] = { t = "Protocol", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = #escProtocols, vals = { 4 }, table = escProtocols }
fields[#fields + 1] = { t = "Unsynced PWM", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 1, vals = { 3 }, table = { [0] = "OFF", "ON" } }
fields[#fields + 1] = { t = "PWM Frequency", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 200, max = 32000, vals = { 5, 6 }, }
if apiVersion >= 1.043 then
fields[#fields + 1] = { t = "Gyro Update", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 1, max = 32, vals = { 1 }, table = {}, upd = function(self) self.updatePidRateTable(self) end, mult = -1, ro = true }
else
fields[#fields + 1] = { t = "Gyro Update", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 1, max = 32, vals = { 1 }, table = {}, upd = function(self) self.updatePidRateTable(self) end, mult = -1 }
end
fields[#fields + 1] = { t = "PID Loop", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 1, max = 16, vals = { 2 }, table = {}, mult = -1 }

labels[#labels + 1] = { t = "ESC/Motor", x = x, y = inc.y(lineSpacing) }
fields[#fields + 1] = { t = "Protocol", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = #escProtocols, vals = { 4 }, table = escProtocols }
if apiVersion >= 1.031 then
fields[#fields + 1] = { t = "Idle Throttle %", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 2000, vals = { 7, 8 }, scale = 100 }
fields[#fields + 1] = { t = "Idle Throttle %", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 2000, vals = { 7, 8 }, scale = 100 }
end
fields[#fields + 1] = { t = "Unsynced PWM", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 1, vals = { 3 }, table = { [0] = "OFF", "ON" } }
fields[#fields + 1] = { t = "Frequency", x = x + indent*2, y = inc.y(lineSpacing), sp = x + sp, min = 200, max = 32000, vals = { 5, 6 }, }

return {
read = 90, -- MSP_ADVANCED_CONFIG
Expand Down Expand Up @@ -81,6 +88,7 @@ return {
end,
calculateGyroRates = function(self, baseRate)
local idx = self.getGyroDenomFieldIndex(self)
baseRate = gyroSampleRateKhz or baseRate
for i=1, 32 do
self.gyroRates[i] = baseRate/i
self.fields[idx].table[i] = string.format("%.2f",baseRate/i)
Expand Down
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/pages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if apiVersion >= 1.042 then
end

if apiVersion >= 1.016 then
PageFiles[#PageFiles + 1] = { title = "Gyro / Motor", script = "pwm.lua" }
PageFiles[#PageFiles + 1] = { title = "System / Motor", script = "pwm.lua" }
end

if apiVersion >= 1.016 then
Expand Down