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

Add plugin for reporting terrain height estimate from the FCU #1677

Merged
merged 5 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions mavros_extras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ add_library(mavros_extras
src/plugins/play_tune.cpp
src/plugins/px4flow.cpp
src/plugins/rangefinder.cpp
src/plugins/terrain.cpp
src/plugins/trajectory.cpp
src/plugins/tunnel.cpp
src/plugins/vibration.cpp
Expand Down
3 changes: 3 additions & 0 deletions mavros_extras/mavros_plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<class name="rangefinder" type="mavros::extra_plugins::RangefinderPlugin" base_class_type="mavros::plugin::PluginBase">
<description>Publish RANGEFINDER message data from FCU sensors in companion computer.</description>
</class>
<class name="terrain" type="mavros::extra_plugins::TerrainPlugin" base_class_type="mavros::plugin::PluginBase">
<description>Publish TERRAIN_REPORT message data from FCU to companion computer.</description>
</class>
<class name="trajectory" type="mavros::extra_plugins::TrajectoryPlugin" base_class_type="mavros::plugin::PluginBase">
<description>Receive planned path from the FCU and send back corrected path (collision free, smoothed) to the FCU.</description>
</class>
Expand Down
74 changes: 74 additions & 0 deletions mavros_extras/src/plugins/terrain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @brief Terrain plugin
* @file terrain.cpp
* @author Matt Anderson <anderson_rayner@hotmail.com>
*
* @addtogroup plugin
* @{
*/
/*
* Copyright 2021 Ardupilot.
*
* This file is part of the mavros package and subject to the license terms
* in the top-level LICENSE file of the mavros repository.
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
*/

#include <mavros/mavros_plugin.h>
#include <mavros_msgs/Terrain.h>

namespace mavros {
namespace extra_plugins {
/**
* @brief Terrain height plugin.
*
* This plugin allows publishing of terrain height estimate from FCU to ROS.
*
*/
class TerrainPlugin : public plugin::PluginBase {
public:
TerrainPlugin() : PluginBase(),
terrain_nh("~terrain")
{ }

void initialize(UAS &uas_) override
{
PluginBase::initialize(uas_);

terrain_pub = terrain_nh.advertise<mavros_msgs::Terrain>("in", 10);
vooon marked this conversation as resolved.
Show resolved Hide resolved
}

Subscriptions get_subscriptions() override
{
return {
make_handler(&TerrainPlugin::handle_terrain)
};
}

private:
ros::NodeHandle terrain_nh;

ros::Publisher terrain_pub;

void handle_terrain(const mavlink::mavlink_message_t *msg, mavlink::common::msg::TERRAIN_REPORT &terrain) {
vooon marked this conversation as resolved.
Show resolved Hide resolved
auto terrain_msg = boost::make_shared<mavros_msgs::Terrain>();

terrain_msg->header.stamp = ros::Time::now();
terrain_msg->header.frame_id = "terrain";

terrain_msg->latitude = (double) terrain.lat / 1e7;
terrain_msg->longitude = (double) terrain.lon / 1e7;
terrain_msg->spacing = terrain.spacing;
terrain_msg->terrain_height = terrain.terrain_height;
terrain_msg->current_height = terrain.current_height;
terrain_msg->pending = terrain.pending;
terrain_msg->loaded = terrain.loaded;

terrain_pub.publish(terrain_msg);
}
};
} // namespace extra_plugins
} // namespace mavros

#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(mavros::extra_plugins::TerrainPlugin, mavros::plugin::PluginBase)
1 change: 1 addition & 0 deletions mavros_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_message_files(
RTKBaseline.msg
State.msg
StatusText.msg
Terrain.msg
Thrust.msg
TimesyncStatus.msg
Trajectory.msg
Expand Down
12 changes: 12 additions & 0 deletions mavros_msgs/msg/Terrain.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Message for TERRAIN_REPORT
# https://mavlink.io/en/messages/common.html#TERRAIN_REPORT

std_msgs/Header header

float64 latitude
float64 longitude
uint16 spacing
float32 terrain_height # in meters, terrain height
float32 current_height # in meters, vehicle height above terrain
uint16 pending
uint16 loaded