How to initialize MavLink messages

What command(s) do I need to send to the rov to initialize and to start message sending (data packets) from the Pixhawk.

Currently I have to start up either mission planner or qgroundcontrol to initialize and start data transmission.

I can receive and decode the MavLink data packages OK but haven’t worked out the initialization process when first connecting to the rov.

I have waded through the source code but can’t find where the initialization commands are sent.
or is their a script I can use to make this automatic whenever the sub is powered up

Regards,

Alan

I believe you just need to send a heartbeat, make sure the sysid (use 255) and compid are unique. If you want some messages to be streamed, check the ‘stream rate’ parameters: Redirecting...

Jacob,

I can get the hearbeat to ping back from the ROV

This worked to create the buffer that I then sent:

mavlink_msg_heartbeat_pack(255, 125, &msg, 12, 3, 0,0,0);
len = mavlink_msg_to_send_buffer(buf, &msg);

However I don’t get any messages streaming back.

I tried this.

	mavlink_msg_request_data_stream_pack(255, 125, &msg, 1, 1, MAVLINK_MSG_ID_GLOBAL_POSITION_INT, 0x05, 1);
	len = mavlink_msg_to_send_buffer(buf, &msg);

I also used “MAV_DATA_STREAM_ALL” but that didn’t work either.

Any suggestions ? It as if I am missing an extra command somewhere

Does that mean it can’t be configured to automatically start streaming on boot ?

In a project I plan to use ArduSub as a ‘Sensor only’ pod that will stream over rs422 (simplex).

Answering to myself.

Just set up a simple flightcontroller (Omnibus Nano V6) with latest ardusub firmware available on website, configured it through QGroundControl so that the SR1_params are identical to the respective SR0_params.

Now with only the controller’s TX1 pin connected to a serial to usb interface, i can use mavproxy --console to display heading, pitch and roll right after putting power to the controller. No need to send anything to the controller or initializing something to receive the data.

Just i can’t use qgroundcontrol to display the data as it won’t connect over a simplex link, but from a MavLink point of view everything seems to be ok so far.

1 Like

You will need to set the SR parameters with PARAM_SET message, or qgc interface as @Sputnik has done.

Thanks,

I don’t quite understand but i will struggle on

I don’t really know how this works as I can’t find any example code.

I tried this. I didn’t work buy am I on the right track ?

mavlink_message_t msg;
mavlink_param_set_t packet_in = {1.0,1,1,"SR0_POSITION",MAV_PARAM_TYPE_REAL32};
mavlink_param_set_t packet1;
memset(&packet1, 0, sizeof(packet1));
packet1.param_value = packet_in.param_value;
packet1.target_system = packet_in.target_system;
packet1.target_component = packet_in.target_component;
packet1.param_type = packet_in.param_type;
mav_array_memcpy(packet1.param_id, packet_in.param_id, sizeof(char) * 16);
mavlink_msg_param_set_pack(0xFF, 0xBE, &msg, packet1.target_system, packet1.target_component, packet1.param_id, packet1.param_value, packet1.param_type);
len = mavlink_msg_to_send_buffer(buf, &msg);

Hi Alan,

Take a look in our pymavlink documentation. For C++ projects, please share a minimum example in pastebin or github, remember to provide build instructions for it or any build system.

Thanks Patrick.

I cant even get the python scripts in the pymavlink documentation to stream data !

Its no big deal I just need to start QGC or mission planner to get the data streams started.

I will revisit this later to try and work m it out.

This is all that is required in pyMavlink to get it streaming.

# Import mavutil
from pymavlink import mavutil
import time
# Create the connection
master = mavutil.mavlink_connection('udp:0.0.0.0:14550')
# Wait a heartbeat before sending commands
master.wait_heartbeat()
master.mav.request_data_stream_send(master.target_system, master.target_component, mavutil.mavlink.MAV_DATA_STREAM_ALL, 0x5, 1)

I must be sending the data packages in correctly to the companion computer
I am doing this.

	sockaddr_in RecvAddr;
			RecvAddr.sin_family = AF_INET;
			RecvAddr.sin_port = htons(atoi(14550));
			RecvAddr.sin_addr.s_addr = inet_addr("192.168.2.2");//not working

			//---------------------------------------------
			// Send a datagram to the receiver
			iSendResult = sendto(ListenSocket, buf, Length, 0, (SOCKADDR *)& RecvAddr, sizeof(RecvAddr));

I am not sure how to code
mavutil.mavlink_connection('udp:0.0.0.0:14550')

in C++