manual_control.cpp
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2015 Matias Nitsche.
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/ManualControl.h>
20 
21 namespace mavros {
22 namespace std_plugins {
27 public:
29  manual_control_nh("~manual_control")
30  { }
31 
32  void initialize(UAS &uas_)
33  {
34  PluginBase::initialize(uas_);
35 
36  control_pub = manual_control_nh.advertise<mavros_msgs::ManualControl>("control", 10);
38  }
39 
41  return {
43  };
44  }
45 
46 private:
48 
51 
52  /* -*- rx handlers -*- */
53 
54  void handle_manual_control(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MANUAL_CONTROL &manual_control)
55  {
56  auto manual_control_msg = boost::make_shared<mavros_msgs::ManualControl>();
57 
58  manual_control_msg->header.stamp = ros::Time::now();
59  manual_control_msg->x = (manual_control.x / 1000.0);
60  manual_control_msg->y = (manual_control.y / 1000.0);
61  manual_control_msg->z = (manual_control.z / 1000.0);
62  manual_control_msg->r = (manual_control.r / 1000.0);
63  manual_control_msg->buttons = manual_control.buttons;
64 
65  control_pub.publish(manual_control_msg);
66  }
67 
68  /* -*- callbacks -*- */
69 
71  {
72  mavlink::common::msg::MANUAL_CONTROL msg;
73  msg.target = m_uas->get_tgt_system();
74 
75  msg.x = req->x;
76  msg.y = req->y;
77  msg.z = req->z;
78  msg.r = req->r;
79  msg.buttons = req->buttons;
80 
81  UAS_FCU(m_uas)->send_message_ignore_drop(msg);
82  }
83 };
84 } // namespace std_plugins
85 } // namespace mavros
86 
msg
MAVROS Plugin base class.
Definition: mavros_plugin.h:37
std::shared_ptr< MAVConnInterface const > ConstPtr
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
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
PluginBase()
Plugin constructor Should not do anything before initialize()
Definition: mavros_plugin.h:75
uint8_t get_tgt_system()
Return communication target system.
Definition: mavros_uas.h:155
UAS for plugins.
Definition: mavros_uas.h:66
#define UAS_FCU(uasobjptr)
helper accessor to FCU link interface
Definition: mavros_uas.h:41
void handle_manual_control(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MANUAL_CONTROL &manual_control)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
Definition: mavros_plugin.h:48
void initialize(UAS &uas_)
Plugin initializer.
static Time now()
Subscriptions get_subscriptions()
Return vector of MAVLink message subscriptions (handlers)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void send_cb(const mavros_msgs::ManualControl::ConstPtr req)


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