ArduPilot / ardupilot

ArduPlane, ArduCopter, ArduRover, ArduSub source
http://ardupilot.org/
GNU General Public License v3.0
10.2k stars 16.78k forks source link

Support for native FrSky telemetry #1587

Closed lakeroe closed 7 years ago

lakeroe commented 9 years ago

Add support for native FrSky telemetry (S.Port based X-Series receiver) using only a simple external inverter (i.e. https://github.com/TauLabs/TauLabs/wiki/User-Guide:-FrSKY-S.PORT-telemetry). Somebody has already started a thread about this: http://ardupilot.com/forum/viewtopic.php?f=100&t=10013

Apart from "real" telemetry data (position, height, velocity, ...) it would be great to also show possible pre-arm check errors.

Two useful links: https://code.google.com/p/telemetry-convert/wiki/FrSkySPortProtocol https://github.com/TauLabs/TauLabs/blob/next/flight/Modules/UAVOFrSKYSPortBridge/UAVOFrSKYSPortBridge.c

lvale commented 9 years ago

Reference also https://github.com/lvale/MavLink_FrSkySPort

Also as a side note, OpenTX is about to have their telemetry handling refactored. https://github.com/opentx/opentx/issues/1634

lakeroe commented 9 years ago

I've recently added some code for native FrSky telemetry. It seems to work quite well and I have done a few test flights so far. The LUA scripts (running on the Taranis) are similar to here: https://github.com/wolkstein/MavLink_FrSkySPort/tree/master

It's also possible to display all text messages sent to the GCS. This is done by not sending the actual message but an ID instead. For this reason I made a quick and dirty hack in GCS_Common.cpp. I defined two global variables uint8_t textId and g_severity and added following code in GCS_MAVLINK::send_text(gcs_severity severity, const char *str)

if (!strcmp(str, "ARMING MOTORS"))
    textId = 1;
else if (!strcmp(str, "PreArm: RC not calibrated"))
    textId = 2;
else if (!strcmp(str, "PreArm: Baro not healthy"))
    textId = 3;
     .
     .
     .
else if (!strcmp(str, "Throttle disarmed"))
    textId = 83;
else
    textId = 0;
g_severity = severity;

I think you'll get the idea ! As this code parses all possible messages (more than 80 so far) I think it's necessary to change this part to a more elegant way. Because the FrSky Taranis is running a LUA script converting the message ID back to the actual text message, it's necessary to keep the text messages and their related IDs in sync. For this reason it would be great to have all messages somewhere stored in a single place (file). It's all a bit complicated to describe but I think you know what I mean. I don't have the programming skills to do such a change but if somebody can do that, I'll do the rest ;-)

lakeroe commented 9 years ago

Hello,

some code for native FrSky telemetry for S.port capable receivers (X4/6/8R) is for download here: http://www.adrive.com/public/U6yfYd/FrSky-Telemetry.zip I tried to submit a "Pull Request" but for some reason it just did not work (Error: Failed to publish this branch). I hope it's okay to append the patch as the changes are not too much (AP_Frsky_Telem.cpp and AP_Frsky_Telem.h can be overwritten completely, changes in the other 3 files are minor).

