Servers by jDrones

Tank empty alert

I have digital fuel sensor which is been places to the bottom of the tank, It will change the logic level 0 or 1 depends on the presence of water.

Can I use any of the AUX pin to read this input and display a mavlink msg or buzzer sound?

I using AUX pin 6, so

BTN_Enable=1;
BTN_PIN1=55;
BTN_REPORT_SEND=1;

The problem is I can’t able to observe any changes in Mission Planner(I checked at Messages and Status Tabs to observe changes), where do I see the parameter BTN_PIN1 changes ?

There should be BUTTON_CHANGE Mavlink messages going to the gcs, but I doubt they’re integrated into the UI so not sure how they’re presented.

do you know anything about integrating it into UI (custom mission planner build) ?

You can write a simple plugin for checking BUTTON_CHANGE mavlink message and display a warning. Plugins are independent from Mission Planner builds, so you can keep using standard MP builds.

yes that sounds really good, if only I had software development knowledge. I am surprised that mission planner doesn’t have a way to display that message. I found it only in the mavlink inspector window but that s about it

Not in yet but button binding are coming to lua scripting on board. The example does basically what you want.

edit: forgot the link https://github.com/ArduPilot/ardupilot/pull/12887

OK, here is a quick plugin which intercepts BUTTON_CHANGE messages and put a notification to the “Messages” tab in Mission Planner.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MissionPlanner.Utilities;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using MissionPlanner;

namespace Shortcuts
{
    public class Plugin : MissionPlanner.Plugin.Plugin
    {
        public override string Name
        {
            get { return "Button change"; }
        }
        public override string Version
        {
            get { return "0.1"; }
        }
        public override string Author
        {
            get { return "EOSBandi"; }
        }
        //[DebuggerHidden]
        public override bool Init()
        {
            return true;
        }
        public override bool Loaded()
        {
            Host.comPort.OnPacketReceived += MavOnOnPacketReceivedHandler;
            return true;
        }
        public override bool Loop()
        {
            return true;
        }
        public override bool Exit()
        {
            return true;
        }

        private void MavOnOnPacketReceivedHandler(object o, MAVLink.MAVLinkMessage linkMessage)
        {

            if ((MAVLink.MAVLINK_MSG_ID)linkMessage.msgid == MAVLink.MAVLINK_MSG_ID.BUTTON_CHANGE)
            {
                //Button change message received
                //Check and display message
                Host.cs.messages.Add((DateTime.Now, "BUTTON CHANGE message received"));
            }
        }
    }
}
2 Likes

Thanks for that, interesting! I will try it next week and I will get back to you!

@Eosbandi Hello, so I followed the mission planner setup for visual studio. Now how do I compile a plugin with the code that you have given me? I would really appreciate some help

Easiest way it to use the MissionPlanner.Stats plugin’s source. It is easier than setup a project for a new plugin. Just replace the ExtViews/MissionPlanner.Stats/StatsPlugin.cs file contents with the code I sent earlier.
Please not that building MissionPlanner will not update the Plugins, you have to build the plugin separately (right click and build in the solution explorer the MissionPlanner.Stats project.

Thanks a lot that works! :grin:
Except for this line of code:

Host.cs.messages.Add((DateTime.Now, “BUTTON CHANGE message received”));

This line which I think sends messages to the MP messages tab seems to create an error when I connect to the pixhawk.
This is the error:

ERROR MissionPlanner.MAVLinkInterface - System.MissingMethodException: Method not found: 'System.Collections.Generic.List 1<System.ValueTuple 2<System.DateTime,System.String>>*

MissionPlanner.CurrentState.get_messages()’.
at Shortcuts.Plugin.MavOnOnPacketReceivedHandler(Object o, MAVLinkMessage linkMessage)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at MissionPlanner.MAVLinkInterface.readPacket()

Which version of Visual Studio are you using ?

I am using the 2019 version to build the plugin (I know the 2017v is recommnended in the documentation), but I just take the plugin to installed mission planner and only that line of code doesn’t work, which is good for me to have in order to display messages in the MP messages tab, right now I use the console for debugging and stuff, the rest of the plugin works, but I have to remove that line.

Check for System.ValueTuple NuGet package, and make sure it is added to the plugin project.

I have installed it as a package in the dependancies and still the same problem. I have the dll file you can try it yourself. If you connect to a pixhawk and check the console you see the behaviour. The mavlink MESSAGES don’t even get used for display on the Flight Data tab on MP.

Send me a dll, I’ll give it a try

Or even better, you can zip and send the plugin project…

1 Like

MissionPlanner.ButtonChange.zip (153.2 KB)

Here it is. Sorry I added a lot of comments to the code.
If you have some feedback on doing things better let me know.

I realised I had a mistake. This is the fix. But doesn’t fix the original problem it is just my algorithm.
if (mavLinkMessage.payloadlength < 9)

Hi !
It works on my machines. The only possible cause that I found is if your machine has .NET 4.7.1 installed, this cause some issues with ValueTuples. with 4.6.x targeted apps (https://github.com/dotnet/standard/issues/567)

So it is most likely related to the actual installation of your dev computer.

So just to double check here.
This line of code works for you and adds the message in the messages tab on MP?
Host.cs.messages.Add((DateTime.Now, “BUTTON CHANGE message received”));

Do you recomment I install the .NET 4.6.x ?

Servers by jDrones