Adding MAVLINK support

ersky9x is a port of er9x for use on the sky9x board.
Post Reply
User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Adding MAVLINK support

Post by MikeB » Tue Jan 19, 2016 12:30 am

As the title suggest, I'm looking in to adding MAVLINK telemetry support to ersky9x.
LTMNO has generously sent me a Mini APM V3.1 board along with a power board.
The plan is to get this working, sending telemetry so I can test the implementation on ersky9x.

I have this all wired up. I can connect using mission planner and adjust parameters etc. (mission planner V1.3.33, ArduCopter V3.1.5).
I can see the flight battery voltage (sent from the power board), and the HUD on mission planner shows correctly when I move the board (roll, pitch and yaw change).
I've copied the SR0 values to SR1. I can change the telemetry baudrate OK.
I have a receiver connected to the channel inputs and can calibrate these OK.

My problem is I'm not seeing any actual telemetry data on the telemetry serial port. All I see is a MAVLINK heartbeat message once per second.
Any suggestions as to what might get the telemetry data flowing please?

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
kaos
Posts: 3247
Joined: Wed Dec 28, 2011 1:15 am
Country: United States

Re: Adding MAVLINK support

Post by kaos » Tue Jan 19, 2016 3:44 am

Have you tried the latest MP 1.3.34?
My MP is 1.3.34 build 1.1.5836.10557 this time around when I reinstalled it.

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Tue Jan 19, 2016 7:35 pm

OK, I was trying to get the raw MAVLINK data sent direct to the Tx and processed there. However, it seems the APM won't send any telemetry data out unless something sends a request in.
So my current plan is two stages:

