Go to the documentation of this file.00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <angles/angles.h>
00028 #include <mavros/mavros_plugin.h>
00029 #include <pluginlib/class_list_macros.h>
00030
00031 #include <mavros/VFR_HUD.h>
00032 #include <geometry_msgs/TwistStamped.h>
00033
00034 namespace mavplugin {
00035
00039 class VfrHudPlugin : public MavRosPlugin {
00040 public:
00041 VfrHudPlugin()
00042 { }
00043
00047 void initialize(UAS &uas,
00048 ros::NodeHandle &nh,
00049 diagnostic_updater::Updater &diag_updater)
00050 {
00051 vfr_pub = nh.advertise<mavros::VFR_HUD>("vfr_hud", 10);
00052
00053 #ifdef MAVLINK_MSG_ID_WIND
00054 wind_pub = nh.advertise<geometry_msgs::TwistStamped>("wind_estimation", 10);
00055 #endif
00056 }
00057
00058 std::string const get_name() const {
00059 return "VFRHUD";
00060 }
00061
00062 const message_map get_rx_handlers() {
00063 return {
00064 MESSAGE_HANDLER(MAVLINK_MSG_ID_VFR_HUD, &VfrHudPlugin::handle_vfr_hud),
00065 #ifdef MAVLINK_MSG_ID_WIND
00066 MESSAGE_HANDLER(MAVLINK_MSG_ID_WIND, &VfrHudPlugin::handle_wind),
00067 #endif
00068 };
00069 }
00070
00071 private:
00072 ros::Publisher vfr_pub;
00073 ros::Publisher wind_pub;
00074
00075 void handle_vfr_hud(const mavlink_message_t *msg, uint8_t sysid, uint8_t compid) {
00076 mavlink_vfr_hud_t vfr_hud;
00077 mavlink_msg_vfr_hud_decode(msg, &vfr_hud);
00078
00079 auto vmsg = boost::make_shared<mavros::VFR_HUD>();
00080 vmsg->header.stamp = ros::Time::now();
00081 vmsg->airspeed = vfr_hud.airspeed;
00082 vmsg->groundspeed = vfr_hud.groundspeed;
00083 vmsg->heading = vfr_hud.heading;
00084 vmsg->throttle = vfr_hud.throttle / 100.0;
00085 vmsg->altitude = vfr_hud.alt;
00086 vmsg->climb = vfr_hud.climb;
00087
00088 vfr_pub.publish(vmsg);
00089 }
00090
00091 #ifdef MAVLINK_MSG_ID_WIND
00092
00095 void handle_wind(const mavlink_message_t *msg, uint8_t sysid, uint8_t compid) {
00096 mavlink_wind_t wind;
00097 mavlink_msg_wind_decode(msg, &wind);
00098
00099 const double speed = wind.speed;
00100 const double course = angles::from_degrees(wind.direction);
00101
00102 auto twist = boost::make_shared<geometry_msgs::TwistStamped>();
00103 twist->header.stamp = ros::Time::now();
00104
00105 twist->twist.linear.x = speed * std::sin(course);
00106 twist->twist.linear.y = speed * std::cos(course);
00107 twist->twist.linear.z = wind.speed_z;
00108
00109 wind_pub.publish(twist);
00110 }
00111 #endif
00112 };
00113
00114 };
00115
00116 PLUGINLIB_EXPORT_CLASS(mavplugin::VfrHudPlugin, mavplugin::MavRosPlugin)
00117