mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-11 20:59:22 +08:00
colcon build/test / build-test (push) Has been cancelled
Cygwin Build / build (push) Has been cancelled
ESP32 Build / build (esp32buzz, 10) (push) Has been cancelled
ESP32 Build / build (esp32s3empty, 10) (push) Has been cancelled
Macos Build / build (CubeOrange) (push) Has been cancelled
Macos Build / build (sitl) (push) Has been cancelled
QURT Build / build (push) Has been cancelled
test ccache / build (10, chibios) (push) Has been cancelled
test chibios / build (CubeOrange-EKF2, 10, chibios) (push) Has been cancelled
test chibios / build (CubeOrange-ODID, 10, chibios) (push) Has been cancelled
test chibios / build (CubeOrange-PPP, 10, chibios) (push) Has been cancelled
test chibios / build (CubeOrange-bootloader, 10, chibios) (push) Has been cancelled
test chibios / build (CubeRedPrimary-bootloader, 10, chibios) (push) Has been cancelled
test chibios / build (MatekF405-Wing, 10, chibios) (push) Has been cancelled
test chibios / build (Pixhawk6X-PPPGW, 10, chibios) (push) Has been cancelled
test chibios / build (SOHW, 10, chibios) (push) Has been cancelled
test chibios / build (build-options-defaults-test, 10, chibios) (push) Has been cancelled
test chibios / build (configure-all, 10, chibios) (push) Has been cancelled
test chibios / build (fmuv2-plane, 10, chibios) (push) Has been cancelled
test chibios / build (fmuv3, 10, chibios) (push) Has been cancelled
test chibios / build (fmuv3-bootloader, 10, chibios) (push) Has been cancelled
test chibios / build (iofirmware, 10, chibios) (push) Has been cancelled
test chibios / build (new-check, 10, chibios) (push) Has been cancelled
test chibios / build (periph-build, 10, chibios) (push) Has been cancelled
test chibios / build (revo-bootloader, 10, chibios) (push) Has been cancelled
test chibios / build (revo-mini, 10, chibios) (push) Has been cancelled
test chibios / build (signing, 10, chibios) (push) Has been cancelled
test chibios / build (stm32f7, 10, chibios) (push) Has been cancelled
test chibios / build (stm32h7, 10, chibios) (push) Has been cancelled
test chibios / build (stm32h7-debug, 10, chibios) (push) Has been cancelled
test dds / build (sitl) (push) Has been cancelled
test dds / build (stm32h7) (push) Has been cancelled
test Linux SBC / build (bbbmini, armhf) (push) Has been cancelled
test Linux SBC / build (bebop, armhf) (push) Has been cancelled
test Linux SBC / build (bhat, armhf) (push) Has been cancelled
test Linux SBC / build (canzero, armhf) (push) Has been cancelled
test Linux SBC / build (erlebrain2, armhf) (push) Has been cancelled
test Linux SBC / build (linux, base) (push) Has been cancelled
test Linux SBC / build (navigator, armhf-musl) (push) Has been cancelled
test Linux SBC / build (navigator64, aarch64) (push) Has been cancelled
test Linux SBC / build (navio, armhf) (push) Has been cancelled
test Linux SBC / build (navio2, armhf) (push) Has been cancelled
test Linux SBC / build (pxf, armhf) (push) Has been cancelled
test Linux SBC / build (pxfmini, armhf) (push) Has been cancelled
test replay / build (replay, base) (push) Has been cancelled
test replay / build (replay, clang) (push) Has been cancelled
test scripts / build (astyle-cleanliness) (push) Has been cancelled
test scripts / build (check_autotest_options) (push) Has been cancelled
test scripts / build (logger_metadata) (push) Has been cancelled
test scripts / build (param_parse) (push) Has been cancelled
test scripts / build (python-cleanliness) (push) Has been cancelled
test scripts / build (validate_board_list) (push) Has been cancelled
test blimp / build (base) (push) Has been cancelled
test blimp / build (clang) (push) Has been cancelled
test copter / build (base) (push) Has been cancelled
test copter / build (clang) (push) Has been cancelled
test copter / build-gcc-heli (push) Has been cancelled
test ap_periph / build-gcc-ap_periph (push) Has been cancelled
test plane / build (base) (push) Has been cancelled
test plane / build (clang) (push) Has been cancelled
test rover / build (base) (push) Has been cancelled
test rover / build (clang) (push) Has been cancelled
test sub / build (base) (push) Has been cancelled
test sub / build (clang) (push) Has been cancelled
test tracker / build (base) (push) Has been cancelled
test tracker / build (clang) (push) Has been cancelled
test unit tests and sitl building / build (examples, base) (push) Has been cancelled
test unit tests and sitl building / build (examples, clang) (push) Has been cancelled
test unit tests and sitl building / build (sitl, base) (push) Has been cancelled
test unit tests and sitl building / build (sitl, clang) (push) Has been cancelled
test unit tests and sitl building / build (unit-tests, base) (push) Has been cancelled
test unit tests and sitl building / build (unit-tests, clang) (push) Has been cancelled
test coverage / build (coverage, base, coverage) (push) Has been cancelled
test coverage / build (sitltest-can, periph) (push) Has been cancelled
test blimp / autotest (sitltest-blimp) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests1a) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests1b) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests1c) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests1d) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests1e) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests2a) (push) Has been cancelled
test copter / autotest (sitltest-copter-tests2b) (push) Has been cancelled
test copter / autotest-heli (sitltest-heli) (push) Has been cancelled
test ap_periph / autotest-can (sitltest-can) (push) Has been cancelled
test plane / autotest (sitltest-plane-tests1a) (push) Has been cancelled
test plane / autotest (sitltest-plane-tests1b) (push) Has been cancelled
test plane / autotest (sitltest-quadplane) (push) Has been cancelled
test rover / autotest (sitltest-balancebot) (push) Has been cancelled
test rover / autotest (sitltest-rover) (push) Has been cancelled
test rover / autotest (sitltest-sailboat) (push) Has been cancelled
test sub / autotest (sitltest-sub) (push) Has been cancelled
test tracker / autotest (sitltest-tracker) (push) Has been cancelled
test coverage / finish (push) Has been cancelled
test environment setup / build (bookworm, debian) (push) Has been cancelled
test environment setup / build (bullseye, debian) (push) Has been cancelled
test environment setup / build (focal, ubuntu) (push) Has been cancelled
test environment setup / build (jammy, ubuntu) (push) Has been cancelled
test environment setup / build (latest, archlinux) (push) Has been cancelled
test environment setup / build (noble, ubuntu) (push) Has been cancelled
test environment setup / build-alpine (push) Has been cancelled
173 lines
5.7 KiB
C++
173 lines
5.7 KiB
C++
/*
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "AP_OpticalFlow_config.h"
|
|
|
|
#if AP_OPTICALFLOW_ENABLED
|
|
|
|
/*
|
|
* AP_OpticalFlow.h - OpticalFlow Base Class for ArduPilot
|
|
*/
|
|
|
|
#include <AP_MSP/msp.h>
|
|
#include <AP_Math/AP_Math.h>
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
#include "AP_OpticalFlow_Calibrator.h"
|
|
|
|
class OpticalFlow_backend;
|
|
|
|
class AP_OpticalFlow
|
|
{
|
|
friend class OpticalFlow_backend;
|
|
|
|
public:
|
|
AP_OpticalFlow();
|
|
|
|
CLASS_NO_COPY(AP_OpticalFlow);
|
|
|
|
// get singleton instance
|
|
static AP_OpticalFlow *get_singleton() {
|
|
return _singleton;
|
|
}
|
|
|
|
enum class Type {
|
|
NONE = 0,
|
|
#if AP_OPTICALFLOW_PX4FLOW_ENABLED
|
|
PX4FLOW = 1,
|
|
#endif // AP_OPTICALFLOW_PX4FLOW_ENABLED
|
|
#if AP_OPTICALFLOW_PIXART_ENABLED
|
|
PIXART = 2,
|
|
#endif // AP_OPTICALFLOW_PIXART_ENABLED
|
|
#if AP_OPTICALFLOW_ONBOARD_ENABLED
|
|
BEBOP = 3,
|
|
#endif // AP_OPTICALFLOW_ONBOARD_ENABLED
|
|
#if AP_OPTICALFLOW_CXOF_ENABLED
|
|
CXOF = 4,
|
|
#endif // AP_OPTICALFLOW_CXOF_ENABLED
|
|
#if AP_OPTICALFLOW_MAV_ENABLED
|
|
MAVLINK = 5,
|
|
#endif // AP_OPTICALFLOW_MAV_ENABLED
|
|
#if AP_OPTICALFLOW_HEREFLOW_ENABLED
|
|
UAVCAN = 6,
|
|
#endif // AP_OPTICALFLOW_HEREFLOW_ENABLED
|
|
#if HAL_MSP_OPTICALFLOW_ENABLED
|
|
MSP = 7,
|
|
#endif // HAL_MSP_OPTICALFLOW_ENABLED
|
|
#if AP_OPTICALFLOW_UPFLOW_ENABLED
|
|
UPFLOW = 8,
|
|
#endif // AP_OPTICALFLOW_UPFLOW_ENABLED
|
|
#if AP_OPTICALFLOW_SITL_ENABLED
|
|
SITL = 10,
|
|
#endif // AP_OPTICALFLOW_SITL_ENABLED
|
|
};
|
|
|
|
// init - initialise sensor
|
|
void init(uint32_t log_bit);
|
|
|
|
// enabled - returns true if optical flow is enabled
|
|
bool enabled() const { return _type != Type::NONE; }
|
|
|
|
// healthy - return true if the sensor is healthy
|
|
bool healthy() const { return backend != nullptr && _flags.healthy; }
|
|
|
|
// read latest values from sensor and fill in x,y and totals.
|
|
void update(void);
|
|
|
|
// handle optical flow mavlink messages
|
|
void handle_msg(const mavlink_message_t &msg);
|
|
|
|
#if HAL_MSP_OPTICALFLOW_ENABLED
|
|
// handle optical flow msp messages
|
|
void handle_msp(const MSP::msp_opflow_data_message_t &pkt);
|
|
#endif
|
|
|
|
// quality - returns the surface quality as a measure from 0 ~ 255
|
|
uint8_t quality() const { return _state.surface_quality; }
|
|
|
|
// flowRate - returns the raw movement from the sensor in rad/s
|
|
const Vector2f& flowRate() const { return _state.flowRate; }
|
|
|
|
// bodyRate - returns the IMU-adjusted movement in rad/s
|
|
const Vector2f& bodyRate() const { return _state.bodyRate; }
|
|
|
|
// last_update() - returns system time of last sensor update
|
|
uint32_t last_update() const { return _last_update_ms; }
|
|
|
|
// get_height_override() - returns the user-specified height of sensor above ground
|
|
float get_height_override() const { return _height_override; }
|
|
|
|
struct OpticalFlow_state {
|
|
uint8_t surface_quality; // image quality (below TBD you can't trust the dx,dy values returned)
|
|
Vector2f flowRate; // optical flow angular rate in rad/sec measured about the X and Y body axis. A RH rotation about a sensor axis produces a positive rate.
|
|
Vector2f bodyRate; // body inertial angular rate in rad/sec measured about the X and Y body axis. A RH rotation about a sensor axis produces a positive rate.
|
|
};
|
|
|
|
// return a 3D vector defining the position offset of the sensors focal point in metres relative to the body frame origin
|
|
const Vector3f &get_pos_offset(void) const {
|
|
return _pos_offset;
|
|
}
|
|
|
|
// start or stop calibration
|
|
void start_calibration();
|
|
void stop_calibration();
|
|
|
|
// parameter var info table
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
private:
|
|
|
|
static AP_OpticalFlow *_singleton;
|
|
|
|
OpticalFlow_backend *backend;
|
|
|
|
struct AP_OpticalFlow_Flags {
|
|
uint8_t healthy : 1; // true if sensor is healthy
|
|
} _flags;
|
|
|
|
// parameters
|
|
AP_Enum<Type> _type; // user configurable sensor type
|
|
AP_Int16 _flowScalerX; // X axis flow scale factor correction - parts per thousand
|
|
AP_Int16 _flowScalerY; // Y axis flow scale factor correction - parts per thousand
|
|
AP_Int16 _yawAngle_cd; // yaw angle of sensor X axis with respect to vehicle X axis - centi degrees
|
|
AP_Vector3f _pos_offset; // position offset of the flow sensor in the body frame
|
|
AP_Int8 _address; // address on the bus (allows selecting between 8 possible I2C addresses for px4flow)
|
|
AP_Float _height_override; // height of the sensor above the ground. Only used in rover
|
|
|
|
// method called by backend to update frontend state:
|
|
void update_state(const OpticalFlow_state &state);
|
|
|
|
// state filled in by backend
|
|
struct OpticalFlow_state _state;
|
|
|
|
uint32_t _last_update_ms; // millis() time of last update
|
|
|
|
void Log_Write_Optflow();
|
|
uint32_t _log_bit = -1; // bitmask bit which indicates if we should log. -1 means we always log
|
|
|
|
#if AP_OPTICALFLOW_CALIBRATOR_ENABLED
|
|
// calibrator
|
|
AP_OpticalFlow_Calibrator *_calibrator;
|
|
#endif
|
|
};
|
|
|
|
namespace AP {
|
|
AP_OpticalFlow *opticalflow();
|
|
}
|
|
|
|
#include "AP_OpticalFlow_Backend.h"
|
|
|
|
#endif // AP_OPTICALFLOW_ENABLED
|