wind_estimation.cpp
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2018 Thomas Stastny <thomas.stastny@mavt.ethz.ch>
11  *
12  * This file is part of the mavros package and subject to the license terms
13  * in the top-level LICENSE file of the mavros repository.
14  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
15  */
16 
17 #include <mavros/mavros_plugin.h>
18 
19 #include <angles/angles.h>
21 
22 #include <geometry_msgs/TwistWithCovarianceStamped.h>
23 
24 namespace mavros {
25 namespace std_plugins {
30 public:
32  nh("~")
33  { }
34 
38  void initialize(UAS &uas_)
39  {
40  PluginBase::initialize(uas_);
41 
42  wind_pub = nh.advertise<geometry_msgs::TwistWithCovarianceStamped>("wind_estimation", 10);
43  }
44 
46  {
47  return {
50  };
51  }
52 
53 private:
55 
57 
61  void handle_apm_wind(const mavlink::mavlink_message_t *msg, mavlink::ardupilotmega::msg::WIND &wind)
62  {
63  const double speed = wind.speed;
64  const double course = -angles::from_degrees(wind.direction); // direction "from" -> direction "to"
65 
66  auto twist_cov = boost::make_shared<geometry_msgs::TwistWithCovarianceStamped>();
67  twist_cov->header.stamp = ros::Time::now();
68  // TODO: check math's
69  twist_cov->twist.twist.linear.x = speed * std::sin(course); // E
70  twist_cov->twist.twist.linear.y = speed * std::cos(course); // N
71  twist_cov->twist.twist.linear.z = -wind.speed_z;// D -> U
72 
73  // covariance matrix unknown in APM msg
74  ftf::EigenMapCovariance6d cov_map(twist_cov->twist.covariance.data());
75  cov_map.setZero();
76  cov_map(0, 0) = -1.0;
77 
78  wind_pub.publish(twist_cov);
79  }
80 
84  void handle_px4_wind(const mavlink::mavlink_message_t *msg, mavlink::common::msg::WIND_COV &wind)
85  {
86  auto twist_cov = boost::make_shared<geometry_msgs::TwistWithCovarianceStamped>();
87  twist_cov->header.stamp = m_uas->synchronise_stamp(wind.time_usec);
88 
89  tf::vectorEigenToMsg(ftf::transform_frame_ned_enu(Eigen::Vector3d(wind.wind_x, wind.wind_y, wind.wind_z)),
90  twist_cov->twist.twist.linear);
91 
92  // fill available covariance elements
93  ftf::EigenMapCovariance6d cov_map(twist_cov->twist.covariance.data());
94  cov_map.setZero();
95  cov_map(0, 0) = wind.var_horiz; // NOTE: this is a summed covariance for both x and y horizontal wind components
96  cov_map(2, 2) = wind.var_vert;
97 
98  wind_pub.publish(twist_cov);
99  }
100 };
101 } // namespace std_plugins
102 } // namespace mavros
103 
MAVROS Plugin base class.
Definition: mavros_plugin.h:37
void publish(const boost::shared_ptr< M > &message) const
MAVROS Plugin base.
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
Definition: mavros_plugin.h:88
Eigen::Map< Eigen::Matrix< double, 6, 6, Eigen::RowMajor > > EigenMapCovariance6d
Eigen::Map for Covariance6d.
Definition: frame_tf.h:50
PluginBase()
Plugin constructor Should not do anything before initialize()
Definition: mavros_plugin.h:75
Subscriptions get_subscriptions()
Return vector of MAVLink message subscriptions (handlers)
UAS for plugins.
Definition: mavros_uas.h:66
static double from_degrees(double degrees)
void vectorEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Vector3 &m)
ros::Time synchronise_stamp(uint32_t time_boot_ms)
Compute FCU message time from time_boot_ms or time_usec field.
T transform_frame_ned_enu(const T &in)
Transform data expressed in NED to ENU frame.
Definition: frame_tf.h:187
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
Definition: mavros_plugin.h:48
static Time now()
void handle_px4_wind(const mavlink::mavlink_message_t *msg, mavlink::common::msg::WIND_COV &wind)
void handle_apm_wind(const mavlink::mavlink_message_t *msg, mavlink::ardupilotmega::msg::WIND &wind)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


mavros
Author(s): Vladimir Ermakov
autogenerated on Mon Jul 8 2019 03:20:11