Console Output for Attitude Mavlink Message
The above output result shows that the message is seamlessly parsed as a dictionary-based string. The message contains the attitude data: roll, pitch, yaw, rollspeed, pitchspeed, and yawspeed.
Discussion
If you come from the first post, Basic Pymavlink
, you noticed that the first half of the code is the same. It connects to the Pixhawk device.
Next, the function def stringify_attitude(attitude)
is defined. Simply the function puts all the values in the attitude dictionary into a comma-separated string. As the default output is a dictionary-style string, I wished to save it as comma-separated values. The comma-separated values are often convenient to work with data analysis. For instance, numpy, pandas, and Matlab can directly read the comma-separated data file.
The last part is the simplest. It opens a file to write and write the data line by line. I put the while loop in the try-finally block to make sure flie.close()
is called when a user stops the script by "ctrl+c"
Exploring Other Data Types
Yes! Thank you for asking. Many different data types exist, such as SCALED_IMU, SYS_STATUS, etc. The best and quickest way is to search through the definition list from the official website: mavlink official doc - message definitions
Next, add the target message of your interest to the script above. Once you print, you will notice which variables are in the dictionary. Then, repeat the same!
Conclusion
Collecting and storing attitude data from drones using Pymavlink is a powerful skill. This blog has guided you through the basics, and the applications are limited only by your imagination. Dive in, experiment, and see what you can achieve with this exciting technology.
PX4 Workshop
Need to master all the PX4 topics with ROS for your robotics project? I got you covered! 🚀🤖✨ Checkout this PX4-ROS workshop: PX4-ROS Workshop