(a) Use an Arduino to handle the MAVLINK data and convert it to FrSky.
(b) Assume there is a bi-directional serial link available from a serial port on the Tx to the APM (via Xbee or 3DR of some other radio link.

So first I'll get (a) working and data being displayed on the Tx. A lot of this is already available as there is a project with all the Arduino code and a modified er9x.

Later I'll see about supporting direct MAVLINK on a serial port.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Wed Jan 20, 2016 6:44 pm

I've made some progress on this today. I've got the code in the Arduino, and it is sending FrSky telemetry packets to a 'D' receiver.
I've started on configuring a telemetry screen specifically for the MAVLINK data, and I have some of the data displayed OK.
I can see a couple of small bugs in the Arduino code, and it doesn't always seem to get the pack voltage data, so I'll need to fix those.
I will add the extra MAVLINK data items to the list of telemetry data for display and voice output.
As far as a specific MAVLINK telemetry display is concerned, is this the sort of thing requuired?:
displays.jpg
Anyone out there want to test this when it is a bit more complete?

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Brodziek
Posts: 11
Joined: Thu Mar 20, 2014 5:55 pm
Country: Poland

Re: Adding MAVLINK support

Post by Brodziek » Tue Jan 26, 2016 3:44 pm

Hi, Mike.
Tema what is true of ersky9x, but the issue is related.
Sorry for my English.
For some time I use the firmware er9x with the modification proposed by
4refr0nt described here: viewtopic.php?f=5&t=5485&p=87943
This code already know.

I'm not a programmer, but by analyzing and comparing the change in code 4refr0nt, I was able to move his modifications to newer versions er9x, now the last version of the R820 er9x.
And even it works!


I made a few changes to accommodate the flight modes used in my telemetry Multiwii.
To make everything work, you need an external converter FrSky telemetry format.
Firmware is now an additional telemetry screen that can be turned on / off in the "Telemetry" menu, the screen uses the telemetry data FrSky.

Are displayed:
Fuel - FrSky telemetry package id: H04 (graphic batteries and percent)
Battery voltage model - FrSky telemetry package id: H3A, H3B
Arming the flight controller - FrSky telemetry package id: H1D (value 128 - ARMED, any other - Disarmed
Flight mode - FrSky telemetry package id: H02 (FrSky Temperature1)
For my needs I changed to:
0 - no drv
1 - Acro
2 - Stabilize
3 - Alt hold
4 - Headfree
5 - GPS hold
6 - GPS home
7 - Failsafe
8 - Passtrough
9 - Horizon
GPS and Sat FiX number - FrSky telemetry package id: H05 (FrSky Temperature2)
Two-digit number: the first digit - Fix, the second digit - number of satellites.
for example:
number 38 is -> 3D fix and 8 sats, the number 04 -> no fix and 4 sats
Baro altitude - FrSky telemetry package id: H10, H21
GPS altitude - FrSky telemetry package id: H01, H09
HDOP - FrSky telemetry package id: H0D
Distance - FrSky telemetry package id: H0B
Current model - FrSky telemetry package id: H28
Course (Model Heading) - FrSky telemetry package id: H14
And RSSI,RCQ in numerical and graphical.

I had to change 7 files that I attach below (latest er9x r820)
All changes are marked with the comment: "Extra data for Mavlink via FrSky"
I also attach the compiled version er9x-128.hex
Maybe something from this be useful?
Mike, could you put something like that on a permanent basis in the firmware er9x
for Atmega 128/256 processors?
Of course, after checking errors and addition of all flight modes APM.
Thank you 4refr0nt for his work.
Thank you also MikeB
Attachments
screen2.jpg
screen1.jpg
er9x-128extra_screen.zip
(86.56 KiB) Downloaded 69 times
Changes to extra telemetry Screen er9x r820.zip
(108.24 KiB) Downloaded 60 times
Using Tapatalk


User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Tue Jan 26, 2016 7:56 pm

I've had a quick look at the source code. You have an extra byte in myeeprom.h in the middle of the model structure. This will make it incompatible with eepe, the byte needs to be at the end as an addition.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Brodziek
Posts: 11
Joined: Thu Mar 20, 2014 5:55 pm
Country: Poland

Re: Adding MAVLINK support

Post by Brodziek » Tue Jan 26, 2016 8:06 pm

Yeah. As I wrote, I'm not a programmer. Therefore, this involves checking by someone wiser. Is there a chance to do something like add permanently to the firmware?
Using Tapatalk

User avatar
LTMNO
Posts: 1030
Joined: Fri Nov 30, 2012 9:31 pm
Country: Canada
Location: Toronto, Canada

Re: Adding MAVLINK support

Post by LTMNO » Tue Jan 26, 2016 8:14 pm

@Brodziek, looks really good...

@Mike, tested the first go with baud at 57 in APM
Setup is :
Proto to ArduP

X8R --> Teensy on SPort --> APM Telmetry

9x with XJT Module

Data flowing by connection to Tower App on Android Tablet. Able to arm, takeoff, etc... (The APM will still do this even if its not powering the motors)

Image

I need to double check that the Pin5 is connected inside....
Last edited by LTMNO on Wed Jan 27, 2016 12:31 am, edited 1 time in total.
9x-m128 / TeZ / SP Rev 2.4 / Rotary Encoder / Haptic / MegaSound9x(Serial) / er9x
9x-m128 / Telemetry Mod / FrSky Lite Converter / MegaSound9x(Serial) / er9x
9x-m128 / 9XTreme / ersky9x(Mavlink)

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Tue Jan 26, 2016 10:49 pm

Brodziek wrote:Yeah. As I wrote, I'm not a programmer. Therefore, this involves checking by someone wiser. Is there a chance to do something like add permanently to the firmware?
I will see what I can do.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
LTMNO
Posts: 1030
Joined: Fri Nov 30, 2012 9:31 pm
Country: Canada
Location: Toronto, Canada

Re: Adding MAVLINK support

Post by LTMNO » Wed Jan 27, 2016 12:52 am

UPDATE:

After crossing the wires on the inside, I was able to get some data sent over...
Image

RPM changes with Throttle from 0 to 3000 units

Image

The N and the E are right... but no values for GPS Lon/Lat
Compass Heading seems right

Image

Disarm doesn't change...
But the Fuel gauge shows 20 on disarm and 40 on armed.

Image

Image

Hope this helps...
9x-m128 / TeZ / SP Rev 2.4 / Rotary Encoder / Haptic / MegaSound9x(Serial) / er9x
9x-m128 / Telemetry Mod / FrSky Lite Converter / MegaSound9x(Serial) / er9x
9x-m128 / 9XTreme / ersky9x(Mavlink)

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Wed Jan 27, 2016 3:18 pm

It will take a little time to sort the differencies, but the Teensy you are using maps some things, on to FrSky IDs, differently to the Arduino. I may be able to sort this though as the IDs are the SPort ones, and these are different to the hub ones, so I can tell where the data comes from.
If GPS lat and long are sent, they should be displayed I think.

In passing, I found a couple of small bugs in the Arduino code, one is a buffer is too small so the telemetry data sent isn't quite correct.
I'll try to get SPort output added to the Arduino code, and I'll see about matching the Teensy use of IDs.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
LTMNO
Posts: 1030
Joined: Fri Nov 30, 2012 9:31 pm
Country: Canada
Location: Toronto, Canada

Re: Adding MAVLINK support

Post by LTMNO » Wed Jan 27, 2016 4:57 pm

No problem. Away on business for a few days. I can use arduino too if needed.


Sent from my iPhone using Tapatalk
9x-m128 / TeZ / SP Rev 2.4 / Rotary Encoder / Haptic / MegaSound9x(Serial) / er9x
9x-m128 / Telemetry Mod / FrSky Lite Converter / MegaSound9x(Serial) / er9x
9x-m128 / 9XTreme / ersky9x(Mavlink)

User avatar
LTMNO
Posts: 1030
Joined: Fri Nov 30, 2012 9:31 pm
Country: Canada
Location: Toronto, Canada

Re: Adding MAVLINK support

Post by LTMNO » Fri Jan 29, 2016 3:11 pm

Hi Mike, I was thinking last night... and I am sure we started to discuss this but just to reiterate.. I think the best solution would be both of these use cases... and I will just throw it out there as ideas...

1) Some people don't use FrSky. Some use oLRS and would like to have the ability to just have a passthru feature via the er9x or erSky9x to just accept MAVLINK from the Radio on the telemetry Pin and have the Firmware handle it.

2) Others will use FrSky and would like to have the Firmware handle the FrSky portion of Telemetry.

