19 #include <sensor_msgs/LaserScan.h> 22 namespace extra_plugins {
26 using mavlink::common::MAV_DISTANCE_SENSOR;
65 mavlink::common::msg::OBSTACLE_DISTANCE obstacle {};
67 if (req->ranges.size() <= obstacle.distances.size()) {
69 Eigen::Map<Eigen::Matrix<uint16_t, Eigen::Dynamic, 1> > map_distances(obstacle.distances.data(), req->ranges.size());
70 auto cm_ranges = Eigen::Map<const Eigen::VectorXf>(req->ranges.data(), req->ranges.size()) * 1e2;
71 map_distances = cm_ranges.cast<uint16_t>();
72 std::fill(obstacle.distances.begin() + req->ranges.size(), obstacle.distances.end(), UINT16_MAX);
73 obstacle.increment = req->angle_increment *
RAD_TO_DEG;
76 size_t scale_factor = ceil(
double(req->ranges.size()) / obstacle.distances.size());
77 for (
size_t i = 0; i < obstacle.distances.size(); i++) {
78 obstacle.distances[i] = UINT16_MAX;
79 for (
size_t j = 0; j < scale_factor; j++) {
80 size_t req_index = i * scale_factor + j;
81 if (req_index < req->ranges.size()) {
82 const float dist_m = req->ranges[req_index];
83 if (!std::isnan(dist_m)) {
84 obstacle.distances[i] = std::min(obstacle.distances[i], (uint16_t)(dist_m * 1e2));
89 obstacle.increment = ceil(req->angle_increment * RAD_TO_DEG * scale_factor);
92 obstacle.time_usec = req->header.stamp.toNSec() / 1000;
94 obstacle.min_distance = req->range_min * 1e2;
95 obstacle.max_distance = req->range_max * 1e2;
97 ROS_DEBUG_STREAM_NAMED(
"obstacle_distance",
"OBSDIST: sensor type: " << utils::to_string_enum<MAV_DISTANCE_SENSOR>(obstacle.sensor_type)
98 << std::endl << obstacle.to_yaml());
std::shared_ptr< MAVConnInterface const > ConstPtr
#define ROS_DEBUG_STREAM_NAMED(name, args)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
Subscriptions get_subscriptions()
ros::Subscriber obstacle_sub
#define UAS_FCU(uasobjptr)
ros::NodeHandle obstacle_nh
void obstacle_cb(const sensor_msgs::LaserScan::ConstPtr &req)
Send obstacle distance array to the FCU.
void initialize(UAS &uas_)
static constexpr double RAD_TO_DEG
Radians to degrees.
std::vector< HandlerInfo > Subscriptions
void initialize(UAS &uas_)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
constexpr std::underlying_type< _T >::type enum_value(_T e)