In order to make this work you need to connect your receiver (X4/6/8R) to your flight controller by an external inverter (https://github.com/TauLabs/TauLabs/wiki/User-Guide:-FrSKY-S.PORT-telemetry) or modify your receiver (http://eleccelerator.com/frsky-x4rsb-smartport-hack-naze32/).

Following parameters are important: SERIAL2_PROTOCOL = 3 (FrSky S-Port) BRD_SER2_RTSCTS = 0 (Disable flow control)

The code seems to work quite well and I have done a few test flights so far, but it's not 100% tested. I have never done any RTOS programming before, so it would be great if an experienced programmer could have a look at the code.

For displaying messages sent to the GCS I made a quick and dirty hack in GCS_Common.cpp. As this code parses all possible messages (about 80 so far) I think it's necessary to change this part to a more elegant way. Because the FrSky Taranis is running a LUA script converting the message ID back to the actual text message, it's necessary to keep the text messages and their related IDs in sync. For this reason it would be great to have all messages stored in a single place (file). It's all a bit complicated to describe but I think you know what I mean ;-) Sorry I can't do that as my programming skills are limited.

By using some LUA scripts it's possible to display following values on the Taranis:

Armed/Disarmed state Flight mode (incl. Simple and Super Simple mode) Battery voltage Battery current Flight time Output throttle Horizontal speed Vertical speed Height Heading (absolut and relative to home) Altitude mode (climb, sink, hold) GPS fix type GPS hdop GPS position (latitude, longitude, altitude) Distance from home Number of satellites used for GPS Artificial horizon All messages sent to the ground station (incl. severity) Further more voice alerts can be played on various events (flight mode change, battery low, message received ...) All telemetry data also gets logged on the internal SD card

Sample screenshots screenshot-1 screenshot-2

Some info about timing: Receiver polls us ~ every 12 ms (83 Hz) and we have to answer within a certain time, so it's necessary to run the main loop with 200 Hz (100 Hz does not work). Our sensor ID get's polled every second time (24 ms) and because we send 16 different values the update rate (on the Taranis display) is ~ 16*24=384 ms (2,6 Hz)

This is tested on FrSky Taranis (OpenTX 2.0.13), X4R. Current is untested because I have no current sensor.

What do you think ?

robustini commented 9 years ago

I think is time to test it... lakeroe, you're the man!

lakeroe commented 9 years ago

Would be great if you can do some testing once the code gets integrated. I will publish the lua scripts and some more (wiki) documentation than as well ...

robustini commented 9 years ago

Can you give me some info about the "external inverter" circuit? I see two mosfet in this schematic but component name is missing.

lakeroe commented 9 years ago

Every standart logic level MOSFET should work. I'll post the FETs I used this evening ...

Here's another inverter schematic: http://www.multiwii.com/forum/viewtopic.php?f=8&t=4507

robustini commented 9 years ago

Thanks! About your commit: at the moment there's big changes in the px4firmware layer (3.3-DEV version), can you align your patch with the latest Copter/Plane release and share a zip with your patch? Remember also the LUA script used in your example... ;-)

lakeroe commented 9 years ago

What's the problem in detail ? It should be enough to overwrite AP_Frsky_Telem.cpp / AP_Frsky_Telem.h and add the few minor changes in the other 3 files. Maybe do a simple file compare. My changes are based on 3.2.0.

I'll have a look at 3.3-DEV later. By the way: 3.3-DEV version ist the same as the master branch, right ?

lakeroe commented 9 years ago

The FETs I use are: BSS138 (https://www.fairchildsemi.com/datasheets/BS/BSS138.pdf) and FDN338P (https://www.fairchildsemi.com/datasheets/FD/FDN338P.pdf)

The LUA scripts are for download here: http://www.adrive.com/public/augCDt/LUA%20scripts.zip

I also just tried the latest master branch (3.3-dev) and it compiles without problems. I didn't test it "in real" though ...

razorbac91 commented 9 years ago

Hi, first of all thank you for your work =) And now the question: is possible to use this project with normal APM 2.6 or i need the pixhawk?

lakeroe commented 9 years ago

This is PixHawk only, for APM you could use the "external" solution: http://diydrones.com/forum/topics/amp-to-frsky-x8r-sport-converter

razorbac91 commented 9 years ago

Ahah as usual i'm not lucky at all xD anyway actualy i use this project http://www.itluxembourg.lu/site/ that allow me to take the mavlink data on the serial port of the tx orange 433 module and send it to pc trough bluetooth module. If i put the teensy in parallel to the bt module and send the telemetry data to the taranis serial port on the battery tray (setted in telemtry mode obviusly) this can work with yours scripts?

lakeroe commented 9 years ago

My scripts work only with my source code posted above. In order to display all the different values you see in the sample screenshots above I have to send different values than the teensy solution ...

razorbac91 commented 9 years ago

Mmmm ok this is bad beaucause i realy like the graphics of yours script :/

lakeroe commented 9 years ago

If you can do some (probably) simple changes in the teensy source it shouldn't be a big problem to get it working with my scripts ...

razorbac91 commented 9 years ago

Mmm i have to try :) thank you for all

