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:
switch((int)message.msgid)
{
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);
}
case(MAVLINK_MSG_ID_SCALED_IMU):
{
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.
Replies
Hi,
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!
Thanks
What are you running ardupilot (2.5-2.6) or pixhawk? I think highres imu might not be configured for 2.5-2.6 (at least I never see that message either) so I would look at messages (26 or 27) rawIMU. You should see those. You could then try and look for an attitude message and do frame conversion to NED if that is what you are after. If you want highres you might need to change onboard code to send it
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);
tcdrain(fd);
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
I think the mavlink messages are supposed to be transmitted at 100hz in the fast_loop unless the buffer is full (MSG_RETRY_DEFERRED). See if you can use a higher baud rate. It seems like that should be fast enough for most applications. If you can write your own software you might be able to replace the mavlink with a command like Serial3.write(gyro.x,1); and put it in a faster loop.
Got it. thanks for the tip
I think the z accelerometer data is not supposed to fluctuate that much. How do those numbers compare to those you get with the mission planner?
Hi John,
In status tab in mission planner values ax, ay and az (I assume that's acceleration) are totally fine. I checked my code again and now my variable imudata.time_boot_ms gives 0 at all times therefore I suspect that I should somehow request acceleration data.
Do you have any idea how can I solve this issue? I tried using function mavlink_msg_request_data_stream_pack but without much luck so far.
I changed from reading scaled IMU data to raw data and surprisingly I started receiving acceleration data in units [cm/s/s] that matched exactly the data from mission planner. I guess I need to check if I'm using most recent mavlink headers because either I'm using wrong message ID or APM is sending scaled IMU data as RAW data.