mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
添加ulanding patch 驱动,第一次编译成功
This commit is contained in:
@@ -45,6 +45,7 @@ add_subdirectory(srf02)
|
||||
add_subdirectory(teraranger)
|
||||
add_subdirectory(tfmini)
|
||||
add_subdirectory(ulanding_radar)
|
||||
add_subdirectory(upatch_radar)
|
||||
add_subdirectory(vl53l0x)
|
||||
add_subdirectory(vl53l1x)
|
||||
add_subdirectory(gy_us42)
|
||||
|
||||
239
src/drivers/distance_sensor/upatch_radar/AerotennaUPatch.cpp
Normal file
239
src/drivers/distance_sensor/upatch_radar/AerotennaUPatch.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2016-2020 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "AerotennaUPatch.hpp"
|
||||
|
||||
#include <lib/drivers/device/Device.hpp>
|
||||
|
||||
AerotennaUPatch::AerotennaUPatch(const char *port, uint8_t rotation) :
|
||||
ScheduledWorkItem(MODULE_NAME, px4::serial_port_to_wq(port)),
|
||||
_px4_rangefinder(0, rotation)
|
||||
{
|
||||
/* store port name */
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
|
||||
/* enforce null termination */
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
|
||||
device::Device::DeviceId device_id;
|
||||
device_id.devid_s.bus_type = device::Device::DeviceBusType_SERIAL;
|
||||
|
||||
uint8_t bus_num = atoi(&_port[strlen(_port) - 1]); // Assuming '/dev/ttySx'
|
||||
|
||||
if (bus_num < 10) {
|
||||
device_id.devid_s.bus = bus_num;
|
||||
}
|
||||
|
||||
_px4_rangefinder.set_device_id(device_id.devid);
|
||||
_px4_rangefinder.set_device_type(DRV_DIST_DEVTYPE_UPATCH);
|
||||
_px4_rangefinder.set_rangefinder_type(distance_sensor_s::MAV_DISTANCE_SENSOR_RADAR);
|
||||
|
||||
_px4_rangefinder.set_min_distance(UPATCH_MIN_DISTANCE);
|
||||
_px4_rangefinder.set_max_distance(UPATCH_MAX_DISTANCE);
|
||||
}
|
||||
|
||||
AerotennaUPatch::~AerotennaUPatch()
|
||||
{
|
||||
stop();
|
||||
|
||||
perf_free(_sample_perf);
|
||||
perf_free(_comms_errors);
|
||||
}
|
||||
|
||||
int AerotennaUPatch::init()
|
||||
{
|
||||
start();
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int AerotennaUPatch::collect()
|
||||
{
|
||||
perf_begin(_sample_perf);
|
||||
|
||||
int bytes_processed = 0;
|
||||
int distance_cm = -1;
|
||||
int index = 0;
|
||||
|
||||
float distance_m = -1.0f;
|
||||
|
||||
bool checksum_passed = false;
|
||||
|
||||
// Read from the sensor UART buffer.
|
||||
const hrt_abstime timestamp_sample = hrt_absolute_time();
|
||||
int bytes_read = ::read(_file_descriptor, &_buffer[0], sizeof(_buffer));
|
||||
|
||||
if (bytes_read > 0) {
|
||||
index = bytes_read - 6;
|
||||
|
||||
while (index >= 0 && !checksum_passed) {
|
||||
if (_buffer[index] == UPATCH_PACKET_HDR) {
|
||||
bytes_processed = index;
|
||||
|
||||
while (bytes_processed < bytes_read && !checksum_passed) {
|
||||
if (UPATCH_VERSION == 1) {
|
||||
uint8_t checksum_value = (_buffer[index + 1] + _buffer[index + 2] + _buffer[index + 3] + _buffer[index + 4]) & 0xFF;
|
||||
uint8_t checksum_byte = _buffer[index + 5];
|
||||
|
||||
if (checksum_value == checksum_byte) {
|
||||
checksum_passed = true;
|
||||
distance_cm = (_buffer[index + 3] << 8) | _buffer[index + 2];
|
||||
distance_m = static_cast<float>(distance_cm) / 100.f;
|
||||
}
|
||||
|
||||
} else {
|
||||
checksum_passed = true;
|
||||
distance_cm = (_buffer[index + 1] & 0x7F);
|
||||
distance_cm += ((_buffer[index + 2] & 0x7F) << 7);
|
||||
distance_m = static_cast<float>(distance_cm) * 0.045f;
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_processed++;
|
||||
}
|
||||
}
|
||||
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!checksum_passed) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
_px4_rangefinder.update(timestamp_sample, distance_m);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int AerotennaUPatch::open_serial_port(const speed_t speed)
|
||||
{
|
||||
// File descriptor initialized?
|
||||
if (_file_descriptor > 0) {
|
||||
PX4_DEBUG("serial port already open");
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
// Configure port flags for read/write, non-controlling, non-blocking.
|
||||
int flags = (O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
|
||||
// Open the serial port.
|
||||
_file_descriptor = ::open(_port, flags);
|
||||
|
||||
if (_file_descriptor < 0) {
|
||||
PX4_ERR("open failed (%i)", errno);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
if (!isatty(_file_descriptor)) {
|
||||
PX4_WARN("not a serial device");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
termios uart_config{};
|
||||
|
||||
// Store the current port configuration. attributes.
|
||||
tcgetattr(_file_descriptor, &uart_config);
|
||||
|
||||
uart_config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
|
||||
|
||||
// Clear ONLCR flag (which appends a CR for every LF).
|
||||
uart_config.c_oflag &= ~ONLCR;
|
||||
|
||||
// No parity, one stop bit.
|
||||
uart_config.c_cflag &= ~(CSTOPB | PARENB);
|
||||
|
||||
// No line processing - echo off, echo newline off, canonical mode off, extended input processing off, signal chars off
|
||||
uart_config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
|
||||
|
||||
// Set the input baud rate in the uart_config struct.
|
||||
int termios_state = cfsetispeed(&uart_config, speed);
|
||||
|
||||
if (termios_state < 0) {
|
||||
PX4_ERR("CFG: %d ISPD", termios_state);
|
||||
::close(_file_descriptor);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
// Set the output baud rate in the uart_config struct.
|
||||
termios_state = cfsetospeed(&uart_config, speed);
|
||||
|
||||
if (termios_state < 0) {
|
||||
PX4_ERR("CFG: %d OSPD", termios_state);
|
||||
::close(_file_descriptor);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
// Apply the modified port attributes.
|
||||
termios_state = tcsetattr(_file_descriptor, TCSANOW, &uart_config);
|
||||
|
||||
if (termios_state < 0) {
|
||||
PX4_ERR("baud %d ATTR", termios_state);
|
||||
::close(_file_descriptor);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
PX4_INFO("successfully opened UART port %s", _port);
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
void AerotennaUPatch::Run()
|
||||
{
|
||||
// Ensure the serial port is open.
|
||||
open_serial_port();
|
||||
|
||||
collect();
|
||||
}
|
||||
|
||||
void AerotennaUPatch::start()
|
||||
{
|
||||
// Schedule the driver at regular intervals.
|
||||
ScheduleOnInterval(UPATCH_MEASURE_INTERVAL, 0);
|
||||
}
|
||||
|
||||
void AerotennaUPatch::stop()
|
||||
{
|
||||
// Ensure the serial port is closed.
|
||||
::close(_file_descriptor);
|
||||
|
||||
// Clear the work queue schedule.
|
||||
ScheduleClear();
|
||||
}
|
||||
|
||||
void AerotennaUPatch::print_info()
|
||||
{
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
}
|
||||
120
src/drivers/distance_sensor/upatch_radar/AerotennaUPatch.hpp
Normal file
120
src/drivers/distance_sensor/upatch_radar/AerotennaUPatch.hpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2016-2020 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file AerotennaUPatch.hpp
|
||||
* @author wp <wp@uav.com>
|
||||
*
|
||||
* Driver for the UPATCH radar from Aerotenna
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <lib/drivers/rangefinder/PX4Rangefinder.hpp>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
#define UPATCH_MEASURE_INTERVAL 10_ms
|
||||
#define UPATCH_MAX_DISTANCE 50.0f
|
||||
#define UPATCH_MIN_DISTANCE 0.315f
|
||||
#define UPATCH_VERSION 1
|
||||
|
||||
#if UPATCH_VERSION == 1
|
||||
#define UPATCH_PACKET_HDR 254
|
||||
#define UPATCH_BUFFER_LENGTH 18
|
||||
#else
|
||||
#define UPATCH_PACKET_HDR 72
|
||||
#define UPATCH_BUFFER_LENGTH 9
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Assume standard deviation to be equal to sensor resolution.
|
||||
* Static bench tests have shown that the sensor ouput does
|
||||
* not vary if the unit is not moved.
|
||||
*/
|
||||
#define SENS_VARIANCE 0.045f * 0.045f
|
||||
|
||||
class AerotennaUPatch : public px4::ScheduledWorkItem
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param port The serial port to open for communicating with the sensor.
|
||||
* @param rotation The sensor rotation relative to the vehicle body.
|
||||
*/
|
||||
AerotennaUPatch(const char *port, uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
|
||||
~AerotennaUPatch() override;
|
||||
|
||||
int init();
|
||||
void print_info();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Reads data from serial UART and places it into a buffer.
|
||||
*/
|
||||
int collect();
|
||||
|
||||
/**
|
||||
* Opens and configures the UART serial communications port.
|
||||
* @param speed The baudrate (speed) to configure the serial UART port.
|
||||
*/
|
||||
int open_serial_port(const speed_t speed = B115200);
|
||||
|
||||
void Run() override;
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
PX4Rangefinder _px4_rangefinder;
|
||||
|
||||
char _port[20] {};
|
||||
|
||||
int _file_descriptor{-1};
|
||||
|
||||
uint8_t _buffer[UPATCH_BUFFER_LENGTH] {};
|
||||
|
||||
perf_counter_t _comms_errors{perf_alloc(PC_COUNT, MODULE_NAME": com_err")};
|
||||
perf_counter_t _sample_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": read")};
|
||||
|
||||
};
|
||||
45
src/drivers/distance_sensor/upatch_radar/CMakeLists.txt
Normal file
45
src/drivers/distance_sensor/upatch_radar/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2016-2020 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.
|
||||
#
|
||||
############################################################################
|
||||
px4_add_module(
|
||||
MODULE drivers__distance_sensor__upatch_radar
|
||||
MAIN upatch_radar
|
||||
SRCS
|
||||
AerotennaUPatch.cpp
|
||||
AerotennaUPatch.hpp
|
||||
upatch_radar_main.cpp
|
||||
MODULE_CONFIG
|
||||
module.yaml
|
||||
DEPENDS
|
||||
drivers_rangefinder
|
||||
px4_work_queue
|
||||
)
|
||||
6
src/drivers/distance_sensor/upatch_radar/module.yaml
Normal file
6
src/drivers/distance_sensor/upatch_radar/module.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
module_name: uPatch Radar
|
||||
serial_config:
|
||||
- command: upatch_radar start ${SERIAL_DEV}
|
||||
port_config_param:
|
||||
name: SENS_UPATCH_CFG
|
||||
group: Sensors
|
||||
49
src/drivers/distance_sensor/upatch_radar/parameters.c
Normal file
49
src/drivers/distance_sensor/upatch_radar/parameters.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-10-26 13:21:09
|
||||
* @LastEditTime: 2021-10-26 14:39:59
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /PX4-Autopilot/src/drivers/distance_sensor/upatch_radar/parameters.c
|
||||
*/
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
// /**
|
||||
// * upatch param cfg
|
||||
// *
|
||||
// * @reboot_required true
|
||||
// * @group Sensors
|
||||
// * @boolean
|
||||
// */
|
||||
// PARAM_DEFINE_INT32(SENS_UPATCH_CFG, 0);
|
||||
164
src/drivers/distance_sensor/upatch_radar/upatch_radar_main.cpp
Normal file
164
src/drivers/distance_sensor/upatch_radar/upatch_radar_main.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2016-2020 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "AerotennaUPatch.hpp"
|
||||
|
||||
#include <px4_platform_common/getopt.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
|
||||
namespace upatch_radar
|
||||
{
|
||||
|
||||
AerotennaUPatch *g_dev{nullptr};
|
||||
|
||||
static int start(const char *port, uint8_t rotation)
|
||||
{
|
||||
if (g_dev != nullptr) {
|
||||
PX4_WARN("already started");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (port == nullptr) {
|
||||
PX4_ERR("serial port required");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Instantiate the driver.
|
||||
g_dev = new AerotennaUPatch(port, rotation);
|
||||
|
||||
if (g_dev == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (g_dev->init() != PX4_OK) {
|
||||
delete g_dev;
|
||||
g_dev = nullptr;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stop()
|
||||
{
|
||||
if (g_dev != nullptr) {
|
||||
delete g_dev;
|
||||
g_dev = nullptr;
|
||||
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int status()
|
||||
{
|
||||
if (g_dev == nullptr) {
|
||||
PX4_ERR("driver not running");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_dev->print_info();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usage()
|
||||
{
|
||||
PRINT_MODULE_DESCRIPTION(
|
||||
R"DESCR_STR(
|
||||
### Description
|
||||
|
||||
Serial bus driver for the Aerotenna upatch radar.
|
||||
|
||||
Setup/usage information: https://docs.px4.io/v1.9.0/en/sensor/upatch_radar.html
|
||||
|
||||
### Examples
|
||||
|
||||
Attempt to start driver on a specified serial device.
|
||||
$ upatch_radar start -d /dev/ttyS1
|
||||
Stop driver
|
||||
$ upatch_radar stop
|
||||
)DESCR_STR");
|
||||
|
||||
PRINT_MODULE_USAGE_NAME("upatch_radar", "driver");
|
||||
PRINT_MODULE_USAGE_SUBCATEGORY("distance_sensor");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("start", "Start driver");
|
||||
PRINT_MODULE_USAGE_PARAM_STRING('d', "/dev/ttyS3", "<file:dev>", "Serial device", false);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 0, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("stop", "Stop driver");
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
} // namespace upatch_radar
|
||||
|
||||
extern "C" __EXPORT int upatch_radar_main(int argc, char *argv[])
|
||||
{
|
||||
uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
const char *device_path = nullptr;
|
||||
int ch;
|
||||
int myoptind = 1;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
while ((ch = px4_getopt(argc, argv, "R:d:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
rotation = (uint8_t)atoi(myoptarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
device_path = myoptarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
return upatch_radar::usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (myoptind >= argc) {
|
||||
return upatch_radar::usage();
|
||||
}
|
||||
|
||||
if (!strcmp(argv[myoptind], "start")) {
|
||||
return upatch_radar::start(device_path, rotation);
|
||||
|
||||
} else if (!strcmp(argv[myoptind], "stop")) {
|
||||
return upatch_radar::stop();
|
||||
|
||||
} else if (!strcmp(argv[myoptind], "status")) {
|
||||
return upatch_radar::status();
|
||||
}
|
||||
|
||||
return upatch_radar::usage();
|
||||
}
|
||||
@@ -195,6 +195,8 @@
|
||||
|
||||
#define DRV_GPS_DEVTYPE_SIM 0xAF
|
||||
|
||||
#define DRV_DIST_DEVTYPE_UPATCH 0xB0
|
||||
|
||||
|
||||
#define DRV_DEVTYPE_UNUSED 0xff
|
||||
|
||||
|
||||
Reference in New Issue
Block a user