laurienzu commented 9 years ago

I use a code with an Arduino Mini Pro on my APM 2.6 and it works very well....I really love your LUA scripts, would be nice if someone can modify this code for our old apm users to have the correct output for your LUA scripts, here the link: https://github.com/vizual54/APM-Mavlink-to-FrSky

badzz commented 9 years ago

Looked at your code but the thing is plane and rover do not have 200hz scheduler see :https://groups.google.com/d/msg/drones-discuss/1gwvlmR8XkA/C4X6rW_lMBoJ

I implemented it using a separate thread as recommended by tridge: https://github.com/diydrones/ardupilot/pull/1800 if you want different sensors id , send me some PR on my branch, I will see what can be done.

lakeroe commented 9 years ago

Hello badzz,

I also had a quick look at your code. Apart from using a separate thread your code is also compatible to standard opentx telemetry values.

Because I wanted to transmit more values I gaveup opentx compatibility, but have to use some LUA scripts instead. If your and my version should be integrated I think we need some kind of switch.

I think it's also necessary to do some code changes to transmit a message id as I wrote some posts above ...

What do you think ?

Best regards, lakeroe

robustini commented 9 years ago

Lakeroe, I tried everything but I can not get this thing working with Pixhawk, i correctly set the parameters:

SERIAL2_PROTOCOL = 3 (FrSky S-Port) BRD_SER2_RTSCTS = 0 (Disable flow control)

All the connections are ok, tx/rx to Telem2 port and the three pin to the S-Port (X8R). The external inverter work fine, tested with uBrain with the same code (adapted for this baord), everything works as expected.

badzz commented 9 years ago

Marco Did you try to connect this way http://copter.ardupilot.com/wiki/common-frsky-telemetry/#X-Receiver_setup . Lakeroe, You are talking about the teensy solution ? I am indeed planning to do a compatibility mode at some point. Thx

robustini commented 9 years ago

I use this simply inverter, Q1 and Q2 are common NPN, BC182:

10930028_10205665517545567_5849225709124840097_n

With "Virtualrobotix uBrain" work fine: https://www.youtube.com/watch?v=VZvY5z89-fs&feature=youtu.be

badzz commented 9 years ago

Ok.. What modification has been done on uBrain ? Any git commit I can look at to understand what is different ? I will check beta build this week end as well to see if anything is wrong. I know that Randy committed SerialManager that could impact frsky driver. Matthias

badzz commented 9 years ago

@marco: try 4, serialmanager modified the way this parameter is handled. I need to update the doc https://github.com/diydrones/ardupilot/blob/master/libraries/AP_SerialManager/AP_SerialManager.h#L75

robustini commented 9 years ago

Already tried, same result.

badzz commented 9 years ago

Just to make sure : which code are you using ? The one in master ? On 30 Jan 2015 23:52, "robustini" notifications@github.com wrote:

Already tried, same result.

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72284562 .

robustini commented 9 years ago

Yes...

badzz commented 9 years ago

ok, and you are not using the LUA script . The code in master shows the standard metrics : T1 (mode) T2 (Sats), voltage, amps ,... I just tested in sitl, and it seems ok with SERIAL2_PROTOCOL=4

On Sat, Jan 31, 2015 at 12:18 AM, robustini notifications@github.com wrote:

Yes...

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72287761 .

lakeroe commented 9 years ago

@Marco Can you try this firmware (Pixhawk version compiled for a quad) ? http://www.adrive.com/public/h3TuJH/PixHawk_3.2.0.zip

It's 3.2.0 including the FrSky telemetry patches and another small change to use a LiPo flasher at auxilary output 3. No other changes ! I use this version for some time now without any problems ...

@Matthias Have you thought about adding the ability to transmit status messages (like in my code) as well ? How do you handle the unavoidable echo you get on the 1-wire s.port ?

robustini commented 9 years ago

@lakeroe Tried now, same result, it doesn't work. I use your firmware and your parameters file. Here the connections, I'm doing the bench test, only with usb connected. Someone else can try with this simple inverter? Maybe I'm doing something wrong, in the afternoon I try with another inverter.

