Skip to content

Mavlink to Ardupilot Custom Telemetry CRSF translation for Yaapu Telemetry Script - #3077

Merged
pkendall64 merged 1 commit into
masterfrom
unknown repository
Apr 23, 2025
Merged

pkendall64 merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Dec 21, 2024 •

Copy link
Copy Markdown

This PR addresses Issue #3074 adding
Mavlink to Ardupilot Custom Telemetry CRSF translation for Yaapu Telemetry Lua script to work.

Tested on a 128x64 BW Radio:

  • Horizon Pitch Indication
  • Horizon Roll Indication
  • Horizon Compass Indication
  • Distance to Home Indication when home location was set, typically 6 Sats necessary.
  • Heading to Home when flying
  • Battery1 Voltage Indication
  • Battery1 Current Indication
  • Battery1 Capacity Indication (requires capacity override to be set by config)
  • GPS Number of Sats Indication
  • GPS Fix Indication
  • GPS HDOP Indication
  • Altitude MSL
  • Arming State Indication
  • Failsafe Indication
  • Control Mode Switching and Audio Indication (for Plane!)
  • Waypoint switching and Audio Indication
  • Control Mode Switching and Audio Indication ("Stabilize" for Copter)

Stuff that needs to be tested:

  • Functionality on Big Radios

Known Issue List:

  • When GPS Fix is lost, NO 2D is shown. It does seem to be an issue of the Yaapu script.
  • As by reports from testers, the big radios with color lcd seem to have problems for unknown reasons.

@ghost
ghost marked this pull request as draft December 21, 2024 08:32
@ghost

ghost commented Dec 21, 2024 •

Copy link
Copy Markdown
Author

StatusText already works when cherry-pick'ed onto 3.5.3.
Note: Building the branch directly results in the branch name taken for version and consequently RX and TX don't bind.
The other message types will be handled in consecutive patches.

@pkendall64

Copy link
Copy Markdown
Collaborator

Note: Building the branch directly results in the branch name taken for version and consequently RX and TX don't bind.

The master branch has a different OTA version and will not bind to a 3.x version. It's not to do with the branch name.

@ghost

ghost commented Dec 21, 2024 •

Copy link
Copy Markdown
Author

Thanks for clarification, I just saw the name of my branch on the led display and thus assumed it was taken as version.

After some trial and error with the first value, endianess, shifting, ... , I think I'll divide the PR between ExpressLRS and Yaapu Script, as there are standard CRSF frames available for the values that Yaapu Script processes.

Means the frame grabbing
https://github.com/yaapu/FrskyTelemetryScript/blob/master/OTX_ETX/bw128x64/SRC/yaapu7.lua#L778
and the value extraction
https://github.com/yaapu/FrskyTelemetryScript/blob/master/OTX_ETX/bw128x64/SRC/yaapu7.lua#L640

It should be the same amount of work resulting in cleaner design.
As far as I see it, only the STATUS_TEXT is not available as a standard CRSF frame.

@ghost

ghost commented Dec 25, 2024

Copy link
Copy Markdown
Author

Basic functions are checked. I'm tracing 1 number format issue with altitude numbers changing to 1023000 value for unknown reason.

I label this ready for review. Please advise where to locate this code. Separate file, class or lib?

I'll rework as requested.

@ghost
ghost marked this pull request as ready for review December 25, 2024 14:28
@ghost ghost changed the title [WIP] Mavlink to CRSF Telemetry Forgery for Yaapu Telemetry Script Mavlink to Ardupilot Custom Telemetry CRSF translation for Yaapu Telemetry Script Dec 25, 2024
@ghost

ghost commented Dec 25, 2024 •

Copy link
Copy Markdown
Author

Rebased and squashed for convenience.
Note: It turned out that the Yaapu Telemetry script is porcelain, i.e. any change to it risks exceeding the memory and crashing the script.

@wvarty wvarty added enhancement 🪄 New feature or request V4.0 🍔 labels Dec 26, 2024
@wvarty

wvarty commented Dec 26, 2024

