Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Support GVs in calculated telemetry sources #2096

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

functionpointer
Copy link

@functionpointer functionpointer commented Jun 25, 2022

Fixes #2092

Summary of changes:

Allows calculated telemetry sources (specifically add, average, min, max and multiply) to use GVars as sources.
The multiply source can also divide by GVars, not just multiply.

This is useful for scaling telemetry values in ways that ratio does not support due to limited precision.
Additionally, GVars may be dynamically changed, further expanding the scaling capabilities.

Example:
Auto-detecting the number of cells and scaling a voltage sensor (VFAS, blheli32 telemetry) to produce average cell voltage.

Current state:

  • Missing gui for colorlcd.
  • Gui works on simulated X9LITE.
  • Tested and works on real X9D+.

See also:
opentx/opentx#8436
opentx/opentx#6293
opentx/opentx#3593

@Eldenroot
Copy link
Contributor

Any progress? @functionpointer

@functionpointer
Copy link
Author

Colorlcd looks good in simulator, it would be good to have someone test it for real.

Main thing missing now is Companion

@Eldenroot
Copy link
Contributor

@elecpower - please could you step in? Thx :)

@elecpower
Copy link
Collaborator

@elecpower - please could you step in? Thx :)

I can do the Companion side when you get radio side approval from the main devs.

@functionpointer functionpointer marked this pull request as ready for review July 5, 2022 13:38
@functionpointer
Copy link
Author

Thanks for the offer @elecpower, that is very helpful :)

I have since tested this in an actual flight on X9D+. It works great! I finally have human understandable voltage callouts for my 3s lipo!

The radio side code is ready as far as i am concerned. It would be great to hear some feedback on it.

@pfeerick pfeerick added enhancement ✨ New feature or request telemetry 📶 labels Jul 15, 2022
@elecpower
Copy link
Collaborator

elecpower commented Aug 2, 2022

Ubuntu 20.04
Tested TX16S sim and observed the source drop down list has negative and positive entries mixed. Should be negatives followed by '---' followed by mirrored positives.
Tested X9D+ and X7 sims and source drop down does not list GVs. Tested with both a new model so no sensors and a converted TX16S with sensors. The lists on the sims are as expected but without the GVs obviously.
I have GVARS defined and checked by inserting a TRACE line below line 282 in radio/src/gui/212x64/model_telemetry_sensor.cpp

@functionpointer
Copy link
Author

Source drop down on X9D+? It has a field where you go through sensors with + and - buttons.
You have to Long-Press to get to the GVars. This is the same behaviour as input or mixer weights use.

Am I misunderstanding something?

@elecpower
Copy link
Collaborator

elecpower commented Aug 2, 2022

Source drop down on X9D+? It has a field where you go through sensors with + and - buttons. You have to Long-Press to get to the GVars. This is the same behaviour as input or mixer weights use.

Am I misunderstanding something?

My bad forgot about the long press as I do 99.9% of my config in Companion and didn't even notice log press in code. So retested ok for B&W. Just leaves list order issue for color.

@elecpower
Copy link
Collaborator

I've started work on Companion side

@elecpower
Copy link
Collaborator

Based on the model file from X9D+ sim and this likely explains the TX16S list order, there is an inconsistency with the YAML values for GVs.
Sensors range from negative max radio sensor capability eg -60 to positive max sensor capability eg +60 with no sensor = zero.
GVs on the other hand have this pattern:
+GV1 stored as -128
-GV1 stored as +127
+GV2 stored as -127
-GV2 stored as +126
Sign is inverted and not numerically mirrored as sensors. I assume the existing memory allocation of int8_t is the reason for the reverse increment Though +/- should have the same number especially since we are using YAML now and to match sensors.
There is a risk that should the max radio sensors capability be increased and/or max radio gvars increased (there is a push to do this) we could have an overlap. Unlikely due to the current ranges but possible.

@elecpower
Copy link
Collaborator

Companion coded to use yaml mapping -GV1 -> -127 and GV1 -> 127 -GV2 -> -126 and GV2 -> 126 etc

Screenshot from 2022-08-04 21-12-14

Screenshot from 2022-08-04 21-13-19

@functionpointer
Copy link
Author

I have used the existing mapping functions in gvars.h and gvars.cpp.
As such the mapping is the same as is used by weights and offsets.

I don't know why the pattern was chosen, but my guess is that it was convenient to implement.
Should i abandon the existing mapping and implement the new one you suggested?

@elecpower
Copy link
Collaborator

If we go down the weights and offsets approach then for consistency the yaml read and write for both the radio and Companion will need to be changed for the telemetry calc fields as from memory the textual reference eg GV1 is stored in yaml files if not a numeric value for weights and offsets.
So either we continue to follow the past methods or start a new one for this case. From the radio coding side I would expect better to stick with the devil we know and change the yaml.
One for @raphaelcoeffic to arbitrate on.

@Eldenroot
Copy link
Contributor

Is there any progress, I would like to use this feature. Reqlly useful and could save me a lot of time

@pfeerick pfeerick added this to the 2.9 milestone Sep 9, 2022
@functionpointer
Copy link
Author

@raphaelcoeffic any word on which way we should go?

@Eldenroot
Copy link
Contributor

2 days ago I needed this feature for one of my projects... this makes a lot of things easier (or maybe I do not know another way in edgetx how to live without this feature).