20150131_112936

lakeroe commented 9 years ago

As far as I can tell from the picture the wiring should be okay. As I could see in your video my changes are working with uBrain so I suppose the problem is the inverter circuit. Your pullups are at 5V level but PixHawk uses 3,3V. Do you have an oscilloscope to check the signals or can you try my inverter circuit using FETs ?

badzz commented 9 years ago

@lakeroe It would better to have a native id for those messages. Doing a check on the strings would need quite a bit of maintenance and I do not think that the maintainer would accept it (understandably so). Last time I talked with randy about adding ids on the prearm status, he proposed to have this unified in ap_motor library. I checked it and there is a fait bit work to make that happen. I checked Luis code already in the past and I can make it 90% compatible with his lua script (barring messages as explained above). Are you ids usage very different than his ones? The idea would be to make it optional: standard frsky/lua script compatible. On 31 Jan 2015 10:42, "lakeroe" notifications@github.com wrote:

@Marco https://github.com/Marco Can you try this firmware (Pixhawk version compiled for a quad) ? http://www.adrive.com/public/h3TuJH/PixHawk_3.2.0.zip

It's 3.2.0 including the FrSky telemetry patches and another small change to use a LiPo flasher at auxilary output 3. No other changes ! I use this version for some time now without any problems ...

@Matthias https://github.com/Matthias Have you thought about adding the ability to transmit status messages (like in my code) as well ? How do you handle the unavoidable echo you get on the 1-wire s.port ?

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72311319 .

lakeroe commented 9 years ago

@Matthias What do you mean with "Luis code" ? Currently I use my own message id's, but it should not be a problem to change them to whatever. The idea to choose between standard frsky / lua script compatible sounds great. I can do the "lua script compatible" part if you want !

CodeChief commented 9 years ago

Hi I'm looking for the best solution to get FrSky telemetry between a Pixhawk clone (HKPilot32) and an FrSky X8R receiver. It's down to three possible solutions of which yours looks the simplest.

1) Officially documented solution on the current APM Copter web site: http://copter.ardupilot.com/wiki/common-frsky-telemetry/ and I already have the SPC cable just finding it hard to find a FUC-1 TTL to RS232 converter. But it says it can only send "some" of the data. Is that true because then I won't waste my time (I want a full solution)? Or is that just a current software limit, is this effectively a more complex version of your adapter (but at least commercially available)?

2) The Teensy solution which appears to be the most high fidelity because you can also add more later, like battery balance lead connection for individual cell measurement, for example in the "wolkstein" variant. https://github.com/wolkstein/MavLink_FrSkySPort

3) Your solution is the simplest circuit and most integrated into the existing processor on board like option 1, which I like. I'm not so experienced with electronics yet, but think I could make your board. Before I start, I wonder is it as simple for me as using the existing SPC cable I have and wiring the TX and RX into the Pixhawk serial port? The SPC basically has a single diode after TX before joining with RX out to the S-Port. Or is additional inversion/resistance necessary?

20150131_155410 20150131_155457 20150131_155444

I assume your solution is also able to provide support for all possible data exchange (maybe it's not coded yet but is this physically possible). You see I just want to get all the hardware sorted out properly then start work on software with all you other guys to improve things. I don't want to start with some hardware which is limited then end-up switching to the Teensy later.

Oh and by the way the cell voltage thing is not necessary because if we're going down the architecturally correct route to get Pixhawk/APM at the centre of everything then we should be finding other ways to get new information, e.g. new Pixhawk specific sensors or support for FrSky sensors on the same S-Port (bus) as this adapter.

If you can answer any of these questions that'd be much appreciated!

p.s. oh yes and please add shots of the other side of your boards, for a newbie to electronics it helps :-)

badzz commented 9 years ago

I'd like to redesign the way metrics are being handled to have an array of metrics to be sent. This way you could switch between different models. Luis code is quite popular afaik : https://github.com/lvale/MavLink_FrSkySPort On 31 Jan 2015 15:43, "lakeroe" notifications@github.com wrote:

