mount_control.cpp
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2019 Jaeyoung Lim.
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/CommandLong.h>
20 #include <mavros_msgs/MountControl.h>
21 #include <geometry_msgs/Quaternion.h>
22 #include <mavros_msgs/MountConfigure.h>
23 
24 namespace mavros {
25 namespace extra_plugins {
26 
28 using mavlink::common::MAV_MOUNT_MODE;
29 using mavlink::common::MAV_CMD;
30 using utils::enum_value;
31 
39 public:
41  nh("~"),
42  mount_nh("~mount_control")
43  { }
44 
45  void initialize(UAS &uas_) override
46  {
48 
50  mount_orientation_pub = mount_nh.advertise<geometry_msgs::Quaternion>("orientation", 10);
52 
53  }
54 
56  {
57  return {
59  };
60  }
61 
62 private:
68 
76  void handle_mount_orientation(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MOUNT_ORIENTATION &mo)
77  {
78  auto q = ftf::quaternion_from_rpy(Eigen::Vector3d(mo.roll, mo.pitch, mo.yaw) * M_PI / 180.0);
79  geometry_msgs::Quaternion quaternion_msg;
80  tf::quaternionEigenToMsg(q, quaternion_msg);
81  mount_orientation_pub.publish(quaternion_msg);
82  }
83 
91  {
92  mavlink::common::msg::COMMAND_LONG cmd {};
93 
94  cmd.target_system = m_uas->get_tgt_system();
95  cmd.target_component = m_uas->get_tgt_component();
96  cmd.command = enum_value(MAV_CMD::DO_MOUNT_CONTROL);
97  cmd.param1 = req->pitch;
98  cmd.param2 = req->roll;
99  cmd.param3 = req->yaw;
100  cmd.param4 = req->altitude; //
101  cmd.param5 = req->latitude; // lattitude in degrees * 1E7
102  cmd.param6 = req->longitude; // longitude in degrees * 1E7
103  cmd.param7 = req->mode; // MAV_MOUNT_MODE
104 
105  UAS_FCU(m_uas)->send_message_ignore_drop(cmd);
106  }
107 
108  bool mount_configure_cb(mavros_msgs::MountConfigure::Request &req,
109  mavros_msgs::MountConfigure::Response &res)
110  {
111  using mavlink::common::MAV_CMD;
112 
113  try {
114  auto client = nh.serviceClient<mavros_msgs::CommandLong>("cmd/command");
115 
116  mavros_msgs::CommandLong cmd{};
117 
118  cmd.request.broadcast = false;
119  cmd.request.command = enum_value(MAV_CMD::DO_MOUNT_CONFIGURE);
120  cmd.request.confirmation = false;
121  cmd.request.param1 = req.mode;
122  cmd.request.param2 = req.stabilize_roll;
123  cmd.request.param3 = req.stabilize_pitch;
124  cmd.request.param4 = req.stabilize_yaw;
125  cmd.request.param5 = req.roll_input;
126  cmd.request.param6 = req.pitch_input;
127  cmd.request.param7 = req.yaw_input;
128 
129  ROS_DEBUG_NAMED("mount", "MountConfigure: Request mode %u ", req.mode);
130  res.success = client.call(cmd);
131  }
132  catch (ros::InvalidNameException &ex) {
133  ROS_ERROR_NAMED("mount", "MountConfigure: %s", ex.what());
134  }
135 
136  ROS_ERROR_COND_NAMED(!res.success, "mount", "MountCongifure: command plugin service call failed!");
137 
138  return res.success;
139  }
140 };
141 } // namespace extra_plugins
142 } // namespace mavros
143 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
#define ROS_ERROR_COND_NAMED(cond, name,...)
Subscriptions get_subscriptions() override
std::shared_ptr< MAVConnInterface const > ConstPtr
void publish(const boost::shared_ptr< M > &message) const
void quaternionEigenToMsg(const Eigen::Quaterniond &e, geometry_msgs::Quaternion &m)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
string cmd
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void handle_mount_orientation(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MOUNT_ORIENTATION &mo)
Publish the mount orientation.
bool mount_configure_cb(mavros_msgs::MountConfigure::Request &req, mavros_msgs::MountConfigure::Response &res)
#define ROS_DEBUG_NAMED(name,...)
uint8_t get_tgt_system()
#define UAS_FCU(uasobjptr)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Eigen::Quaterniond quaternion_from_rpy(const Eigen::Vector3d &rpy)
std::vector< HandlerInfo > Subscriptions
#define ROS_ERROR_NAMED(name,...)
void initialize(UAS &uas_) override
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
uint8_t get_tgt_component()
void command_cb(const mavros_msgs::MountControl::ConstPtr &req)
Send mount control commands to vehicle.
constexpr std::underlying_type< _T >::type enum_value(_T e)


mavros_extras
Author(s): Vladimir Ermakov , Amilcar Lucas
autogenerated on Tue Jun 1 2021 02:36:36