mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 15:38:52 +08:00
camera_capture: use up_input_capture_set directly
It reserves the channel and pwm_out will not use it
This commit is contained in:
@@ -36,5 +36,7 @@ px4_add_module(
|
||||
COMPILE_FLAGS
|
||||
SRCS
|
||||
camera_capture.cpp
|
||||
DEPENDS
|
||||
arch_io_pins
|
||||
)
|
||||
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
|
||||
#define commandParamToInt(n) static_cast<int>(n >= 0 ? n + 0.5f : n - 0.5f)
|
||||
|
||||
static constexpr int capture_channel = 5; ///< FMU output 6
|
||||
|
||||
namespace camera_capture
|
||||
{
|
||||
CameraCapture *g_camera_capture{nullptr};
|
||||
@@ -216,63 +218,27 @@ CameraCapture::set_capture_control(bool enabled)
|
||||
|
||||
#else
|
||||
|
||||
int fd = ::open(PX4FMU_DEVICE_PATH, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
PX4_ERR("open fail");
|
||||
return;
|
||||
}
|
||||
|
||||
input_capture_config_t conf;
|
||||
conf.channel = 5; // FMU chan 6
|
||||
conf.filter = 0;
|
||||
|
||||
if (_camera_capture_mode == 0) {
|
||||
conf.edge = _camera_capture_edge ? Rising : Falling;
|
||||
|
||||
} else {
|
||||
conf.edge = Both;
|
||||
}
|
||||
|
||||
conf.callback = nullptr;
|
||||
conf.context = nullptr;
|
||||
capture_callback_t callback = nullptr;
|
||||
void *context = nullptr;
|
||||
|
||||
if (enabled) {
|
||||
|
||||
conf.callback = &CameraCapture::capture_trampoline;
|
||||
conf.context = this;
|
||||
|
||||
unsigned int capture_count = 0;
|
||||
|
||||
if (::ioctl(fd, INPUT_CAP_GET_COUNT, (unsigned long)&capture_count) != 0) {
|
||||
PX4_INFO("Not in a capture mode");
|
||||
|
||||
unsigned long mode = PWM_SERVO_MODE_4PWM2CAP;
|
||||
|
||||
if (::ioctl(fd, PWM_SERVO_SET_MODE, mode) == 0) {
|
||||
PX4_INFO("Mode changed to 4PWM2CAP");
|
||||
|
||||
} else {
|
||||
PX4_ERR("Mode NOT changed to 4PWM2CAP!");
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
callback = &CameraCapture::capture_trampoline;
|
||||
context = this;
|
||||
}
|
||||
|
||||
if (::ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) {
|
||||
int ret = up_input_capture_set_callback(capture_channel, callback, context);
|
||||
|
||||
if (ret == 0) {
|
||||
_capture_enabled = enabled;
|
||||
_gpio_capture = false;
|
||||
|
||||
} else {
|
||||
PX4_ERR("Unable to set capture callback for chan %" PRIu8 "\n", conf.channel);
|
||||
PX4_ERR("Unable to set capture callback for chan %" PRIu8 " (%i)", capture_channel, ret);
|
||||
_capture_enabled = false;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
reset_statistics(false);
|
||||
|
||||
err_out:
|
||||
::close(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -292,6 +258,22 @@ CameraCapture::reset_statistics(bool reset_seq)
|
||||
int
|
||||
CameraCapture::start()
|
||||
{
|
||||
#if !defined(BOARD_CAPTURE_GPIO)
|
||||
input_capture_edge edge = Both;
|
||||
|
||||
if (_camera_capture_mode == 0) {
|
||||
edge = _camera_capture_edge ? Rising : Falling;
|
||||
}
|
||||
|
||||
int ret = up_input_capture_set(capture_channel, edge, 0, nullptr, nullptr);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("up_input_capture_set failed (%i)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// run every 100 ms (10 Hz)
|
||||
ScheduleOnInterval(100000, 10000);
|
||||
|
||||
@@ -329,6 +311,26 @@ CameraCapture::status()
|
||||
}
|
||||
|
||||
PX4_INFO("Number of overflows : %" PRIu32, _capture_overflows);
|
||||
|
||||
#if !defined(BOARD_CAPTURE_GPIO)
|
||||
input_capture_stats_t stats;
|
||||
int ret = up_input_capture_get_stats(capture_channel, &stats, false);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("Unable to get stats for chan %" PRIu8 " (%i)", capture_channel, ret);
|
||||
|
||||
} else {
|
||||
PX4_INFO("Status chan: %" PRIu8 " edges: %" PRIu32 " last time: %" PRIu64 " last state: %" PRIu32
|
||||
" overflows: %" PRIu32 " latency: %" PRIu16,
|
||||
capture_channel,
|
||||
stats.edges,
|
||||
stats.last_time,
|
||||
stats.last_edge,
|
||||
stats.overflows,
|
||||
stats.latency);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static int usage()
|
||||
|
||||
@@ -54,9 +54,6 @@
|
||||
#include <uORB/topics/vehicle_command.h>
|
||||
#include <uORB/topics/vehicle_command_ack.h>
|
||||
|
||||
#define PX4FMU_DEVICE_PATH "/dev/px4fmu"
|
||||
|
||||
|
||||
class CameraCapture : public px4::ScheduledWorkItem
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user