Copy link
Copy Markdown
Collaborator

Please advise where to locate this code. Separate file, class or lib?

I'll rework as requested.

I think where you have written it is fine, and exactly where we'd want it. Lots of requests for this feature from the community... Nice work!

@ghost

ghost commented Dec 26, 2024

Copy link
Copy Markdown
Author

Honestly, it can just be some intermediary solution until EdgeTX provides native mavlink support.

This proprietary multi-stage passthru protocol was horrible to reverse engineer.
Mavlink -> FrSky -> CRSF -> LUA script

@ghost

ghost commented Dec 28, 2024

Copy link
Copy Markdown
Author

Short update
The heading to HOME may be fixed now. Own heading was subtracted twice, once by me and another time by HUD7.lua.

The Altitude Value Issue is related to the TERRAIN message altitude. Likely a wrong and too high number.

@ghost

ghost commented Dec 28, 2024

Copy link
Copy Markdown
Author

I found a caveat in my concept.
Turns out that mavlink message HOME_POSITION is sent once on arming and not cyclic.
Means that position Lon, Lat has to be saved and distance + heading must be calculated locally after GPS related mavlink messages. Not sure how to do this yet but I'll try to use ardupilot codebase for that.

@ghost

ghost commented Dec 29, 2024 •

Copy link
Copy Markdown
Author

Switched to calculating distance and bearing locally.

Copied and adapted a whole lot of Ardupilot Code from AP_Common and AP_Math.

From my observations, Ardupilot sends the HOME_POSITION mavlink message cyclically until armed, so testing can only be done when armed.

I still have to fly with this change to see if it's any good now.

EDIT: Please advise on the failed builds for ESP8285 etc. due to missing endian.h . How should I rework this or is the build guaranteed to be little endian?

@ghost

ghost commented Dec 29, 2024

Copy link
Copy Markdown
Author

As far as I could test on a 128x64BW Radio, everything works as expected now.
Rebased and Squashed for convenience.

Please advise on the htole32 topic and then we need some beta testers.

@ghost
ghost requested a review from wvarty December 29, 2024 13:52
@ghost

ghost commented Dec 29, 2024

Copy link
Copy Markdown
Author

@tridge @peterbarker @rmackay9
Gents, I'd like to communicate that I'm using a decent amount of snippets from AP_Common, AP_Math, AP_Frsky_Telem, AP_RCTelemetry for this feature.

@yaapu
Sir, I'd like to communicate that with this feature, I feed "forged" Ardupilot Custom Telemetry into your FrSkyTelemetry Script.

@robustini

robustini commented Dec 29, 2024 •

Copy link
Copy Markdown

@tridge @peterbarker @rmackay9 Gents, I'd like to communicate that I'm using a decent amount of snippets from AP_Common, AP_Math, AP_Frsky_Telem, AP_RCTelemetry for this feature.

@yaapu Sir, I'd like to communicate that with this feature, I feed "forged" Ardupilot Custom Telemetry into your FrSkyTelemetry Script.

The important thing is that it works, thank you for your PR!

@pkendall64

Copy link
Copy Markdown
Collaborator

@menschel Can you rewrite the float code as fixed point integer math. The problem is that floating point on ESP devices is slow, especially on 8285 based devices as they do not have a floating point unit. Also, the floating point math is problematic on the dual core ESP32 as it is not multicore safe and would require locking which we cannot afford to do in a time-critical application like ELRS.

@yaapu

yaapu commented Dec 31, 2024

Copy link
Copy Markdown

@yaapu
Sir, I'd like to communicate that with this feature, I feed "forged" Ardupilot Custom Telemetry into your FrSkyTelemetry Script.

@menschel hi, I did not look at the code but was wondering how the telemety scheduler worked, what is the expected rate for custom passthrough frames, I ask because it is very possible that a high telemetry rate could kill the lua script for excessive cpu or memory load.
As you found out youself recent edgetx versions reduced the available amount of lua memory and my scripts now barely fit
A much better test platform would be a color lcd radio or an ethos radio.

