2019-07-31 15:17:35 -04:00
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2019 PX4 Development Team. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <drivers/drv_hrt.h>
|
|
|
|
|
#include <lib/conversion/rotation.h>
|
2019-08-04 14:19:11 -04:00
|
|
|
#include <uORB/PublicationMulti.hpp>
|
2019-07-31 15:17:35 -04:00
|
|
|
#include <uORB/topics/distance_sensor.h>
|
|
|
|
|
|
2020-09-21 16:20:50 -04:00
|
|
|
class PX4Rangefinder
|
2019-07-31 15:17:35 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2019-09-01 19:01:12 -06:00
|
|
|
PX4Rangefinder(const uint32_t device_id,
|
|
|
|
|
const uint8_t device_orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
|
2020-05-04 11:09:30 -04:00
|
|
|
~PX4Rangefinder();
|
2019-07-31 15:17:35 -04:00
|
|
|
|
2020-12-15 18:28:22 -08:00
|
|
|
// Set the MAV_DISTANCE_SENSOR type (LASER, ULTRASOUND, INFRARED, RADAR)
|
|
|
|
|
void set_rangefinder_type(uint8_t rangefinder_type) { _distance_sensor_pub.get().type = rangefinder_type; };
|
2019-07-31 15:17:35 -04:00
|
|
|
|
2021-06-15 10:12:24 -06:00
|
|
|
void set_device_id(const uint32_t device_id) { _distance_sensor_pub.get().device_id = device_id; };
|
2020-12-15 18:28:22 -08:00
|
|
|
void set_device_type(const uint8_t device_type);
|
2019-07-31 15:17:35 -04:00
|
|
|
|
2019-09-01 19:01:12 -06:00
|
|
|
void set_fov(const float fov) { set_hfov(fov); set_vfov(fov); }
|
|
|
|
|
void set_hfov(const float fov) { _distance_sensor_pub.get().h_fov = fov; }
|
|
|
|
|
void set_vfov(const float fov) { _distance_sensor_pub.get().v_fov = fov; }
|
2019-07-31 15:17:35 -04:00
|
|
|
|
2019-09-01 19:01:12 -06:00
|
|
|
void set_max_distance(const float distance) { _distance_sensor_pub.get().max_distance = distance; }
|
|
|
|
|
void set_min_distance(const float distance) { _distance_sensor_pub.get().min_distance = distance; }
|
2019-07-31 15:17:35 -04:00
|
|
|
|
2019-09-01 19:01:12 -06:00
|
|
|
void set_orientation(const uint8_t device_orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
|
|
|
|
|
|
2020-04-26 21:59:46 -04:00
|
|
|
void update(const hrt_abstime ×tamp_sample, const float distance, const int8_t quality = -1);
|
2019-07-31 15:17:35 -04:00
|
|
|
|
2020-09-21 16:20:50 -04:00
|
|
|
int get_instance() { return _distance_sensor_pub.get_instance(); };
|
2020-09-07 19:22:08 -04:00
|
|
|
|
2019-07-31 15:17:35 -04:00
|
|
|
private:
|
2020-09-21 16:20:50 -04:00
|
|
|
uORB::PublicationMultiData<distance_sensor_s> _distance_sensor_pub{ORB_ID(distance_sensor)};
|
2019-07-31 15:17:35 -04:00
|
|
|
};
|