Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish BATTERY2 message as /mavros/battery2 topic #1619

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions mavros/src/plugins/sys_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ class SystemStatusPlugin : public plugin::PluginBase
state_pub = nh.advertise<mavros_msgs::State>("state", 10, true);
extended_state_pub = nh.advertise<mavros_msgs::ExtendedState>("extended_state", 10);
batt_pub = nh.advertise<BatteryMsg>("battery", 10);
batt2_pub = nh.advertise<BatteryMsg>("battery2", 10);
estimator_status_pub = nh.advertise<mavros_msgs::EstimatorStatus>("estimator_status", 10);
statustext_pub = nh.advertise<mavros_msgs::StatusText>("statustext/recv", 10);
statustext_sub = nh.subscribe("statustext/send", 10, &SystemStatusPlugin::statustext_cb, this);
Expand All @@ -514,6 +515,7 @@ class SystemStatusPlugin : public plugin::PluginBase
make_handler(&SystemStatusPlugin::handle_extended_sys_state),
make_handler(&SystemStatusPlugin::handle_battery_status),
make_handler(&SystemStatusPlugin::handle_estimator_status),
make_handler(&SystemStatusPlugin::handle_battery2),
};
}

Expand All @@ -532,6 +534,7 @@ class SystemStatusPlugin : public plugin::PluginBase
ros::Publisher state_pub;
ros::Publisher extended_state_pub;
ros::Publisher batt_pub;
ros::Publisher batt2_pub;
ros::Publisher estimator_status_pub;
ros::Publisher statustext_pub;
ros::Subscriber statustext_sub;
Expand Down Expand Up @@ -795,6 +798,19 @@ class SystemStatusPlugin : public plugin::PluginBase
batt_pub.publish(batt_msg);
}

void handle_battery2(const mavlink::mavlink_message_t *msg, mavlink::ardupilotmega::msg::BATTERY2 &batt) {
float volt = batt.voltage / 1000.0f; // mV
float curr = batt.current_battery / 100.0f; // 10 mA or -1

auto batt_msg = boost::make_shared<BatteryMsg>();
batt_msg->header.stamp = ros::Time::now();

batt_msg->voltage = volt;
batt_msg->current = curr;

batt2_pub.publish(batt_msg);
}

void handle_statustext(const mavlink::mavlink_message_t *msg, mavlink::common::msg::STATUSTEXT &textm)
{
auto text = mavlink::to_string(textm.text);
Expand Down