Are you planning on implementing all the passthrough frames?

@ghost

ghost commented Dec 31, 2024 •

Copy link
Copy Markdown
Author

Can you rewrite the float code as fixed point integer math.

Sure. I'll check if it works just by typedef'ing the ftype to uint64_t. Seems mandatory precision is degE7.

EDIT:
https://github.com/ExpressLRS/ExpressLRS/pull/3077/files#diff-65f24b1e2b67aca71adb33cf49a38988ecfa80f8d3ef5433302f1f41ebd81420R254
I'll go for a linear fractional approach because it is sufficient to achieve 3deg accuracy. That will remove all floats in the calculation.

...how the telemetry scheduler worked ...

There is none, just a simple event-based translation based on what Mavlink message comes in.
You can argue that there is a scheduler in Ardupilot GCS_Mavlink though.
What comes in on 900Mhz is worse then CRSF from before, approx. 12 Mavlink messages per second.

Are you planning on implementing all the passthrough frames?

Not all, I have implemented everything that I saw on my setup with Plane 4.5.7.
I consider this a workaround until EdgeTX supports native Mavlink.

@mha1

mha1 commented Dec 31, 2024

Copy link
Copy Markdown
Contributor

Sure. I'll check if it works just by typedef'ing the ftype to uint64_t. Seems mandatory precision is degE7.

ESP8285/32 are 32bit processors which means they can't do 64bit integer math natively and have to do 64bit integer math in software which makes it very slow. So using uint64_t is not a solution. You need to work with scaled uint32_t integers. Doing it right you won't have a loss of precision, just lower resolution. Here's a little intro to scaled integers: https://developerhelp.microchip.com/xwiki/bin/view/software-tools/c-programming/variables/data-types/scaled-integers/

@ghost
ghost marked this pull request as draft January 1, 2025 10:45
@ghost

ghost commented Jan 1, 2025

Copy link
Copy Markdown
Author

Reworked to fixed point with a few simplifications.
atan2 has been replaced with tangens theorem based approach

I have not yet flown with this change. I'll squash and rebase when master is updated.

@mha1

mha1 commented Jan 1, 2025

Copy link
Copy Markdown
Contributor

Reworked to fixed point with a few simplifications

Thanks. Why is roundf() still necessary?

@ghost

ghost commented Jan 1, 2025

Copy link
Copy Markdown
Author

Good that you mention it, that prep_number() function also needs to loose float types...

@ShreyyyJ

Copy link
Copy Markdown

@raul-ortega any update on the performance of your setup?
I want to use mavlink with mission planner using Nomad Dual Xrossband ExpressLRS Module and XR4 receiver at K1000Hz packet rate. If anyone tested this setup, I really wanna know the performance you got and the range.

@raul-ortega

Copy link
Copy Markdown

@raul-ortega any update on the performance of your setup?
I want to use mavlink with mission planner using Nomad Dual Xrossband ExpressLRS Module and XR4 receiver at K1000Hz packet rate. If anyone tested this setup, I really wanna know the performance you got and the range.

Nothing, due to wheather conditions!

@ghost

ghost commented Mar 20, 2025 via email

Copy link
Copy Markdown
Author

@Allister779

Copy link
Copy Markdown

I've got a nomad module, a Quad-plane w/XR4 on AP4.6b4+, and quad w/DBR4 on AC4.5.7. Both on K1000. I'm willing to at least ground test this if it will help the cause. Please tell me what Git commit hash to use because I see a few bounced around here and I'm not sure what's best/safest. Or can I just build from the Git pull request?

@ghost

ghost commented Mar 26, 2025 via email

Copy link
Copy Markdown
Author

@Allister779

Copy link
Copy Markdown