I guess the issue would be that there should be two versions of the firmware or a switch based on size of firmware to be able to handle each protocol. One being MAVLINK converted to FrSky(this is done by teensy or arduino) or the Firmware just handling Mavlink for Telemetry.

I personally will be using both use cases and would benefit from both.

Thoughts? is this possible?
9x-m128 / TeZ / SP Rev 2.4 / Rotary Encoder / Haptic / MegaSound9x(Serial) / er9x
9x-m128 / Telemetry Mod / FrSky Lite Converter / MegaSound9x(Serial) / er9x
9x-m128 / 9XTreme / ersky9x(Mavlink)

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Fri Jan 29, 2016 4:55 pm

Generally planned. I've got a better screen display up and running, just need to map data from the teensy to match the Arduino.
Once that is all working, I'll look at native MavLink data.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
LTMNO
Posts: 1030
Joined: Fri Nov 30, 2012 9:31 pm
Country: Canada
Location: Toronto, Canada

Re: Adding MAVLINK support

Post by LTMNO » Fri Jan 29, 2016 6:36 pm

Awesome! Thanks, I am having memory lapses... I know we discussed this. ;-)
9x-m128 / TeZ / SP Rev 2.4 / Rotary Encoder / Haptic / MegaSound9x(Serial) / er9x
9x-m128 / Telemetry Mod / FrSky Lite Converter / MegaSound9x(Serial) / er9x
9x-m128 / 9XTreme / ersky9x(Mavlink)

tomismrkolj1
Posts: 51
Joined: Sun Jan 24, 2016 10:32 am
Country: -

Re: Adding MAVLINK support

Post by tomismrkolj1 » Sun Jan 31, 2016 10:15 am

Hi,
Mike, i have already posted a comment and a question in other topic in ersky9xr forum, but this thread seems more appropriate.
here are the links of "working" arduino mini pro and nano interfaces to s.port of frsky, however they didn't work for me out of the box. Much cheaper solutions than a teensy board... Appropriate libraries, cpp and hex files are there.

https://code.google.com/p/er9x-frsky-mavlink/
https://github.com/rotcehdnih/Mavlink2F ... ee/mavTone
https://github.com/ptsneves/FrSkyTelemetry

