Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Trim acc #457

Closed
wants to merge 9 commits into from
Closed

Trim acc #457

wants to merge 9 commits into from

Conversation

druckgott
Copy link
Contributor

Added A new Page fro Trim Accelerometer

Add new Page:
title = "Trim Accelerometer", script = "acc_calibrate.lua"
Add Page to Trim Accelerometer:
MSP_ACC_TRIM
MSP_SET_ACC_TRIM

{ "acc_trim_pitch",             VAR_INT16  | MASTER_VALUE, .config.minmax = { -300, 300 }, PG_ACCELEROMETER_CONFIG, offsetof(accelerometerConfig_t, accelerometerTrims.values.pitch) },
    { "acc_trim_roll",              VAR_INT16  | MASTER_VALUE, .config.minmax = { -300, 300 }, PG_ACCELEROMETER_CONFIG, offsetof(accelerometerConfig_t, accelerometerTrims.values.roll) },
local labels = {}
local fields = {}

if apiVersion >= 1.041 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if apiVersion >= 1.041 then
if apiVersion >= 1.16 then

@@ -0,0 +1,30 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want this

local labels = {}
local fields = {}

if apiVersion >= 1.041 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values have been available through msp in betaflight since msp api version 1.16(we had msp over telemetry since then) so this conditional is not needed.

We only need conditionals like this in the page file itself if parameters are removed/added to the message along the way.
In this case the only conditional needed is the one in "pages.lua" that makes the whole page conditional to msp api version 1.16

What would happen here is that for api versions lower than 1.41 the page would still be accessible, but would be empty.

if apiVersion >= 1.041 then
labels[#labels + 1] = { t = "Trim Accelerometer" , x = x, y = inc.y(lineSpacing) }
fields[#fields + 1] = { t = "acc trim pitch", x = x, y = inc.y(lineSpacing), sp = x + sp, min = -300, max = 300, vals = { 1 } }
fields[#fields + 1] = { t = "acc trim roll", x = x, y = inc.y(lineSpacing), sp = x + sp, min = -300, max = 300, vals = { 2 } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much indent.
The field text could also be just "Pitch" and "Roll" since the "Trim Accelerometer" header explains it all. These should also be indented. "x = x + indent" for both of these. Look at the other pages to see how we usually do it.

This won't work as it should. both pitch and roll trim are 16 bit values so for pitch it should be "vals = { 1, 2 }" and for roll "vals = { 3, 4 }". Have a look at the MSP_ACC_TRIM" message in the BF source code. 🙂

@@ -56,4 +56,8 @@ if apiVersion >= 1.41 then
PageFiles[#PageFiles + 1] = { title = "GPS PIDs", script = "gpspids.lua" }
end

if apiVersion >= 1.16 then
PageFiles[#PageFiles + 1] = { title = "Trim Accelerometer", script = "acc_calibrate.lua" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "acc_trim.lua" would be a more appropriate filename since we already have similarly named files to calibrate the accelerometer.

title = "ACC",
reboot = true,
eepromWrite = true,
minBytes = 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this message we need at least 4 bytes to be able to do anything.

read = 240, -- MSP_ACC_TRIM
write = 239, -- MSP_SET_ACC_TRIM
title = "ACC",
reboot = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a reboot needed for the trim to take effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's needed. How can I test this?

Thx for all the other informations it's my fist commit,didnt know all the thinks only test it and it works 😉.

What happens if I do Wirte only 1 instead of 1, 2 due to 16 bit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"reboot = false". Then try making some changes, save the page and see if it took effect 🙂

What happens is that the pitch field will modify the first byte of pitch trim and the roll field will modify the second byte of pitch trim. So the roll field will make unintended changes to pitch trim, and you won't be able to change roll trim at all

1.remove first line
2. remove: if apiVersion >= 1.041 then ...
3. fix indent
4. add: x = x + indent
5. change name acc_calibrate.lua --> acc_trim.lua
6. reboot      = false, 
7. minBytes    = 4,
8. fix vals
remove due to name change
@druckgott
Copy link
Contributor Author

Fixed all points and tested it. Worked for me.

@klutvott123
Copy link
Member

Negative values doesn't display properly. We haven't had to deal with negative values in the bf lua scripts until now so everything is treated as unsigned. We'll have to look into that

Comment on lines 14 to 16
labels[#labels + 1] = { t = "Trim Accelerometer", x = x, y = inc.y(lineSpacing) }
fields[#fields + 1] = { t = "Pitch", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = -300, max = 300, vals = { 1, 2 } }
fields[#fields + 1] = { t = "Roll", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = -300, max = 300, vals = { 3, 4 } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're using tabs here. use spaces to align things.

Change Tab to Space
@druckgott
Copy link
Contributor Author

Ok yes I also so this this -1 ore <=-1, do you have an Idea where we have to change the code to get this working. Is there any way ob debuggin?

@druckgott
Copy link
Contributor Author

druckgott commented Nov 13, 2022

Ok now the problem with negativ values is fixed. I do not exactly know there the limit is by switching to negativ calculation so I selected 65000 because this will never reached from -300 to 300

@druckgott druckgott requested review from klutvott123 and haslinghuis and removed request for klutvott123 November 13, 2022 11:13
@klutvott123
Copy link
Member

@druckgott I think it's better if we handle this in a more generic way. See #458
With this your PR should work without the postLoad function

@druckgott
Copy link
Contributor Author

ok I removed it again and if your fix is done then it should be fine.

@klutvott123
Copy link
Member

Looks good to me. You just need to squash to one commit now 👍

@druckgott
Copy link
Contributor Author

How can I squash to one commit now?

@klutvott123
Copy link
Member

git rebase -i HEAD~9
you'll get a list of the last 9 commits and a bunch of actions. every commit is prepended with "pick" as default. Replace "pick" with "fixup" or "f" for all commits except the top one that you want to keep. This will leave you with one commit with all your changes.
Then git push --force-with-lease to push your changes

@druckgott
Copy link
Contributor Author

Mhh I cant get it working. I did all the things bevor online direct on github.com and not with git clone ....
can you fix it, next time I will directly do it with git on windows.

@klutvott123
Copy link
Member

Just make a new PR

@druckgott druckgott mentioned this pull request Nov 14, 2022
@druckgott
Copy link
Contributor Author

Did a new one:
#459

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants