1
$\begingroup$

I am using Mavlink protocol (in c++) to communicate with the ArduPilotMega, I am able to read messages such as ATTITUDE for example.
I am currently getting only 2Hz (message rate) and I would like to increase it. I found out that I should use MESSAGE_INTERVAL in order to change it, and that I probably need to use the command MAV_CMD_SET_MESSAGE_INTERVAL to set it.

So my question is, how do I send that command using mavlink in c++?

I tried doing this with the code below but it did not work, I guess that I should use the command that I mentioned above but I don't know how.

mavlink_message_t command;
mavlink_message_interval_t interval;

interval.interval_us = 100000;
interval.message_id = 30;

mavlink_msg_message_interval_encode(255, 200, &command, &interval);
p_sensorsPort->write_message(command);

Update: I also tried this code below, maybe I am not giving it the right system id or component id.

mavlink_message_t command;
mavlink_command_long_t interval;

interval.param1 = MAVLINK_MSG_ID_ATTITUDE;
interval.param2 = 100000;
interval.command = MAV_CMD_SET_MESSAGE_INTERVAL;
interval.target_system = 0;
interval.target_component = 0;

mavlink_msg_command_long_encode(255, 0, &command, &interval);
p_sensorsPort->write_message(command);

Maybe I am missing something about the difference between target_system, target_component and sysid, compid. I tried few values for each but nothing worked. Is there any ack that will be able to tell me if it even got the command?

$\endgroup$
1
$\begingroup$

You don't need to send any mavlink message. You can simply change the parameter SR1_EXTRA_1 to desired Attitude data rate and your data rate will be changed. Similarly you can change other parameter to change data rate of other messages. More information of messages can be found at https://github.com/ArduPilot/ardupilot/blob/master/ArduCopter/GCS_Mavlink.cpp#L821

$\endgroup$
  • $\begingroup$ Thank you! I changed that parameter using Mission Planner and it did the job. Just for interest - what is the difference between the SR0_ parameters and SR1_ parameters? $\endgroup$ – A. Sarid May 25 '16 at 13:27
  • 1
    $\begingroup$ SR0 deals with connection via USB port while SR1 deals with connection via serial port (generally used for telemetry). $\endgroup$ – nikhil May 25 '16 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.