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 Ernes,
Well, I don't know why, but I also have never received the message 105 (IMU in NED body frame). Usually what the pixhawk sends the IMU data but through the message 26 (Scaled IMU). Maybe, if you change some configuration in Mission Planner or some other ground control station, you can set up pixhawk to send IMU in NED body frame, but anyway the autopilot send IMU data through message 26.
Fernando Lima Saraiva Filho said:
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:
The accelerometer output is fused with the GPS. Turn off the GPS control parameter. That will stabilize the output for other projects.
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. :)
Hi Nuno,
It's me again. I don't know if you are interested in using ros in your project but if you are I just found out about neat ros interface called roscopter by Yogesh Girdhar. In the pacakage reading data from APM works 'out of the box'. It also seems to be able to get GPS data.
Project website is: https://code.google.com/p/roscopter/wiki/roscopter
Hi Nuno,
Unfortunately I don't have access to my code anymore. If I remember correctly I was using this project: https://github.com/mavlink/c_uart_interface_example/blob/master/mav... as a reference when writing my code.
It is important that you connect to APM via serial interface using correct parameters (check function at line 80) and port variables in main function. After you are connected you need to wait for messages and check their IDs to look for the data of your interest (see my original message and line 312 of the github project that I showed you).
I didn't play with GPS data. You can try to listen to https://pixhawk.ethz.ch/mavlink/#GPS_RAW_INT message and try to extract desired information.
If you have any more questions then let me know and I will try to answer them to the best of my ability.
Hello,
Check this out: https://github.com/mavlink/c_uart_interface_example
On same topic I am getting data through mavlink to my computer over USB but I am capped at ~25 Hz. Is there a way to get the sensor data at a quicker rate? Possibly using a different uart port/telemetry port? Any advice on getting the data at a much faster rate would be appreciated
.
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
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
-
1
-
2
of 2 Next