@pfeerick pfeerick modified the milestones: 2.9, 2.10 Apr 10, 2023
@raphaelcoeffic raphaelcoeffic added needs: rebase A git rebase on top of the latest destination branch version is required needs: testing labels Aug 12, 2023
@raphaelcoeffic raphaelcoeffic marked this pull request as draft August 12, 2023 05:23
@pfeerick
Copy link
Member

@philmoz Any chance you can rebase and resolve the conflicts that will arise on the colorlcd side? Also taking this comment about the display of values into account. #2096 (comment)

I think #2096 (comment) is possible material for a separate cleanup PR.

@philmoz
Copy link
Collaborator

philmoz commented Nov 12, 2023

@functionpointer - Are you ok with me updating your fork?

@functionpointer
Copy link
Author

Yes, please.
Is there anything i can help with?

@philmoz
Copy link
Collaborator

philmoz commented Nov 12, 2023

Is there anything i can help with?

Can you sync the main branch in your fork to get it up to date.

@functionpointer
Copy link
Author

Alright i did

@philmoz
Copy link
Collaborator

philmoz commented Nov 13, 2023

Rebased to 39b21b6 and fixed the color LCD code (including the sort order). Should rebase cleanly to later PR's.

Have not fixed the B&W issue.

This is not using the new source select menu - that will require more extensive changes (and can probably wait).

Please test that the color LCD functionality is working as expected.

@pfeerick pfeerick removed the needs: rebase A git rebase on top of the latest destination branch version is required label Nov 13, 2023
@pfeerick
Copy link
Member

pfeerick commented Nov 13, 2023

Have not fixed the B&W issue.

There isn't one AFAIK... on B&W, you long press enter in weight/offset fields for GVs, and that is working as expected. The only outstanding issue is related to yaml storage, hence why material for a different PR.

I've only had a quick glance after flashing to TX16S and X9D+ but it looks somewhat like the colorlcd functionality is as expected. I'll comment further in the next day or so after some actual use of it.

@pfeerick pfeerick marked this pull request as ready for review December 12, 2023 04:47
@pfeerick pfeerick self-requested a review December 12, 2023 04:48
@pfeerick pfeerick changed the title Support GVars in calculated telemetry sources feat: Support GVs in calculated telemetry sources Dec 12, 2023
functionpointer and others added 5 commits January 4, 2024 10:40
…ly to use GVars as sources.

The multiply source can also divide by GVars, not just multiply.
It was using the min variable from its environment before
@pfeerick
Copy link
Member

pfeerick commented Jan 4, 2024

@elecpower Sorry to distract from #4406, but regarding this PR, I finally realised what the issue you was referring to was here... i.e. Companion and radio firmware are at odds with how to index GVs (at least for telemetry sensor purposes)? Thus rendering it impossible to use Companion in conjunction with this feature at present. Although it seems if it is configured exclusively on the radio that Companion won't mangle the settings if you leave that field alone? I'm so tempted to merge this on that premise (with a caution in the release notes), but I'll behave! 😆

How hard would it be to make it so Companion matches the firmware? And then move on from there? Perhaps in the future there should be a gv() type available? Or did you mean make a change here, specific to this option (and potentially work outwards from there)?

@raphaelcoeffic Can you have a look at this, particularly Neil's two earlier comments at: #2096 (comment)

before (as read from TX16S)
image
image

after (set to "correct" value by Companion)
image
image

for reference:
2096-calc_gv_error.etx.zip

@elecpower
Copy link
Collaborator

@pfeerick @raphaelcoeffic IMO this PR should implement one of the methods as shown in the screen shots below so it is crystal clear whether the value is a numeric or a gvar. I am not in favour of yaml containing magic numbers which may cause confusion and can be broken by future features requiring data conversion. There have been requests to increase the number of gvars and this would definitely break the use of +/- 127.
What the firmware and Companion do with it internally is up to each as long as they interpret identically. Companion rawsource and rawswitch are prime examples of different internal handling to firmware.
The code to do the yaml exists so not a big task to implement in this PR.
gvarout
gvarinput
gvarlscf

@elecpower
Copy link
Collaborator

elecpower commented Jan 4, 2024

The yaml parsing is an if then else nightmare now. Why introduce another?

@pfeerick
Copy link
Member

pfeerick commented Jan 4, 2024 via email

@pfeerick pfeerick modified the milestones: 2.10, 2.11 Jan 17, 2024
@pfeerick pfeerick added the needs: rebase A git rebase on top of the latest destination branch version is required label Oct 30, 2024
@gagarinlg
Copy link
Member

Do we want this for 2.11 or better move it to 3.0? I would prefer to move it to 3.0

@pfeerick
Copy link
Member

I think it needs to move, as it is waiting for Raphael's thoughts on how to proceed ;)

@pfeerick pfeerick modified the milestones: 2.11, 3.0 Jan 24, 2025
@functionpointer
Copy link
Author

Good to see this isn't entirely forgotten yet.

I am still using it regularly and it is great.
Unfortunately it will take some rewriting to get it merged, as a good portion of code has changed in the meantime.

Nevertheless, the question of how to store it must be answered first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request needs: rebase A git rebase on top of the latest destination branch version is required needs: testing telemetry 📶
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support GVars in calculated telemetry sources /OTX/
7 participants