Skip to content

Commit 30cc6c0

Browse files
committed
PWM page improvements
1 parent 72d257b commit 30cc6c0

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/SCRIPTS/BF/PAGES/pwm.lua

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ local inc = { x = function(val) x = x + val return x end, y = function(val) y =
1616
local labels = {}
1717
local fields = {}
1818

19+
local gyroSampleRateKhz
20+
21+
if apiVersion >= 1.043 then
22+
gyroSampleRateKhz = assert(loadScript("/SCRIPTS/BF/BOARD_INFO/"..mcuId..".lua"))().gyroSampleRateHz / 1000
23+
end
24+
1925
local escProtocols = { [0] = "PWM", "OS125", "OS42", "MSHOT" }
2026

2127
if apiVersion >= 1.020 then
@@ -37,23 +43,24 @@ if apiVersion >= 1.043 then
3743
escProtocols[#escProtocols + 1] = "DISABLED"
3844
end
3945

46+
labels[#labels + 1] = { t = "System Config", x = x, y = inc.y(lineSpacing) }
4047
if apiVersion >= 1.031 and apiVersion <= 1.040 then
41-
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 }
48+
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 }
4249
end
43-
44-
if apiVersion >= 1.016 then
45-
if apiVersion <= 1.042 then
46-
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 }
47-
fields[#fields + 1] = { t = "PID Loop", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 1, max = 16, vals = { 2 }, table = {}, mult = -1 }
48-
end
49-
fields[#fields + 1] = { t = "Protocol", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = #escProtocols, vals = { 4 }, table = escProtocols }
50-
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" } }
51-
fields[#fields + 1] = { t = "PWM Frequency", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 200, max = 32000, vals = { 5, 6 }, }
50+
if apiVersion >= 1.043 then
51+
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 }
52+
else
53+
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 }
5254
end
55+
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 }
5356

57+
labels[#labels + 1] = { t = "ESC/Motor", x = x, y = inc.y(lineSpacing) }
58+
fields[#fields + 1] = { t = "Protocol", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = #escProtocols, vals = { 4 }, table = escProtocols }
5459
if apiVersion >= 1.031 then
55-
fields[#fields + 1] = { t = "Idle Throttle %", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 2000, vals = { 7, 8 }, scale = 100 }
60+
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 }
5661
end
62+
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" } }
63+
fields[#fields + 1] = { t = "Frequency", x = x + indent*2, y = inc.y(lineSpacing), sp = x + sp, min = 200, max = 32000, vals = { 5, 6 }, }
5764

5865
return {
5966
read = 90, -- MSP_ADVANCED_CONFIG
@@ -81,6 +88,7 @@ return {
8188
end,
8289
calculateGyroRates = function(self, baseRate)
8390
local idx = self.getGyroDenomFieldIndex(self)
91+
baseRate = gyroSampleRateKhz or baseRate
8492
for i=1, 32 do
8593
self.gyroRates[i] = baseRate/i
8694
self.fields[idx].table[i] = string.format("%.2f",baseRate/i)

src/SCRIPTS/BF/pages.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if apiVersion >= 1.042 then
3333
end
3434

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

3939
if apiVersion >= 1.016 then

0 commit comments

Comments
 (0)