|
|
|
@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
|
|
|
|
|
#include <sys/ioctl.h> |
|
|
|
|
#include <lib/mathlib/mathlib.h> |
|
|
|
|
|
|
|
|
|
#include <uORB/topics/trigger_pwm.h> |
|
|
|
|
#include "drivers/drv_pwm_output.h" |
|
|
|
|
#include "pwm.h" |
|
|
|
|
|
|
|
|
@ -18,6 +19,7 @@
@@ -18,6 +19,7 @@
|
|
|
|
|
|
|
|
|
|
CameraInterfacePWM::CameraInterfacePWM(): |
|
|
|
|
CameraInterface(), |
|
|
|
|
_pwm_pub {nullptr, nullptr}, |
|
|
|
|
_camera_is_on(false) |
|
|
|
|
{ |
|
|
|
|
_p_pin = param_find("TRIG_PINS"); |
|
|
|
@ -34,17 +36,24 @@ CameraInterfacePWM::CameraInterfacePWM():
@@ -34,17 +36,24 @@ CameraInterfacePWM::CameraInterfacePWM():
|
|
|
|
|
int single_pin; |
|
|
|
|
|
|
|
|
|
while ((single_pin = pin_list % 10)) { |
|
|
|
|
|
|
|
|
|
_pins[i] = single_pin - 1; |
|
|
|
|
|
|
|
|
|
if (_pins[i] < 0) { |
|
|
|
|
_pins[i] = -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wingtra safety check, pins can only be on 5 or 6!!!
|
|
|
|
|
if (_pins[i] != 4 && _pins[i] != 5) { |
|
|
|
|
_pins[i] = -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pin_list /= 10; |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_orb_id[0] = 0; |
|
|
|
|
_orb_id[1] = 1; |
|
|
|
|
|
|
|
|
|
setup(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -63,6 +72,13 @@ void CameraInterfacePWM::setup()
@@ -63,6 +72,13 @@ void CameraInterfacePWM::setup()
|
|
|
|
|
up_pwm_servo_init(pin_bitmask); |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_DISARMED, PWM_CAMERA_DISARMED, 2000)); |
|
|
|
|
up_pwm_servo_set(_pins[i], math::constrain(PWM_CAMERA_DISARMED, PWM_CAMERA_DISARMED, 2000)); |
|
|
|
|
|
|
|
|
|
trigger_pwm_s pwm; |
|
|
|
|
pwm.timestamp = hrt_absolute_time(); |
|
|
|
|
pwm.pwm = PWM_CAMERA_DISARMED; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[1]), &pwm, &(_orb_id[1]), ORB_PRIO_DEFAULT); |
|
|
|
|
pwm.pwm = PWM_CAMERA_DISARMED; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[0]), &pwm, &(_orb_id[0]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -72,17 +88,21 @@ void CameraInterfacePWM::trigger(bool enable)
@@ -72,17 +88,21 @@ void CameraInterfacePWM::trigger(bool enable)
|
|
|
|
|
// This only starts working upon prearming
|
|
|
|
|
|
|
|
|
|
if (!_camera_is_on) { |
|
|
|
|
// (TODO: powerOn does not work yet)
|
|
|
|
|
// Turn camera on and give time to start up
|
|
|
|
|
// powerOn();
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trigger_pwm_s pwm; |
|
|
|
|
pwm.timestamp = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
if (enable) { |
|
|
|
|
// Set all valid pins to shoot level
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_INSTANT_SHOOT, 1000, 2000)); |
|
|
|
|
|
|
|
|
|
pwm.pwm = PWM_CAMERA_INSTANT_SHOOT; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[1]), &pwm, &(_orb_id[1]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -91,6 +111,9 @@ void CameraInterfacePWM::trigger(bool enable)
@@ -91,6 +111,9 @@ void CameraInterfacePWM::trigger(bool enable)
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000)); |
|
|
|
|
|
|
|
|
|
pwm.pwm = PWM_CAMERA_NEUTRAL; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[1]), &pwm, &(_orb_id[1]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -101,16 +124,20 @@ void CameraInterfacePWM::keep_alive(bool signal_on)
@@ -101,16 +124,20 @@ void CameraInterfacePWM::keep_alive(bool signal_on)
|
|
|
|
|
// This should alternate between signal_on and !signal_on to keep the camera alive
|
|
|
|
|
|
|
|
|
|
if (!_camera_is_on) { |
|
|
|
|
// (TODO: powerOn does not work yet)
|
|
|
|
|
// Turn camera on and give time to start up
|
|
|
|
|
powerOn(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
trigger_pwm_s pwm; |
|
|
|
|
pwm.timestamp = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
if (signal_on) { |
|
|
|
|
// Set channel 2 pin to keep_alive signal
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i], math::constrain(PWM_2_CAMERA_KEEP_ALIVE, 1000, 2000)); |
|
|
|
|
|
|
|
|
|
pwm.pwm = PWM_2_CAMERA_KEEP_ALIVE; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[0]), &pwm, &(_orb_id[0]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -119,50 +146,50 @@ void CameraInterfacePWM::keep_alive(bool signal_on)
@@ -119,50 +146,50 @@ void CameraInterfacePWM::keep_alive(bool signal_on)
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000)); |
|
|
|
|
|
|
|
|
|
pwm.pwm = PWM_CAMERA_NEUTRAL; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[0]), &pwm, &(_orb_id[0]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int CameraInterfacePWM::powerOn() |
|
|
|
|
void CameraInterfacePWM::turn_on_off(bool enable) |
|
|
|
|
{ |
|
|
|
|
// This only starts working upon prearming
|
|
|
|
|
|
|
|
|
|
// Set all valid pins to turn on level
|
|
|
|
|
// for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) {
|
|
|
|
|
// if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
|
|
|
|
|
// up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_ON, 1000, 2000));
|
|
|
|
|
// up_pwm_servo_set(_pins[i], math::constrain(PWM_2_CAMERA_ON_OFF, 1000, 2000));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// For now, set channel one on neutral upon startup.
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
trigger_pwm_s pwm; |
|
|
|
|
pwm.timestamp = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
_camera_is_on = true; |
|
|
|
|
if (enable) { |
|
|
|
|
// For now, set channel one on neutral upon startup.
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000)); |
|
|
|
|
up_pwm_servo_set(_pins[i], math::constrain(PWM_2_CAMERA_ON_OFF, 1000, 2000)); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
pwm.pwm = PWM_CAMERA_NEUTRAL; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[1]), &pwm, &(_orb_id[1]), ORB_PRIO_DEFAULT); |
|
|
|
|
pwm.pwm = PWM_2_CAMERA_ON_OFF; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[0]), &pwm, &(_orb_id[0]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int CameraInterfacePWM::powerOff() |
|
|
|
|
{ |
|
|
|
|
// This only starts working upon prearming
|
|
|
|
|
} else { |
|
|
|
|
// For now, set channel one on neutral upon startup.
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000)); |
|
|
|
|
up_pwm_servo_set(_pins[i], math::constrain(PWM_CAMERA_NEUTRAL, 1000, 2000)); |
|
|
|
|
|
|
|
|
|
// Set all valid pins to turn off level
|
|
|
|
|
for (unsigned i = 0; i < sizeof(_pins) / sizeof(_pins[0]); i = i + 2) { |
|
|
|
|
if (_pins[i] >= 0 && _pins[i + 1] >= 0) { |
|
|
|
|
up_pwm_servo_set(_pins[i + 1], math::constrain(PWM_CAMERA_OFF, 1000, 2000)); |
|
|
|
|
up_pwm_servo_set(_pins[i], math::constrain(PWM_2_CAMERA_ON_OFF, 1000, 2000)); |
|
|
|
|
pwm.pwm = PWM_CAMERA_NEUTRAL; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[1]), &pwm, &(_orb_id[1]), ORB_PRIO_DEFAULT); |
|
|
|
|
pwm.pwm = PWM_CAMERA_NEUTRAL; |
|
|
|
|
orb_publish_auto(ORB_ID(trigger_pwm), &(_pwm_pub[0]), &pwm, &(_orb_id[0]), ORB_PRIO_DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_camera_is_on = false; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
_camera_is_on = !_camera_is_on; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CameraInterfacePWM::info() |
|
|
|
|