Help dealing with a new message in MAVLink

Hello developers,
I added a new message to MAVLink with 4 parameters and regenerated it, then I replaced the generated MAVLink class with the original class in Mission Planner.
What I have to do next to be able to read first 2 parameters in the MAVLink message and show the output in 2 labels?
Another question, I added new custom control with 2 textboxes and a button, I want to transfer the values of textboxes to the 3rd and fourth parameters in my MAVLink message when i click the button, so I can read them in ardupilot. Any idea how to do that?
Thanks in advanced

I added my message to CurrentState.cs
at the start

                public float adc1 { get; set; }
                public float adc2 { get; set; }

and inside public void UpdateCurrentSettings(Action bs, bool updatenow, MAVLinkInterface mavinterface, MAVState MAV) added

                mavLinkMessage = MAV.getPacket((uint)MAVLink.MAVLINK_MSG_ID.RAW_ADC);
                if (mavLinkMessage != null)
                    var adc_data = mavLinkMessage.ToStructure<MAVLink.mavlink_raw_adc_t>();
                    adc1 = adc_data.adc1;
                    adc2 = adc_data.adc2;

Now I can see these params in status in flight data.
I didnt tried to use them, but I used different values in new form: I got text from currentstate (e.g.):

                labelAirspeed.Text = ((int)MainV2.comPort.MAV.cs.airspeed).ToString("D3");
                labelGroundspeed.Text = ((int)MainV2.comPort.MAV.cs.groundspeed).ToString("D3")

First You should change code of ardupilot, so UAV can react to your command.
I only used default commands to switch relay with MP, in my click on button function I added that

MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_RELAY, 0, relay1_state, 0, 0, 0, 0, 0);

Autopilot changes state of the first relay to relay1_state.

1 Like

Thanks alot Nikita for you help. I started now to figure out how things works.
As I understood, you did added to the ardupilotmega.xml a message “RAW_AD” with too parameters adc1 & adc2 with type float. Right?
Note: Can you attach here the xml part you used?

Right, I added message to ardupilotmega.xml

<message id="227" name="RAW_ADC">
  <description>Raw ADC output</description>
  <field type="float" name="adc1">RAW ADC1</field>
  <field type="float" name="adc2">RAW ADC2</field>

Thanks alot. I will try them and get back to you if I faced anything.

I followed this solution and updated CurrentState.cs accordingly, but the variables I created aren’t updating in the Status/Quick tabs. They’re just always set to zero. I checked the logs after a run and my custom messages were coming through with the values I expected. Am I missing a step to ensure that the CurrentState object is updated with my new message values?

Which logs?

If you followed that topic, everything should work.

I checked the telemetry log and my message was recorded in there. I’m not sure what’s going wrong. My message structure is in ardupilotmega.xml, I added the variables at the beginning of currentstate.cs, and I added the structure to receive the packet in UpdateCurrentSettings. When I execute mission planner my variables show up in the status, but they’re always 0 and never change.

I also can’t seem to debug currentstate.cs. All the breakpoints I try to set end up saying that they won’t be hit during execution.