altitude.cpp
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2015 Andreas Antener <andreas@uaventure.com>.
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 <mavros_msgs/Altitude.h>
20 
21 namespace mavros {
22 namespace std_plugins {
27 public:
29  nh("~")
30  { }
31 
35  void initialize(UAS &uas_)
36  {
37  PluginBase::initialize(uas_);
38 
39  nh.param<std::string>("frame_id", frame_id, "map");
40  altitude_pub = nh.advertise<mavros_msgs::Altitude>("altitude", 10);
41  }
42 
44  {
45  return {
47  };
48  }
49 
50 private:
52  std::string frame_id;
53 
55 
56  void handle_altitude(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ALTITUDE &altitude)
57  {
58  auto ros_msg = boost::make_shared<mavros_msgs::Altitude>();
59  ros_msg->header = m_uas->synchronized_header(frame_id, altitude.time_usec);
60 
61  ros_msg->monotonic = altitude.altitude_monotonic;
62  ros_msg->amsl = altitude.altitude_amsl;
63  ros_msg->local = altitude.altitude_local;
64  ros_msg->relative = altitude.altitude_relative;
65  ros_msg->terrain = altitude.altitude_terrain;
66  ros_msg->bottom_clearance = altitude.bottom_clearance;
67 
68  altitude_pub.publish(ros_msg);
69  }
70 };
71 } // namespace std_plugins
72 } // namespace mavros
73 
MAVROS Plugin base class.
Definition: mavros_plugin.h:37
std_msgs::Header synchronized_header(const std::string &frame_id, const T time_stamp)
Create message header from time_boot_ms or time_usec stamps and frame_id.
Definition: mavros_uas.h:325
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
void handle_altitude(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ALTITUDE &altitude)
Definition: altitude.cpp:56
PluginBase()
Plugin constructor Should not do anything before initialize()
Definition: mavros_plugin.h:75
UAS for plugins.
Definition: mavros_uas.h:66
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
Definition: mavros_plugin.h:48
Subscriptions get_subscriptions()
Return vector of MAVLink message subscriptions (handlers)
Definition: altitude.cpp:43
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


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