EdgeTX / edgetx

EdgeTX is the cutting edge open source firmware for your R/C radio
https://edgetx.org
GNU General Public License v2.0
1.63k stars 342 forks source link

CRSF input for Trainer mode #1607

Open sk8board opened 2 years ago

sk8board commented 2 years ago

Currently, Trainer mode only allows PPM or SBUS input. I am requesting CRSF input for Trainer mode.

Here is why.

I place a receiver in the JR module bay and connect the receiver to the Batt, Ground, and HeartBeat terminals. I then bind the receiver to the student transmitter. If the receiver will output PPM or SBUS, then this allows wireless trainer mode.

The problem is ELRS receivers do not output PPM or SBUS. Therefore, to use student transmitters with internal ELRS, there is a need for trainer mode to support CRSF protocol.

raphaelcoeffic commented 2 years ago

@wimalopaan would you be interested in adding this to your trainer protos?

rotorman commented 2 years ago

Luckily the channel data in CRSF is encoded 1-to-1 as with S.BUS. Here as a helper, a short CRSF parsing code by kobata, where he connected a HappyModel EP2 receiver via MCU to USB to act as a joystick: https://qiita.com/kobatan/items/40728fbb625057d9f42b

wimalopaan commented 2 years ago

@wimalopaan would you be interested in adding this to your trainer protos?

Yes, I'll have look at it

wimalopaan commented 2 years ago

Does anyone have a full protocol spec at hand? For this the control-part (no sensor reply) would be sufficient.

What would be the best test-setup for someone not owning CRSF hardware? Are the PC-based generators e.g. to use with some USB/serial converter?

wimalopaan commented 2 years ago

Luckily the channel data in CRSF is encoded 1-to-1 as with S.BUS. Here as a helper, a short CRSF parsing code by kobata, where he connected a HappyModel EP2 receiver via MCU to USB to act as a joystick: https://qiita.com/kobatan/items/40728fbb625057d9f42b

Crossfire is a bidi protocol as oppsed to SBUS oder IBUS-Controlpart.

At a first glance it looks like the Crossfire-RX does not expect anything from the FC (the radio in this case) to be returned for packets of type CRSF_ADDRESS_FLIGHT_CONTROLLER and CRSF_FRAMETYPE_RC_CHANNELS_PACKED. Is this assumption correct?

rotorman commented 2 years ago

Correct, you could just wire up the EP2 (CRSF) receiver TX line and leave the RX unconnected. Here a capture from the EP2 TX line (snippet):

C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21 
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 0C 14 35 00 64 0C 00 07 00 00 00 00 2E
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21 
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21

What you get are CRSF_FRAMETYPE_RC_CHANNELS_PACKED (third byte 0x16) and CRSF_FRAMETYPE_LINK_STATISTICS (third byte 0x14) packets.

wimalopaan commented 2 years ago

Correct, you could just wire up the EP2 (CRSF) receiver TX line and leave the RX unconnected. Here a capture from the EP2 TX line (snippet):

C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21 
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 0C 14 35 00 64 0C 00 07 00 00 00 00 2E
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21 
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21

Cool, thanks for the data: will use that as replay ...

wimalopaan commented 2 years ago

If I would like to get real HW, what would you suggest as RF-Module and RX? Available, simple and cheap...

rotorman commented 2 years ago

Here some more change in data for your experiments:

C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21
C8 0C 14 35 00 64 0C 00 07 00 00 00 00 2E
C8 18 16 EA 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 BB 
C8 18 16 EC 03 9F 4B 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 9D 
C8 18 16 EA 03 9F 4B 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 07 
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 21 
C8 18 16 EC 03 9F 49 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 DC DA 37 
C8 18 16 EA 03 9F 4B 99 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 DC DA 11
C8 18 16 EC 03 9F 49 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 FF 
C8 18 16 EC 03 9F 49 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 7C D3 0B 
C8 18 16 EA 03 9F 4B A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 7C D3 2D 
C8 18 16 EA 03 9F 4B A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 D9 
C8 18 16 EC 03 9F 47 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 61 
C8 18 16 EC 03 9F 47 B9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 7C D3 DF 
C8 18 16 EC 03 9F 47 B9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 2B 
C8 0C 14 35 00 64 0A 00 07 00 00 00 00 FC 
C8 18 16 EC 03 9F 45 B9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 97 
C8 18 16 EC 03 9F 45 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 DD 
C8 18 16 EC 03 9F 45 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 7C D3 29 
C8 18 16 EC 03 9F 45 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 DD
C8 0C 14 35 00 64 0B 00 07 00 00 00 00 68 
C8 18 16 EC 03 9F 45 B9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 97 
C8 18 16 EC 03 9F 47 A9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 7C D3 95 
C8 18 16 EA 03 9F 47 B9 F3 0B F0 81 0F 7C E0 03 1F F8 28 08 00 00 44 1C D7 B1
C8 0C 14 35 00 64 0A 00 07 00 00 00 00 FC 

