Hello all,

Recently I started working with APM and mavlink. I'm trying to get attitude and acceleration data from APM via USB. So far I was able to receive RPY data correctly but I can't seem to be able to get correct readings from accelerometer. Relevant part of my code is here:

                case (0):
                    printf("Heartbeat received\n");
                case (MAVLINK_MSG_ID_ATTITUDE):
                    mavlink_attitude_t attitude;
                    mavlink_msg_attitude_decode(&message, &attitude);
                    printf("attitude time: %d:\n", attitude.time_boot_ms);
                    printf("roll: %f:\n", attitude.roll*180/PI);
                    printf("pitch: %f:\n", attitude.pitch*180/PI);
                    printf("yaw: %f:\n\n", attitude.yaw*180/PI);
                    mavlink_scaled_imu_t imudata;
                    mavlink_msg_scaled_imu_decode(&message, &imudata);
                    printf("Scaled IMU time: %d:\n", imudata.time_boot_ms);
                    printf("Zacc: %d:\n", imudata.zacc/1000);


I tried to use both SCALED_IMU and RAW_IMU data but both seem to return similar, meaningless values. The values I get for acceleration in z direction when APM is on the table are like: 7, -13, 1, 27, -6 etc. (note that according to https://pixhawk.ethz.ch/mavlink/#SCALED_IMU the unit I should obtain is g (I'm dividing obtained value by 1000)).

What am I doing wrong? Should I somehow convert the value I'm receiving? Or maybe I should request data on APM? I would be grateful for any advice.

Views: 6158

Reply to This

Replies to This Discussion

Thanks Steve! Reading values from message #27 successfully now. FYI, I am using an AMP 2.6.

Now I am trying to send message #70, rc channels override. I want to be able to confirm that I am overriding the channels so I am reading message #35, rc channels raw. I took code from send_quad_command.cpp, manipulated, and pasted into mavlink_serial.cpp to the beginning of the main while loop right before the read function.

mavlink_rc_channels_override_t sp;

sp.target_system = sysid;

sp.target_component = compid;

sp.chan1_raw = 1000;

sp.chan2_raw = 0;

sp.chan3_raw = 0;

sp.chan4_raw = 0;

sp.chan5_raw = 0;

sp.chan6_raw = 0;

sp.chan7_raw = 0;

sp.chan8_raw = 0;

mavlink_msg_rc_channels_override_encode(200, 0, &message, &sp);

unsigned len = mavlink_msg_to_send_buffer((uint8_t*)buf, &message);

write(fd, buf, len);


I can still see that my TX is controlling the channel values though. Is the APM not equipped to deal will message id 70? I am doing this right? Thanks again

Sean, I built a powerful forestry laser using the APM and its accelerometer. I access the data steam through an Excel com port VBA.

Why not write your own custom code ? It is fairly easy.

The data stream is Hex message #ID 1E. It comes in backwards, I.e. Little Endian Format. You then must use IEEE7 to decode the hex bytes after re-oredering. If you use Qground control you can see the byte steam.

It looks like this. I separated the picth, roll and yaw in their 32 bit segments.  You then reverse them  35 97 d9 00.        ...   .84 72 a6 bd     etc

fe 1c 7e 01 01 1e de 76 01     00 d9 97 35      bd a6 72 84    bc 8c 60 97    3f 00 81 b0 39 00 be 81 39 60 bd 09 3a ef 95

then run through an IEEE7 decoder. Sample code all over the internet.

Also, if you are not using mission planner, you will need to turn on the data stream for pitch, yaw and roll (if using arducopter). Some version start the stream on their own.

the command to start the Message ID 1E data stream is:

FE 06 6D FF BE 42 0A 00 01 01 0A 01 2D 1F   picth, roll, yaw stream   #1E

just use the CRC 2D 1F  attached. It is good.

run this through qground control command window in Hex format or a terminal program that allows octet stream representation. This will turn on your stream. If using C or VBA just send the bytes...byte by byte and frame the "FE" to start as the header.


Lastly, you need to scale the accelerometers and calibrate zero. To scale and convert to degree multiply by 52.2957795  *  1.0966. The first number is the radians to degrees conversion and the second the scale to bring to 0-180 degees.      1.0966 is the magic number.  :)

The accelerometer output is fused with the GPS. Turn off the GPS control parameter. That will stabilize the output for other projects.

"The buffer size isn't available from MissionPlanner; only the baud. To change the buffer size, the parameter must be set in the firmware."

Could you be more specific on which parameter that has to be changed in order to increase the buffer size

Hi Ernes,

I am also trying to receive Mavlink messages using C code, but there are some messages that I would like to receive and I am not receiving. For example, I do see many messages coming, but I never see the message 26 (scaled IMU), and I would like to receive it. Do you know how can I do it?

Thank you.

Enes Mentese said:


I also tried running the mavlink c_uart_interface_example code but unlike you I was not able to get any IMU readings. I can see that messages are being received but none of them have the message ID 105. I am running the code off of an ubuntu VM using the eclipse IDE. I have the example set to 115200 baud, I can't set it to any higher or else I get errors. I am wondering, how do I get the APM to send message ID 105?

Your knowledge and help will be greatly appreciated!


Reply to Discussion


© 2017   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service