18 #include <mavros_msgs/ESCInfo.h> 19 #include <mavros_msgs/ESCStatus.h> 23 namespace extra_plugins
71 void handle_esc_info(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::ESC_INFO &esc_info)
77 uint8_t esc_index = esc_info.index;
79 _esc_info.counter = esc_info.counter;
80 _esc_info.count = esc_info.count;
81 _esc_info.connection_type = esc_info.connection_type;
82 _esc_info.info = esc_info.info;
84 if (_esc_info.count > _max_esc_count)
86 _max_esc_count = _esc_info.count;
91 _esc_info.esc_info.resize(_max_esc_count);
94 for (
int i = 0; i < std::min<ssize_t>(
batch_size, ssize_t(_max_esc_count) - esc_index); i++)
96 _esc_info.esc_info[esc_index + i].header = _esc_info.header;
97 _esc_info.esc_info[esc_index + i].failure_flags = esc_info.failure_flags[i];
98 _esc_info.esc_info[esc_index + i].error_count = esc_info.error_count[i];
99 _esc_info.esc_info[esc_index + i].temperature = esc_info.temperature[i];
102 _max_esc_info_index = std::max(_max_esc_info_index, esc_info.index);
104 if (_max_esc_info_index == esc_info.index)
106 esc_info_pub.
publish(_esc_info);
110 void handle_esc_status(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::ESC_STATUS &esc_status)
114 uint8_t esc_index = esc_status.index;
118 _esc_status.esc_status.resize(_max_esc_count);
123 for (
int i = 0; i < std::min<ssize_t>(
batch_size, ssize_t(_max_esc_count) - esc_index); i++)
125 _esc_status.esc_status[esc_index + i].header = _esc_status.header;
126 _esc_status.esc_status[esc_index + i].rpm = esc_status.rpm[i];
127 _esc_status.esc_status[esc_index + i].voltage = esc_status.voltage[i];
128 _esc_status.esc_status[esc_index + i].current = esc_status.current[i];
131 _max_esc_status_index = std::max(_max_esc_status_index, esc_status.index);
133 if (_max_esc_status_index == esc_status.index)
135 esc_status_pub.
publish(_esc_status);
144 _max_esc_status_index = 0;
145 _max_esc_info_index = 0;
146 _esc_info.esc_info.resize(0);
147 _esc_status.esc_status.resize(0);
void publish(const boost::shared_ptr< M > &message) const
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
mavros_msgs::ESCStatus _esc_status
void handle_esc_status(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ESC_STATUS &esc_status)
void initialize(UAS &uas_) override
ros::Time synchronise_stamp(uint32_t time_boot_ms)
ros::Publisher esc_info_pub
std::lock_guard< std::mutex > lock_guard
void connection_cb(bool connected) override
std::atomic< bool > connected
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Subscriptions get_subscriptions() override
mavros_msgs::ESCInfo _esc_info
uint8_t _max_esc_status_index
ros::Publisher esc_status_pub
void enable_connection_cb()
void handle_esc_info(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ESC_INFO &esc_info)
std::vector< HandlerInfo > Subscriptions
uint8_t _max_esc_info_index
void initialize(UAS &uas_) override
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
std::recursive_mutex mutex