setpoint_accel.cpp
Go to the documentation of this file.
1 
10 /*
11  * Copyright 2014 Nuno Marques.
12  *
13  * This file is part of the mavros package and subject to the license terms
14  * in the top-level LICENSE file of the mavros repository.
15  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
16  */
17 
18 #include <mavros/utils.h>
19 #include <mavros/mavros_plugin.h>
20 #include <mavros/setpoint_mixin.h>
22 
23 #include <geometry_msgs/Vector3Stamped.h>
24 
25 namespace mavros {
26 namespace std_plugins {
33  private plugin::SetPositionTargetLocalNEDMixin<SetpointAccelerationPlugin> {
34 public:
36  sp_nh("~setpoint_accel"),
37  send_force(false)
38  { }
39 
40  void initialize(UAS &uas_) override
41  {
42  PluginBase::initialize(uas_);
43 
44  sp_nh.param("send_force", send_force, false);
45 
47  }
48 
50  {
51  return { /* Rx disabled */ };
52  }
53 
54 private:
57 
59 
60  bool send_force;
61 
62  /* -*- mid-level helpers -*- */
63 
69  void send_setpoint_acceleration(const ros::Time &stamp, Eigen::Vector3d &accel_enu)
70  {
71  using mavlink::common::MAV_FRAME;
72 
73  /* Documentation start from bit 1 instead 0.
74  * Ignore position and velocity vectors, yaw and yaw rate
75  */
76  uint16_t ignore_all_except_a_xyz = (3 << 10) | (7 << 3) | (7 << 0);
77 
78  if (send_force)
79  ignore_all_except_a_xyz |= (1 << 9);
80 
81  auto accel = ftf::transform_frame_enu_ned(accel_enu);
82 
83  set_position_target_local_ned(stamp.toNSec() / 1000000,
84  utils::enum_value(MAV_FRAME::LOCAL_NED),
85  ignore_all_except_a_xyz,
86  Eigen::Vector3d::Zero(),
87  Eigen::Vector3d::Zero(),
88  accel,
89  0.0, 0.0);
90  }
91 
92  /* -*- callbacks -*- */
93 
95  Eigen::Vector3d accel_enu;
96 
97  tf::vectorMsgToEigen(req->vector, accel_enu);
98  send_setpoint_acceleration(req->header.stamp, accel_enu);
99  }
100 };
101 } // namespace std_plugins
102 } // namespace mavros
103 
mavros::ftf::transform_frame_enu_ned
T transform_frame_enu_ned(const T &in)
Transform data expressed in ENU to NED frame.
Definition: frame_tf.h:224
mavros::plugin::PluginBase::Subscriptions
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
Definition: mavros_plugin.h:47
mavros::std_plugins::SetpointAccelerationPlugin::initialize
void initialize(UAS &uas_) override
Plugin initializer.
Definition: setpoint_accel.cpp:40
mavros::std_plugins::SetpointAccelerationPlugin::SetPositionTargetLocalNEDMixin
friend class SetPositionTargetLocalNEDMixin
Definition: setpoint_accel.cpp:55
mavros::std_plugins::SetpointAccelerationPlugin::get_subscriptions
Subscriptions get_subscriptions() override
Return vector of MAVLink message subscriptions (handlers)
Definition: setpoint_accel.cpp:49
mavros::plugin::PluginBase::PluginBase
PluginBase()
Plugin constructor Should not do anything before initialize()
Definition: mavros_plugin.h:74
mavros::UAS
UAS for plugins.
Definition: mavros_uas.h:67
mavros::std_plugins::SetpointAccelerationPlugin::send_setpoint_acceleration
void send_setpoint_acceleration(const ros::Time &stamp, Eigen::Vector3d &accel_enu)
Send acceleration/force to FCU acceleration controller.
Definition: setpoint_accel.cpp:69
mavros::std_plugins::SetpointAccelerationPlugin::send_force
bool send_force
Definition: setpoint_accel.cpp:60
mavros::plugin::SetPositionTargetLocalNEDMixin< SetpointAccelerationPlugin >::set_position_target_local_ned
void set_position_target_local_ned(uint32_t time_boot_ms, uint8_t coordinate_frame, uint16_t type_mask, Eigen::Vector3d p, Eigen::Vector3d v, Eigen::Vector3d af, float yaw, float yaw_rate)
Message specification: https://mavlink.io/en/messages/common.html#SET_POSITION_TARGET_LOCAL_NED.
Definition: setpoint_mixin.h:38
ConstPtr
std::shared_ptr< MAVConnInterface const > ConstPtr
utils.h
some useful utils
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
eigen_msg.h
tf::vectorMsgToEigen
void vectorMsgToEigen(const geometry_msgs::Vector3 &m, Eigen::Vector3d &e)
mavros::plugin::SetPositionTargetLocalNEDMixin
This mixin adds set_position_target_local_ned()
Definition: setpoint_mixin.h:35
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
mavros::std_plugins::SetpointAccelerationPlugin::sp_nh
ros::NodeHandle sp_nh
Definition: setpoint_accel.cpp:56
setpoint_mixin.h
Mixin for setpoint plugins.
mavros::std_plugins::SetpointAccelerationPlugin::accel_cb
void accel_cb(const geometry_msgs::Vector3Stamped::ConstPtr &req)
Definition: setpoint_accel.cpp:94
mavros_plugin.h
MAVROS Plugin base.
mavros
Definition: frame_tf.h:34
mavros::std_plugins::SetpointAccelerationPlugin::accel_sub
ros::Subscriber accel_sub
Definition: setpoint_accel.cpp:58
ros::Time
mavros::plugin::PluginBase
MAVROS Plugin base class.
Definition: mavros_plugin.h:36
mavros::std_plugins::SetpointAccelerationPlugin::SetpointAccelerationPlugin
SetpointAccelerationPlugin()
Definition: setpoint_accel.cpp:35
class_list_macros.hpp
TimeBase< Time, Duration >::toNSec
uint64_t toNSec() const
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
mavros::std_plugins::SetpointAccelerationPlugin
Setpoint acceleration/force plugin.
Definition: setpoint_accel.cpp:32
mavros::utils::enum_value
constexpr std::underlying_type< _T >::type enum_value(_T e)
Definition: utils.h:55
ros::NodeHandle
ros::Subscriber


mavros
Author(s): Vladimir Ermakov
autogenerated on Tue May 6 2025 02:34:03