I am not a programmer anymore (did that 25 years ago, but then started to play FPS games...), but as far as I have read on the forums, one of the main problems of sending native mavlink through frsky x8r telemetry channel is its limited throughput, and this is the reason why mavlink to frsky conversion is done before data is sent to s.port.

I would very like to do some testing. I have 9xr pro, xjt, x8r and apm 2.6.
I have (borrowed) arduino nano and mini pro 32k is on its way from China (bought 16k version instead of 32k).

tnx.

tomi

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Sun Jan 31, 2016 12:44 pm

Thanks, I'll follow all that up.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Thu Feb 04, 2016 2:12 pm

Update:
I'm working through the Arduino code, so I can add SPort as well as hub. We have the driver code for that in the openXsensor, so I'm going to use that. It includes both drivers. I'll simply add a link option so there is a single set of code and you choose which driver you need.
As I look at the code, I'm finding a number of problems due to not handling interrupts in a timely fashion. For example, the code that sends out the hub data is called from an interrupt. This means that while the data is being sent (around 70mS every 200mS), no other interrupts take place, so the millis() function doesn't run, the timer to schedule the hub data sending doesn't run and the serial input from the APM is blocked.
I'm re-coding this so all keeps working all the time. This is not too difficult as most of the needed code exists either in openXsensor or er9x, I just need to pull it all together.
Don't be surprised if the resulting code ends up a lot smaller! The original used a timer driver that required the floating point library to be included, I've removed that!

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
LTMNO
Posts: 1030
Joined: Fri Nov 30, 2012 9:31 pm
Country: Canada
Location: Toronto, Canada

Re: Adding MAVLINK support

Post by LTMNO » Thu Feb 04, 2016 2:58 pm

Thanks Mike, I guess the size of the code doesn't really matter much as long as it all works ;-)
Appreciate you working on this...
9x-m128 / TeZ / SP Rev 2.4 / Rotary Encoder / Haptic / MegaSound9x(Serial) / er9x
9x-m128 / Telemetry Mod / FrSky Lite Converter / MegaSound9x(Serial) / er9x
9x-m128 / 9XTreme / ersky9x(Mavlink)

tomismrkolj1
Posts: 51
Joined: Sun Jan 24, 2016 10:32 am
Country: -

Re: Adding MAVLINK support

Post by tomismrkolj1 » Thu Feb 04, 2016 3:38 pm

These are great news Mike! Keep up the good work.

Please tell me which arduino do you use for converter, as I have tried nano again with all existing software, but did not get anything to work.
I have x8r so I need s.port connection.

tnx

tomi

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Thu Feb 04, 2016 4:51 pm

I'm currently using a MINI, but the PRO MINI should work just as well. I don't have a nano so can't test that at present.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

tomismrkolj1
Posts: 51
Joined: Sun Jan 24, 2016 10:32 am
Country: -

Re: Adding MAVLINK support

Post by tomismrkolj1 » Thu Feb 04, 2016 5:03 pm

Nano is just mini pro with usb circuitry onboard. I guess...

Do you connect on s.port or hub?

tomi

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Thu Feb 04, 2016 5:29 pm

I'm testing using hub at present, but I will add SPort support.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Sat Feb 06, 2016 11:34 pm

I may be able to start posting some things to test very soon. I have the Arduino working with both hub and SPort protocols, you just leave IO2 open for hub and connect it to GND for SPort. It may even be possible to autodetect!
I have only a few data items being sent over SPort at present, and I think there will be some scaling problems to solve.
The test APM I'm using doesn't have GPS so I expect some problems there.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

tomismrkolj1
Posts: 51
Joined: Sun Jan 24, 2016 10:32 am
Country: -

Re: Adding MAVLINK support

Post by tomismrkolj1 » Sun Feb 07, 2016 6:15 am

Cool,

do you think the code would fit to 16k (which I have at home now) or it is necessary to have 32k mini pro (which is coming from China...)

tomi

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Sun Feb 07, 2016 9:56 am

It depends on your bootloader size. The code is currently 14068 bytes long, but will get longer as I add more items to the SPort transmission. This assumes I don't find some code space saving!

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
RCHH
Posts: 398
Joined: Sun Jun 24, 2012 2:48 pm
Country: -
Location: Plymouth

