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 <mavros/mavros_plugin.h>
00028 #include <mavros/setpoint_mixin.h>
00029 #include <pluginlib/class_list_macros.h>
00030
00031 #include <geometry_msgs/PoseStamped.h>
00032
00033 namespace mavplugin {
00034
00040 class SetpointPositionPlugin : public MavRosPlugin,
00041 private SetPositionTargetLocalNEDMixin<SetpointPositionPlugin>,
00042 private TFListenerMixin<SetpointPositionPlugin> {
00043 public:
00044 SetpointPositionPlugin() :
00045 uas(nullptr),
00046 tf_rate(10.0)
00047 { };
00048
00049 void initialize(UAS &uas_,
00050 ros::NodeHandle &nh,
00051 diagnostic_updater::Updater &diag_updater)
00052 {
00053 bool listen_tf;
00054
00055 uas = &uas_;
00056 sp_nh = ros::NodeHandle(nh, "setpoint");
00057
00058 sp_nh.param("position/listen_tf", listen_tf, false);
00059 sp_nh.param<std::string>("position/frame_id", frame_id, "local_origin");
00060 sp_nh.param<std::string>("position/child_frame_id", child_frame_id, "setpoint");
00061 sp_nh.param("position/tf_rate_limit", tf_rate, 50.0);
00062
00063 if (listen_tf) {
00064 ROS_INFO_STREAM_NAMED("setpoint", "Listen to position setpoint transform " << frame_id
00065 << " -> " << child_frame_id);
00066 tf_start("PositionSpTF", &SetpointPositionPlugin::send_setpoint_transform);
00067 }
00068 else {
00069 setpoint_sub = sp_nh.subscribe("local_position", 10, &SetpointPositionPlugin::setpoint_cb, this);
00070 }
00071 }
00072
00073 const std::string get_name() const {
00074 return "SetpointPosition";
00075 }
00076
00077 const message_map get_rx_handlers() {
00078 return { };
00079 }
00080
00081 private:
00082 friend class SetPositionTargetLocalNEDMixin;
00083 friend class TFListenerMixin;
00084 UAS *uas;
00085
00086 ros::NodeHandle sp_nh;
00087 ros::Subscriber setpoint_sub;
00088
00089 std::string frame_id;
00090 std::string child_frame_id;
00091
00092 double tf_rate;
00093
00094
00095
00101 void send_setpoint_transform(const tf::Transform &transform, const ros::Time &stamp) {
00102
00103 tf::Vector3 origin = transform.getOrigin();
00104 tf::Quaternion q = transform.getRotation();
00105
00106
00107
00108
00109 uint16_t ignore_all_except_xyzy = (1<<11)|(7<<6)|(7<<3);
00110
00111
00112 set_position_target_local_ned(stamp.toNSec() / 1000000,
00113 MAV_FRAME_LOCAL_NED,
00114 ignore_all_except_xyzy,
00115 origin.y(), origin.x(), -origin.z(),
00116 0.0, 0.0, 0.0,
00117 0.0, 0.0, 0.0,
00118 tf::getYaw(q), 0.0);
00119 }
00120
00121
00122
00123
00124
00125 void setpoint_cb(const geometry_msgs::PoseStamped::ConstPtr &req) {
00126 tf::Transform transform;
00127 poseMsgToTF(req->pose, transform);
00128 send_setpoint_transform(transform, req->header.stamp);
00129 }
00130 };
00131
00132 };
00133
00134 PLUGINLIB_EXPORT_CLASS(mavplugin::SetpointPositionPlugin, mavplugin::MavRosPlugin)