#include#include void poseCallback(const geometry_msgs::PoseStamped::ConstPtr& poseMsg) { // Extract the orientation quaternion from the pose message auto orientation = poseMsg->pose.orientation; // Print the orientation quaternion ROS_INFO("Orientation: [%f, %f, %f, %f]", orientation.x, orientation.y, orientation.z, orientation.w); } int main(int argc, char** argv) { // Initialize the ROS node ros::init(argc, argv, "orientation_example"); // Create a ROS node handle ros::NodeHandle nh; // Subscribe to the pose topic auto poseSub = nh.subscribe("/pose", 1, poseCallback); // Spin the node ros::spin(); return 0; }
#includeThis example shows how to create a quaternion representing a rotation and extract the orientation from it. The quaternion is created using the `boost::math::quaternion` library and the orientation is obtained by accessing the imaginary part of the quaternion. Package library: Boost C++ Libraries#include int main() { // Define a quaternion representing a 90-degree rotation around the x-axis auto q = boost::math::quaternion (std::sqrt(0.5), std::sqrt(0.5), 0, 0); // Get the orientation from the quaternion auto orientation = q.imag(); // Print the orientation std::cout << "Orientation: [" << orientation[0] << ", " << orientation[1] << ", " << orientation[2] << "]" << std::endl; return 0; }