Add camera trigger pwm params

Fix math::constrain usage

Fix second constraint
This commit is contained in:
Hamish Willee 2018-11-13 22:00:25 -08:00 committed by Beat Küng
parent e77c2cdfab
commit 68148c5fb4
2 changed files with 39 additions and 4 deletions

View File

@ -139,3 +139,29 @@ PARAM_DEFINE_INT32(TRIG_PINS, 56);
* @group Camera trigger
*/
PARAM_DEFINE_FLOAT(TRIG_DISTANCE, 25.0f);
/**
* PWM output to trigger shot.
*
* @reboot_required true
*
* @min 1000
* @max 2000
* @unit us
* @group Camera trigger
* @reboot_required true
*/
PARAM_DEFINE_INT32(TRIG_PWM_SHOOT, 1900);
/**
* PWM neutral output on trigger pin.
*
* @min 1000
* @max 2000
* @unit us
* @group Camera trigger
* @reboot_required true
*/
PARAM_DEFINE_INT32(TRIG_PWM_NEUTRAL, 1500);

View File

@ -2,13 +2,22 @@
#include <sys/ioctl.h>
#include <lib/mathlib/mathlib.h>
#include <parameters/param.h>
#include "drivers/drv_pwm_trigger.h"
#include "pwm.h"
// TODO : make these parameters later
#define PWM_CAMERA_SHOOT 1900
#define PWM_CAMERA_NEUTRAL 1500
//#define PWM_CAMERA_SHOOT 1900
//#define PWM_CAMERA_NEUTRAL 1500
int32_t pwm_camera_shoot = 0;
param_get(param_find("TRIG_PWM_SHOOT"), &pwm_camera_shoot);
int32_t pwm_camera_neutral = 0;
param_get(param_find("TRIG_PWM_NEUTRAL"), &pwm_camera_neutral);
CameraInterfacePWM::CameraInterfacePWM():
CameraInterface()
@ -40,7 +49,7 @@ void CameraInterfacePWM::setup()
// Set neutral pulsewidths
for (unsigned i = 0; i < arraySize(_pins); i++) {
if (_pins[i] >= 0) {
up_pwm_trigger_set(_pins[i], math::constrain(PWM_CAMERA_NEUTRAL, PWM_CAMERA_NEUTRAL, 2000));
up_pwm_trigger_set(_pins[i], math::constrain(pwm_camera_neutral, 0, 2000));
}
}
@ -51,7 +60,7 @@ void CameraInterfacePWM::trigger(bool trigger_on_true)
for (unsigned i = 0; i < arraySize(_pins); i++) {
if (_pins[i] >= 0) {
// Set all valid pins to shoot or neutral levels
up_pwm_trigger_set(_pins[i], math::constrain(trigger_on_true ? PWM_CAMERA_SHOOT : PWM_CAMERA_NEUTRAL, 1000, 2000));
up_pwm_trigger_set(_pins[i], math::constrain(trigger_on_true ? pwm_camera_shoot : pwm_camera_neutral, 0, 2000));
}
}
}