Have a look at HappyModel ES24TX and EP1 or EP2 Alternatively ES900TX and ES900RX if you want 868 MHz instead (868 MHz units cannot do 500 Hz ELRS, but they have longer range): http://www.happymodel.cn/index.php/2021/02/19/expresslrs-module-es915tx-long-range-915mhz-transmitter-and-es915rx-receiver/

wimalopaan commented 2 years ago

The other protocols like SBUS, IBUS oder SumD/V3 use a fixed known baudrate. As I read CRSF can use different baudrates. But in the hardware-tab there is no more a baudrate selector.

What would be your suggestion how to implement that (at first):

1) use a fixed baudrate (e.g. 400KBaud (or 420KBaud?)) 2) use a user selectable baudrate (we need again a baudrate chooser) 3) autobaud (this may be only a try-n-error strategy by simple trying some well known baudrates).

raphaelcoeffic commented 2 years ago

400k is ok for a start, I think. Autobaud might be doable but it normally requires some bit patterns to be efficient and precise.

raphaelcoeffic commented 2 years ago

There is also the “brute force method” that just switches between known baud rates and tries to decode some traffic.

wimalopaan commented 2 years ago

There is also the “brute force method” that just switches between known baud rates and tries to decode some traffic.

... that's what I meant above under 3)

rotorman commented 2 years ago

Isn't the receiver side always 420k 8N1 irrespective of the update rate? https://github.com/ExpressLRS/ExpressLRS/blob/2f78e06889f75996a7e7aaa6e63e5bd0f9ffd64d/src/lib/CrsfProtocol/crsf_protocol.h#L30

wimalopaan commented 2 years ago

In #1462 now we have

This is available on AUX serial ports (AUX1 or AUX2).

wimalopaan commented 2 years ago

For SUMDV3 I intend to do the following:

So, if one wants to use the binary switches that come in via SUMDV3 trainer, she has to setup the wanted LS as above before.

pfeerick commented 2 years ago

I'll grab another ELRS RX out later to try the CRSF support...

wimalopaan commented 2 years ago

I'll grab another ELRS RX out later to try the CRSF support...

I do not guarantee for anything ;-)

pfeerick commented 2 years ago

It seems to be working fine... only checked with the first four channels so far though :)

wimalopaan commented 2 years ago

It seems to be working fine... only checked with the first four channels so far though :)

Sounds good, thanks for testing.

sk8board commented 2 years ago

Thank you for working on this. Do you know if this enhancement is targeted for a release?

pfeerick commented 2 years ago

Should be in 2.8.

sk8board commented 2 years ago

@pfeerick @raphaelcoeffic

Should be in 2.8.

Is CRSF input for Trainer mode still planned for 2.8? If so, can I test this with 2.8.0-rc3?

gagarinlg commented 2 years ago

It is not going to be in 2.8.when you check PR #1462, you will see, that it needs to be rebased I clouding a bunch of manual work for translations.

wimalopaan commented 2 years ago

Maybe you want to checkout my https://github.com/wimalopaan/edgetx/tree/wmibus_telem branch for this. This is more uptodate.

pfeerick commented 2 years ago

So #1861 supercedes and includes #1462?

wimalopaan commented 2 years ago

Yes, it does. It includes SBus/IBus/SumDV1-3 trainer input (up to 32 channels if EXTENDED_TRAINER is set) and FrSky-Telemetry-Input.

raphaelcoeffic commented 2 years ago

It includes SBus/IBus/SumDV1-3 trainer input (up to 32 channels if EXTENDED_TRAINER is set) and FrSky-Telemetry-Input.

Kind of a "pot pourri", we'll need to sort that out and extract features one by one.

wimalopaan commented 2 years ago

Yes, it is. Actually I don't have time to sort that out by myself ... sorry. But please don't hesitate to cherry pick the parts.

pfeerick commented 2 years ago

Lol... have no fear, the skeleton will be picked clean, and credit given where credit is due ;)