I'm not familiar with Git commands so I first tried to use the Git Pull Request function in configurator to build for this PR. The build went okay for the nomad, but it wouldn't connect to any of my receivers (I didn't update them). Verified UID, etc. Admittedly didn't fight too long.

Next I used the commit hash for your latest commit in the test353 branch (940fb5) and let Configurator build it for me. That seemed to work. Again, only changed the nomad.

Good news, at least so far on the bench it's all working!
The Nomad is on build 940fb5 (TX16s Edge 2.10.2)
DBR4 is on 3.5.3 (AC4.5.7)
XR4 is on 3.5.2-pr3035 (AP4.6.0B4+ Tridge's test B5)

The yaapu script did crash on me once in all the excitment, but it was just the script. The radio and other telem pages still worked fine.

Any concerns about flying this configuration?

@ghost

ghost commented Mar 26, 2025 via email

Copy link
Copy Markdown
Author

@robustini

robustini commented Mar 27, 2025 •

Copy link
Copy Markdown

@Allister779 update EdgeTX to 2.16 and use the DEV version of Yaapu.
No crashes here for ages.
It is normal that if you use the branch indicated 353 and the current master you can't do the bind, there are differences.
Remember to flash the rxes as well.

@Allister779

Copy link
Copy Markdown

Got a chance to finally fly it today. On AC4.6 beta5, and EdgeTX 2.10.6 (Yaapu on Dev).

Good: It worked in flight.
Bad:

  • Yaapu crashed once before I took off. Error in refresh(): CPU Limit. Power cycled everything and it worked.
  • On both flights I got a voice warning "motors disarmed" followed quickly by "motors armed" and my flight mode. You'll excuse me for not looking down at the screen at that moment.... It only happened once per flight.
  • After the second flight the radio seemed to have totally locked up. Based on the messages on the screen everything was working until the point I landed and disarmed. I couldn't seem to do anything on the radio, none of the buttons did anything.

If you need any more info let me know.

@raul-ortega

raul-ortega commented Apr 10, 2025 via email •

Copy link
Copy Markdown

@ghost

ghost commented Apr 11, 2025 via email

Copy link
Copy Markdown
Author

@Allister779

Copy link
Copy Markdown

Mine is a Mk1 Max. I can't remember when I got it, but it's got some good miles on it.

The sequence was just as you described, except one time rather than saying "Manual Flight Mode" it said "Position Hold".

I don't know about the RF Mode. I was less than 40m away each time it happened. When I did look down the only thing I noticed was my dynamic power was still down at 10mw so I'm assuming it was happy with the connection.

@ghost

ghost commented Apr 11, 2025 via email

Copy link
Copy Markdown
Author

@raul-ortega

raul-ortega commented Apr 11, 2025 •

Copy link
Copy Markdown

Mine was one of the firsts Radiomaster TX16S, without touch screen. This has been working for a long time, without any issues using yaapu lua script, working with CRSF protocol. Now I'm using K1000 and this is the first time I see this issue in the yaapu lua script.

This information is irrelevant: In my case I was not using dynamic power, TX was configure at 500mw and Rx at 100mw. SRx params were set by default by Mission Planner. I was flying at a very short distance, no more than 180 meters.

Some info about my setup:

  • Yaapu Telemetry Widget: 2.0.x dev (1997425)
  • Handset: Radiomaster TX16S
  • EdgeTX 2.10.5 (Centurion)
  • TX: Radiomaster Nomad TX 2.4/900Hz
  • RX: Radiomaster XR4
  • RF Band: 868 EU
  • TX Power: 500 mw
  • RX Power: 100 mw
  • Paket rate: K1000 Full(-101 dBm)
  • Telem ratio: 1:2(39891bps)
  • Switch mode: 16ch Rate/2.
  • Antenna mode: Gemini
  • Link mode: Mavlink
  • Flight Controller: Speedybee F405 Wing
  • Flight Firmware: Arduplane 4.4.4

@ghost

ghost commented Apr 11, 2025 via email

Copy link
Copy Markdown
Author

@Allister779

Copy link
Copy Markdown

I was on K1000 as well.

Just so I understand, are you in favor of the mLRS approach?

@ghost

ghost commented Apr 12, 2025 via email

Copy link
Copy Markdown
Author

@raul-ortega

raul-ortega commented Apr 12, 2025 via email •

Copy link
Copy Markdown

@robustini

robustini commented Apr 12, 2025 •

Copy link
Copy Markdown

My RM Bandit Micro is supported but only as a SiK Radio

mLRS pre release v1.3.06: full support of RadioMaster Bandit, Bandit Micro, "big" Ranger and BetaFPV 1W Micro ELRS Tx modules
allows JrBay pin5 use, no limit to only SiK anymore.
Support of wireless bridge functionality (using the "backpack").

Instead, it seems to me that your module now would not work only as SiK.
I own both RadioMaster Ranger and BetaFPV 1W Micro, some testing I will definitely do if only out of curiosity.

@MUSTARDTIGERFPV

Copy link
Copy Markdown
Member

If ELRS project would drop the fixed package:telemetry
rate, it would yield equal performance. It is the bottleneck for MAVftp
operations for example.

This is absolutely something we want to support, but we can't with the packet format in 3.0 - we'll hope to get this possible in 4.0

handset->sendTelemetryToTX((uint8_t *)&crsfbatt);

// send the batt1 message to Yaapu Telemetry Script
ap_send_crsf_passthrough_single(0x5003, format_batt1(battery_status.voltages[0], battery_status.current_battery, battery_status.current_consumed));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just out of curiosity, why are you only passing one cell of battery info out of CRSF? Is this a part of the AP CRSF standard? The Yaapu script I'm using seems to expect all the cells, not just 1

Comment thread src/lib/MAVLink/MAVLink.cpp Outdated
* Helper function to send an ardupilot specific CRSF passthrough frame
* with a single data item appid is the function that produces the data.
*/
static void ap_send_crsf_passthrough_single(uint16_t appid, uint32_t data);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove unnecessary duplicate line.

Comment thread src/lib/MAVLink/MAVLink.cpp Outdated
* Helper function to send an ardupilot specific CRSF passthrough frame
* with a text payload.
*/
static void ap_send_crsf_passthrough_text(const char *text, uint8_t severity);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove unnecessary duplicate line.

Comment thread src/lib/MAVLink/MAVLink.cpp Outdated
* Helper function to send an ardupilot specific CRSF passthrough frame
* with 2 data item appid is the function that produces the data.
*/
static void ap_send_crsf_passthrough_multi(uint16_t appid, uint32_t data, uint16_t appid2, uint32_t data2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove unnecessary duplicate line.

Comment thread src/lib/MAVLink/MAVLink.cpp Outdated

CRSF::SetHeaderAndCrc((uint8_t *)&crsftext, CRSF_FRAMETYPE_ARDUPILOT_RESP, CRSF_FRAME_SIZE(sizeof(crsftext)), CRSF_ADDRESS_FLIGHT_CONTROLLER);
handset->sendTelemetryToTX((uint8_t *)&crsftext);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove blank line

Comment thread src/lib/MAVLink/MAVLink.cpp Outdated
// send the gps_status message to Yaapu Telemetry Script
ap_send_crsf_passthrough_single(0x5002, format_gps_status(gps_int.fix_type, gps_int.alt, gps_int.eph, gps_int.satellites_visible));


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One blank line is enough

for Yaapu Telemetry Lua script to work.

Uses CORDIC algo to calculate bearing
and distance to home.

Based on Ardupilot Code but reworked to integer operations.
@ghost

ghost commented Apr 23, 2025 via email

Copy link
Copy Markdown
Author

@ghost

ghost commented Apr 23, 2025 via email

Copy link
Copy Markdown
Author

@pkendall64
pkendall64 merged commit 4763c8a into ExpressLRS:master Apr 23, 2025
@ghost
ghost deleted the pr-fix-ap-crsf-custom-telem branch April 23, 2025 09:41
@edombek

edombek commented Sep 6, 2025

Copy link
Copy Markdown

This is not on 3.6.0 (((

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 🪄 New feature or request V4.0 🍔

Projects

None yet

Development

Successfully merging this pull request may close these issues.