castacks / PX4-fully-actuated

PX4 autopilot extended to fully-actuated multirotors
BSD 3-Clause "New" or "Revised" License
33 stars 8 forks source link

How to get the Euler Angle (Roll, Pitch, Yaw) data of the UAV in Gazebo? #11

Closed daydayupcg137 closed 3 years ago

daydayupcg137 commented 3 years ago
       Excuse me, can you help me?How do I get the Euler Angle (Roll, Pitch, Yaw) data of the UAV in Gazebo?I can currently find _**/MAVROS/local_position/pose**_ from the Mavros topic, but it contains XYZ position and Quaternion, not Euler Angle data.
keipour commented 3 years ago

Assuming that your callback function is called pixhawk_pose_callback, the code would be this:

void pixhawk_pose_callback(geometry_msgs::PoseStamped pose) {
  tf::Quaternion q(pose.pose.orientation.x,
           pose.pose.orientation.y,
           pose.pose.orientation.z,
           pose.pose.orientation.w);
  double roll, pitch, yaw;
  tf::Matrix3x3(q).getRPY(roll, pitch, yaw);
}

You would also need to define tf as dependency and include this at the top: #include <tf/transform_datatypes.h>