Hey there :)
I am not sure whether this is the right place for my question, but I feel like it could be a software problem. Recently I noticed, that the APM sends MAVlink messages at about 13Hz maximum. Even if I request a rate of 50Hz! (Tested in QGC and with a ROS-Mavlink bridge - both say 13Hz)
Why is that so? Am I doing it wrong? Is the Software/Hardware of the APM not capable of sending MAVlink messages faster? I realy want to have the messages at 50Hz and I am considering to switch to the Pixhawk board if there is no way to make this work with the ArduPilot :(
Hope you can halp me or point me to the right place to get help :)
Georg
Replies
All right - we found the problem. In our case we want to do external control and state estimation so we needed some specific MAVlink messages containing IMU measurements. So in case you have a similar problem here is what we did to get the attitude of the copter with 100Hz via USB. Since I am not sure whether this is the right place for such discussions I apologize in advance.
ATTENTION: The code is not tested with the flying system! So be careful - as always :)
In the File
GCS_Mavlink.ino
we recreated the Functiongcs_check()
, since it handles the sending of the messages and the heartbeat with this more lightweight version:static bool gcs_check_custom()
{
static uint32_t last_1hz, last_50hz;
bool sent_message = false;
uint32_t tnow = millis();
// Heartbeat is sent every 1000ms
if (tnow - last_1hz > 1000){
last_1hz = tnow;
gcs_send_message(MSG_HEARTBEAT);
sent_message = true;
}
// Attitude is sent every time the loop is run and the
// Heartbeat is not sent.
if (true && !sent_message) {
gcs_send_message(MSG_ATTITUDE);
sent_message = true;
}
gcs_send_message(MSG_RETRY_DEFERRED);
return sent_message;
}
In the main file
ArduCopter.ino
add the following Lines underSystem Timers
// ------------------------------------
// Timer for our own 100Hz Mavlink Loop
static uint32_t mavlink_loop_timer;
// ------------------------------------
and the following Lines in the function
loop()
below the lineuint16_t num_samples;
// ---------------------------------
if (timer - mavlink_loop_timer > 10e3)
{
gcs_check_custom();
mavlink_loop_timer = timer;
}
// ---------------------------------
This new function only sends the Attitude message! Now comment the
gcs_check();
line out in order to prevent interference. We did this because we are not interested in any other messages. Remember, that if you use this code the Attitude message will be sent without request (similar to the heartbeat)! If you have suggestions or run into problems please let me know.Hope anyone can use this! All the best,
Georg