Skip to content

Commit

Permalink
mavros: fix run on Galactic
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Ermakov <[email protected]>
  • Loading branch information
vooon committed Jun 20, 2021
1 parent f9dce35 commit 164f3a2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
6 changes: 6 additions & 0 deletions mavros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ include_directories(
## Check if the datasets are installed
include(CheckGeographicLibDatasets)

if(rclcpp_VERSION VERSION_LESS 9.0.0)
add_definitions(
-DUSE_OLD_DECLARE_PARAMETER
)
endif()

# [[[cog:
# import mavros_cog
# ]]]
Expand Down
8 changes: 6 additions & 2 deletions mavros/include/mavros/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,16 @@ class Plugin : public std::enable_shared_from_this<Plugin>
)
{
node_watch_parameters[name] = cb;

#ifdef USE_OLD_DECLARE_PARAMETER
// NOTE(vooon): for Foxy:
return node->declare_parameter(
name,
rclcpp::ParameterValue(), parameter_descriptor, ignore_override);
// NOTE(vooon): for master
// return node->declare_parameter<ParameterT>(name, parameter_descriptor, ignore_override);
#else
// NOTE(vooon): for Galactic:
return node->declare_parameter<ParameterT>(name, parameter_descriptor, ignore_override);
#endif
}

template<typename ParameterT>
Expand Down
2 changes: 2 additions & 0 deletions mavros/src/plugins/param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class Parameter
"CMD_TOTAL",
"CMD_INDEX",
"LOG_LASTFILE",
"MIS_TOTAL",
"FENCE_TOTAL",
"FORMAT_VERSION"
};
Expand Down Expand Up @@ -983,6 +984,7 @@ class ParamPlugin : public plugin::Plugin
res->success = false;
return;
}
lock.unlock();
}

if (Parameter::check_exclude_param_id(req->param_id) && !req->force_set) {
Expand Down
43 changes: 30 additions & 13 deletions mavros/src/plugins/waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ class WaypointPlugin : public plugin::MissionBase
{
public:
explicit WaypointPlugin(plugin::UASPtr uas_)
: MissionBase(uas_, "mission")
: MissionBase(uas_, "mission"),
enable_partial_push_auto(true)
{
rcl_interfaces::msg::ParameterDescriptor desc_pp{};
desc_pp.dynamic_typing = true;

enable_node_watch_parameters();

// NOTE(vooon): I'm not quite sure that this option would work with mavros router
Expand All @@ -49,16 +53,25 @@ class WaypointPlugin : public plugin::MissionBase
use_mission_item_int = p.as_bool();
});

node_declate_and_watch_parameter<bool>(
"enable_partial_push", [&](const rclcpp::Parameter & p) {
node_declate_and_watch_parameter(
"enable_partial_push", 2, [&](const rclcpp::Parameter & p) {
RCLCPP_DEBUG_STREAM(get_logger(), log_prefix << ": enable_partial_push = " << p);

if (p.get_type() != rclcpp::PARAMETER_BOOL) {
return;
if (p.get_type() == rclcpp::PARAMETER_INTEGER) {
auto v = p.as_int();

enable_partial_push_auto = v >= 2;
if (enable_partial_push_auto) {
enable_partial_push = detect_partial_push();
} else {
enable_partial_push = v != 0;
}
}

enable_partial_push = p.as_bool();
});
if (p.get_type() == rclcpp::PARAMETER_BOOL) {
enable_partial_push = p.as_bool();
}
}, desc_pp);

auto wp_qos = rclcpp::QoS(10).transient_local();

Expand Down Expand Up @@ -94,6 +107,8 @@ class WaypointPlugin : public plugin::MissionBase
rclcpp::Service<mavros_msgs::srv::WaypointClear>::SharedPtr clear_srv;
rclcpp::Service<mavros_msgs::srv::WaypointSetCurrent>::SharedPtr set_cur_srv;

bool enable_partial_push_auto;

/* -*- mid-level helpers -*- */

// Acts when capabilities of the fcu are changed
Expand All @@ -120,14 +135,11 @@ class WaypointPlugin : public plugin::MissionBase
if (connected) {
schedule_pull(BOOTUP_TIME);

const auto key = "enable_partial_push";
rclcpp::Parameter p;
if (!node->get_parameter(key, p) || p.get_type() == rclcpp::PARAMETER_NOT_SET) {
bool new_state = uas->is_ardupilotmega();
if (enable_partial_push_auto) {
enable_partial_push = detect_partial_push();

RCLCPP_INFO_STREAM(
get_logger(), log_prefix << ": detected enable_partial_push: " << new_state);
node->set_parameter(rclcpp::Parameter(key, new_state));
get_logger(), log_prefix << ": detected enable_partial_push: " << enable_partial_push);
}
} else if (schedule_timer) {
schedule_timer->cancel();
Expand Down Expand Up @@ -159,6 +171,11 @@ class WaypointPlugin : public plugin::MissionBase
wp_reached_pub->publish(wr);
}

bool detect_partial_push()
{
return uas->is_ardupilotmega();
}

/* -*- ROS callbacks -*- */

void pull_cb(
Expand Down

0 comments on commit 164f3a2

Please sign in to comment.