mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 09:58:28 -04:00
AP_Proximity: LightWareSF40C used intermediate serial class
This commit is contained in:
parent
fcdb833f46
commit
788e466c90
@ -16,7 +16,6 @@
|
|||||||
#include <AP_Common/AP_Common.h>
|
#include <AP_Common/AP_Common.h>
|
||||||
#include <AP_HAL/AP_HAL.h>
|
#include <AP_HAL/AP_HAL.h>
|
||||||
#include <AP_HAL/utility/sparse-endian.h>
|
#include <AP_HAL/utility/sparse-endian.h>
|
||||||
#include <AP_SerialManager/AP_SerialManager.h>
|
|
||||||
#include <AP_Math/crc.h>
|
#include <AP_Math/crc.h>
|
||||||
#include "AP_Proximity_LightWareSF40C.h"
|
#include "AP_Proximity_LightWareSF40C.h"
|
||||||
|
|
||||||
@ -24,30 +23,6 @@ extern const AP_HAL::HAL& hal;
|
|||||||
|
|
||||||
#define PROXIMITY_SF40C_HEADER 0xAA
|
#define PROXIMITY_SF40C_HEADER 0xAA
|
||||||
#define PROXIMITY_SF40C_DESIRED_OUTPUT_RATE 3
|
#define PROXIMITY_SF40C_DESIRED_OUTPUT_RATE 3
|
||||||
#define PROXIMITY_SF40C_UART_RX_SPACE 1280
|
|
||||||
|
|
||||||
/*
|
|
||||||
The constructor also initialises the proximity sensor. Note that this
|
|
||||||
constructor is not called until detect() returns true, so we
|
|
||||||
already know that we should setup the proximity sensor
|
|
||||||
*/
|
|
||||||
AP_Proximity_LightWareSF40C::AP_Proximity_LightWareSF40C(AP_Proximity &_frontend,
|
|
||||||
AP_Proximity::Proximity_State &_state) :
|
|
||||||
AP_Proximity_Backend(_frontend, _state)
|
|
||||||
{
|
|
||||||
const AP_SerialManager &serial_manager = AP::serialmanager();
|
|
||||||
_uart = serial_manager.find_serial(AP_SerialManager::SerialProtocol_Lidar360, 0);
|
|
||||||
if (_uart != nullptr) {
|
|
||||||
// start uart with larger receive buffer
|
|
||||||
_uart->begin(serial_manager.find_baudrate(AP_SerialManager::SerialProtocol_Lidar360, 0), PROXIMITY_SF40C_UART_RX_SPACE, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// detect if a Lightware proximity sensor is connected by looking for a configured serial port
|
|
||||||
bool AP_Proximity_LightWareSF40C::detect()
|
|
||||||
{
|
|
||||||
return AP::serialmanager().find_serial(AP_SerialManager::SerialProtocol_Lidar360, 0) != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the state of the sensor
|
// update the state of the sensor
|
||||||
void AP_Proximity_LightWareSF40C::update(void)
|
void AP_Proximity_LightWareSF40C::update(void)
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AP_Proximity.h"
|
#include "AP_Proximity.h"
|
||||||
#include "AP_Proximity_Backend.h"
|
#include "AP_Proximity_Backend_Serial.h"
|
||||||
|
|
||||||
#define PROXIMITY_SF40C_TIMEOUT_MS 200 // requests timeout after 0.2 seconds
|
#define PROXIMITY_SF40C_TIMEOUT_MS 200 // requests timeout after 0.2 seconds
|
||||||
#define PROXIMITY_SF40C_PAYLOAD_LEN_MAX 256 // maximum payload size we can accept (in some configurations sensor may send as large as 1023)
|
#define PROXIMITY_SF40C_PAYLOAD_LEN_MAX 256 // maximum payload size we can accept (in some configurations sensor may send as large as 1023)
|
||||||
#define PROXIMITY_SF40C_COMBINE_READINGS 7 // combine this many readings together to improve efficiency
|
#define PROXIMITY_SF40C_COMBINE_READINGS 7 // combine this many readings together to improve efficiency
|
||||||
|
|
||||||
class AP_Proximity_LightWareSF40C : public AP_Proximity_Backend
|
class AP_Proximity_LightWareSF40C : public AP_Proximity_Backend_Serial
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
AP_Proximity_LightWareSF40C(AP_Proximity &_frontend,
|
using AP_Proximity_Backend_Serial::AP_Proximity_Backend_Serial;
|
||||||
AP_Proximity::Proximity_State &_state);
|
|
||||||
|
|
||||||
// static detection function
|
uint16_t rxspace() const override {
|
||||||
static bool detect();
|
return 1280;
|
||||||
|
};
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
void update(void) override;
|
void update(void) override;
|
||||||
@ -105,7 +105,6 @@ private:
|
|||||||
void process_message();
|
void process_message();
|
||||||
|
|
||||||
// internal variables
|
// internal variables
|
||||||
AP_HAL::UARTDriver *_uart; // uart for communicating with sensor
|
|
||||||
uint32_t _last_request_ms; // system time of last request
|
uint32_t _last_request_ms; // system time of last request
|
||||||
uint32_t _last_reply_ms; // system time of last valid reply
|
uint32_t _last_reply_ms; // system time of last valid reply
|
||||||
uint32_t _last_restart_ms; // system time we restarted the sensor
|
uint32_t _last_restart_ms; // system time we restarted the sensor
|
||||||
|
Loading…
Reference in New Issue
Block a user