Re: Adding MAVLINK support

Post by RCHH » Sun Feb 07, 2016 10:37 pm

Oh lordy! Now I will have to go get the relevant bits for my Pixhawk ... Mike you are costing me a fortune in new hardware! lol!!!

Brilliant stuff once again, and a genius addition to ErSky9X!!!

Will be only too happy to test out as and when required.

PS.

Will test only if we have British spelling .... StabiliSe and not StabiliZe! heh heh!!!! :twisted: :mrgreen: lol!!!
Last edited by RCHH on Sun Feb 07, 2016 10:41 pm, edited 1 time in total.
The simpleton asked "Hows about ErSky9X for Horus???". And the Genius from Dorset replied "Why not indeed? I shall get right onto it!" And then there was light on Horus! And it was good!

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Sun Feb 07, 2016 10:40 pm

I have just posted test versions of ersky9x and the Arduino code for a Mavlink to FrSky converter (usual place here: viewtopic.php?f=7&t=4676).

I switched from the Arduino 1.0.5 IDE to the 1.5.8 IDE. The code has shrunk to 11662 bytes! Your code size will likely depend on the Arduino IDE you use. The original code was, I felt, overly complex, and used several libraries. I have chosen to get everything into a single directory, so it should be straightforward to compile. I also noticed that the original was sending more data using the hub protocol than the FrSky downlink could handle, causing corruption of telemetry values. I reduced the amount of data sent by sending a 'hub' frame every 250mS instead of 200mS, and when the extra frame sent every one second is sent, then the other frame sent every 250mS is not sent. The display then seems quite stable.
I tested using an Arduino Mini. A Pro mini should also work and a nano might, but I can't test that.
To connect the Arduino, connect the serial Tx and Rx to the APM. It expects 57600 baud. Make sure Tx goes to Rx and Rx to Tx, the usual swapping over.
The serial to the receiver is IO5.
If IO2 is left unconnected, then you will get hub protocol, if IO2 is connected to ground then you have SPort protocol. Currently, fewer telemetry values are sent over SPort, more will be added later.

Ersky9x includes code to display specific Mavlink data. In the telemetry menu, set the Usr Proto to Ardup, this is the Mavlink over FrSky mode. A new telemetry screen is then available to display the Mavlink data, although most values are also mapped to standard FrSky items.

It is likely that some values may be incorrectly scaled, I'll need feedback one obvious problems like that. The (barometric) altitude seems to wander a bit.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14035
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Adding MAVLINK support

Post by MikeB » Sun Feb 07, 2016 10:42 pm

RCHH wrote:Oh lordy! Now I will have to go get the relevant bits for my Pixhawk
Out of curiosity, what bits will you need to get? If the Pixhawk is sending Mavlink telemetry, and you are using a FrSky receiver, then all you need is an Arduino Pro Mini.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
RCHH
Posts: 398
Joined: Sun Jun 24, 2012 2:48 pm
Country: -
Location: Plymouth

Re: Adding MAVLINK support

Post by RCHH » Sun Feb 07, 2016 11:05 pm

MikeB wrote:
RCHH wrote:Oh lordy! Now I will have to go get the relevant bits for my Pixhawk
Out of curiosity, what bits will you need to get? If the Pixhawk is sending Mavlink telemetry, and you are using a FrSky receiver, then all you need is an Arduino Pro Mini.

Mike.
Ha! I just read through all of the posts here (quick glance earlier today) and now realised I alreadyhave all the bits I need. I just have to actually FIND the bag of Arduino Pro Minis I bought the year before last! lol!!!

Now I have to find another excuse to buy some other stuff ... might get a PixHack and try that too! lol!!!

I can test with SPort and Hub as well, and also with an APM 2.8 board, and probably on my old MultiWii Pro machine as well. I have some test code for that particular one kicking about somewhere, but it is a bit of a fossil compared to the Pixhawk.
The simpleton asked "Hows about ErSky9X for Horus???". And the Genius from Dorset replied "Why not indeed? I shall get right onto it!" And then there was light on Horus! And it was good!

Post Reply

Return to “ersky9x”

Who is online

Users browsing this forum: Google [Bot] and 3 guests