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.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

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:

    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

  • 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:

    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

  • "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
    ?
    Regards,
    Bjørn

  • 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 Mateusz Sadowski,

    I need to make a similar implementation but I need to read the GPS data too.

    Could you share more information about your implementation? 

    Thanks

    • 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.

  • Hi Mateusz,

    I am trying myself to receive attitude using mavlink. We don't need anything else, just the roll pitch yaw. I noticed that you provided a little snippit of your code in the question posted here, and that is the heart of what we need - but we can't get to that point, where messages are received. Would you be willing to help us get similar message protocols setup?

    Send me a message if you have a minute.

    Thanks,
    Sean

    • 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

      mavlink/c_uart_interface_example
      Simple MAVLink to UART interface example for *nix systems - mavlink/c_uart_interface_example
This reply was deleted.

Activity

DIY Robocars via Twitter
RT @a1k0n: Did I get rid of hand-tuned parameters? Yes. Am I still hand-tuning more parameters? Also yes. I have a few knobs to address the…
Monday
DIY Robocars via Twitter
RT @a1k0n: I'm not going to spoil it, but (after charging the battery) this works way better than it has any right to. The car is now faste…
Monday
DIY Robocars via Twitter
RT @a1k0n: Decided to just see what happens if I run the sim-trained neural net on the car, with some safety rails around max throttle slew…
Monday
DIY Robocars via Twitter
Sep 24
DIY Robocars via Twitter
RT @SmallpixelCar: @a1k0n @diyrobocars I learned from this. This is my speed profile. Looks like I am too conservative on the right side of…
Sep 24
DIY Robocars via Twitter
RT @a1k0n: @SmallpixelCar @diyrobocars Dot color is speed; brighter is faster. Yeah, it has less room to explore in the tighter part, and t…
Sep 24
DIY Robocars via Twitter
RT @a1k0n: I'm gonna try to do proper offline reinforcement learning for @diyrobocars and throw away all my manual parameter tuning for the…
Sep 23
DIY Robocars via Twitter
RT @circuitlaunch: DIY Robocars & Brazilian BBQ - Sat 10/1. Our track combines hairpin curves with an intersection for max danger. Take tha…
Sep 22
DIY Robocars via Twitter
RT @SmallpixelCar: Had an great test today on @RAMS_RC_Club track. However the car starts to drift at 40mph. Some experts recommended to ch…
Sep 11
DIY Robocars via Twitter
RT @gclue_akira: 世界最速 チームtamiyaのaiカー https://t.co/1Qq2zOeftG
Sep 10
DIY Robocars via Twitter
RT @DanielChiaJH: Always a good time working on my @diyrobocars car at @circuitlaunch. Still got some work to do if I’m to beat @a1k0n howe…
Sep 10
DIY Robocars via Twitter
RT @SmallpixelCar: My new speed profile for @RAMS_RC_Club track https://t.co/RtLb7TcgIJ
Sep 10
DIY Robocars via Twitter
RT @SmallpixelCar: Practiced at @RAMS_RC_Club today with my new @ARRMARC car https://t.co/AEu2hCx89T
Aug 28
DIY Robocars via Twitter
Aug 24
DIY Robocars via Twitter
RT @gclue_akira: 柏の葉で走行させてるjetracerの中身 #instantNeRF #jetracer https://t.co/giVvuE4hP7
Jul 4
DIY Robocars via Twitter
Cool web-based self-driving simulator. Click save when the AI does the right thing https://github.com/pncsoares/self-driving-car
Jul 4
More…