@Matthias https://github.com/Matthias What do you mean with "Luis code" ? Currently I use my own message id's, but it should not be a problem to change them to whatever. The idea to choose between standard frsky / lua script compatible sounds great. I can do the "lua script compatible" part if you want !

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72320307 .

robustini commented 9 years ago

@lakeroe News: with another inverter all work fine, i'm sorry, need to check the other one (identical)... Tried with the "Plane" version (latest master) and work only the LiPo voltage.

lakeroe commented 9 years ago

@Matthias I know Luis' scripts and also used them as a starting point for my own ones, I just didn't know his name.

@CodeChief The documentation on the APM Copter web site for X-Receivers is not valid yet (X-Receivers are supported beginning with AC3.3). Whatever solution you choose you either need FUL-1 TTL to RS232 converter + SPC cable or one of the different inverters mentioned above. In your post you wrote FUC-1 but you definitly need a FUL-1 converter. http://www.banggood.com/FrSky-Receiver-Upgrade-Lite-FUL1-p-930265.html I don't think you can buy a ready solution somewhere (yet).

For the firmware you have two options: 1) Use "my" 3.2.0 firmware (download link some posts above) + LUA scripts (also for download above) 2) Wait for 3.3 firmware ...

@Marco Can you again try my compiled firmware ?

robustini commented 9 years ago

Where is your compiled firmware for the Plane? I repeat, with your compiled version for Copter now all work fine.

lakeroe commented 9 years ago

No I mean the copter firmware I posted this morning ...

robustini commented 9 years ago

Yes, all work fine now with your compiled version.

lakeroe commented 9 years ago

Great to hear that ...

badzz commented 9 years ago

And with master ?

On Sat, 31 Jan 2015 17:11 robustini notifications@github.com wrote:

Yes, all work fine now with your compiled version.

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72323755 .

badzz commented 9 years ago

@robustini: with master, you should have gps, t1 (mode), t2 sats, speed, course, altitude,.. On 31 Jan 2015 16:42, "robustini" notifications@github.com wrote:

@lakeroe https://github.com/lakeroe News: with another inverter all work fine, i'm sorry... Tried with the "Plane" version (latest master) and i've only the LiPo voltage.

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72322611 .

robustini commented 9 years ago

Oh nice, so with the master the LUA script doesn't work for this reason?

lakeroe commented 9 years ago

Yes, the code for working with the LUA scripts is NOT in the master branch (yet) ...

BjoernKellermann commented 9 years ago

Does it make sense to invert the signal in software in order to use standard logic level shifters?

To physically connect Pixhawk serial 2 and S.Port on FrSky X-series receivers, we need a logic level shifter from 5 to 3.3 Volt and we have to invert the signal from high to low and from low to hight.

Logic level shifters are easy to buy, e.g. From sparcfun fir apr. 2-3 USD. I haven't found an inverter.

lakeroe commented 9 years ago

Inverting the signal in software is not possible, the processor has no support for that :-( If you can do some tinkering this inverter is possible the simplest one to try:

5d5876d2-39c3-11e4-8a23-13f01bba1f5b https://github.com/TauLabs/TauLabs/wiki/User-Guide:-FrSKY-S.PORT-telemetry

The FETs I use are: BSS138 (https://www.fairchildsemi.com/datasheets/BS/BSS138.pdf) and FDN338P (https://www.fairchildsemi.com/datasheets/FD/FDN338P.pdf)

The inverter further above using transistors (and pullups to 5v) also works fine.

proficnc commented 9 years ago

Is it possible to use the s.bus out for this? It has an inverter on it on Pixhawk. You would need to pass through the i/o chip, but it would get rid of the need for the inverter

badzz commented 9 years ago

Sbus output can only output, no input. On 31 Jan 2015 22:38, "proficnc" notifications@github.com wrote:

Is it possible to use the s.bus out for this? It has an inverter on it on Pixhawk. You would need to pass through the i/o chip, but it would get rid of the need for the inverter

— Reply to this email directly or view it on GitHub https://github.com/diydrones/ardupilot/issues/1587#issuecomment-72338099 .