c++roboticsdronekitmavlink

Changing Mavlink Message Rate ArduPilotMega


I am working on a project that uses Mavlink protocol (in c++) to communicate with the ArduPilotMega (2.6).
I am able to read messages such as ATTITUDE for example. The current message rate (for all messages) is 2Hz and I would like to increase this rate.
I found out that I should probably set MESSAGE_INTERVAL using MAV_CMD_SET_MESSAGE_INTERVAL in order to change it.

So my question is:
How do I send this command message using mavlink in c++?

I tried doing it using the code below but it did not work. I guess I have to use the command 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?


Solution

  • From Robotis Stack Exchange answer,

    In order to change the message rate, the simplest way is to change the SR_* parameters value using Mission Planner. The maximum rate is 10Hz.
    For example, in order to change the ATTITUDE message rate to be 10Hz I just had to change the SR_EXTRA1 parameter to be 10.

    For more information about which parameter changes each message see GCS_Mavlink.cpp file in ArduCopter firmware.