mirror of
https://github.com/CopterExpress/clover.git
synced 2026-06-06 17:49:32 +00:00
Fix yaw value in rewritten fcu_horiz
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <geometry_msgs/TransformStamped.h>
|
||||
#include <geometry_msgs/PoseStamped.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
class FcuHoriz : public nodelet::Nodelet
|
||||
{
|
||||
geometry_msgs::TransformStamped t_;
|
||||
@@ -11,11 +13,18 @@ class FcuHoriz : public nodelet::Nodelet
|
||||
void handlePose(const geometry_msgs::PoseStampedConstPtr& msg)
|
||||
{
|
||||
static tf2_ros::TransformBroadcaster br;
|
||||
double roll, pitch, yaw;
|
||||
|
||||
t_.header.stamp = msg->header.stamp;
|
||||
t_.header.frame_id = msg->header.frame_id;
|
||||
t_.transform.translation.x = msg->pose.position.x;
|
||||
t_.transform.translation.y = msg->pose.position.y;
|
||||
t_.transform.translation.z = msg->pose.position.z;
|
||||
|
||||
// Warning: this is not thead-safe
|
||||
quaternionToEuler(msg->pose.orientation, roll, pitch, yaw);
|
||||
eulerToQuaternion(t_.transform.rotation, 0, 0, yaw);
|
||||
|
||||
br.sendTransform(t_);
|
||||
}
|
||||
|
||||
|
||||
17
clever/src/util.h
Normal file
17
clever/src/util.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <tf/transform_datatypes.h>
|
||||
#include <geometry_msgs/Quaternion.h>
|
||||
|
||||
inline void quaternionToEuler(geometry_msgs::Quaternion q, double& roll, double& pitch, double& yaw)
|
||||
{
|
||||
tf::Quaternion tfq(q.x, q.y, q.z, q.w);
|
||||
tf::Matrix3x3 m(tfq);
|
||||
m.getRPY(roll, pitch, yaw);
|
||||
}
|
||||
|
||||
inline void eulerToQuaternion(geometry_msgs::Quaternion& q, double roll, double pitch, double yaw)
|
||||
{
|
||||
tf::Quaternion tfq(roll, pitch, yaw);
|
||||
quaternionTFToMsg(tfq, q);
|
||||
}
|
||||
Reference in New Issue
Block a user