PX4 Firmware
PX4 Autopilot Software http://px4.io
seagull_map2.cpp
Go to the documentation of this file.
1 #ifdef __PX4_NUTTX
2 
3 #include <sys/ioctl.h>
4 #include <lib/mathlib/mathlib.h>
5 
7 #include "seagull_map2.h"
8 
9 // PWM levels of the interface to Seagull MAP 2 converter to
10 // Multiport (http://www.seagulluav.com/manuals/Seagull_MAP2-Manual.pdf)
11 #define PWM_CAMERA_DISARMED 900
12 #define PWM_CAMERA_NEUTRAL 1500
13 #define PWM_1_CAMERA_ON 1100
14 #define PWM_1_CAMERA_AUTOFOCUS_SHOOT 1300
15 #define PWM_1_CAMERA_INSTANT_SHOOT 1700
16 #define PWM_1_CAMERA_OFF 1900
17 #define PWM_2_CAMERA_KEEP_ALIVE 1700
18 #define PWM_2_CAMERA_ON_OFF 1900
19 
20 CameraInterfaceSeagull::CameraInterfaceSeagull():
22  _camera_is_on(false)
23 {
24  get_pins();
25  setup();
26 }
27 
28 CameraInterfaceSeagull::~CameraInterfaceSeagull()
29 {
30  // Deinitialise trigger channels
32 }
33 
34 void CameraInterfaceSeagull::setup()
35 {
36  for (unsigned i = 0; i < arraySize(_pins); i = i + 2) {
37  if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
38 
39  // Initialize the interface
40  uint8_t pin_bitmask = (1 << _pins[i + 1]) | (1 << _pins[i]);
41  up_pwm_trigger_init(pin_bitmask);
42 
43  // Set both interface pins to disarmed
44  up_pwm_trigger_set(_pins[i + 1], PWM_CAMERA_DISARMED);
45  up_pwm_trigger_set(_pins[i], PWM_CAMERA_DISARMED);
46 
47  // We only support 2 consecutive pins while using the Seagull MAP2
48  return;
49  }
50  }
51 
52  PX4_ERR("Bad pin configuration - Seagull MAP2 requires 2 consecutive pins for control.");
53 }
54 
55 void CameraInterfaceSeagull::trigger(bool trigger_on_true)
56 {
57 
58  if (!_camera_is_on) {
59  return;
60  }
61 
62  for (unsigned i = 0; i < arraySize(_pins); i = i + 2) {
63  if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
64  // Set channel 1 to shoot or neutral levels
65  up_pwm_trigger_set(_pins[i + 1], trigger_on_true ? PWM_1_CAMERA_INSTANT_SHOOT : PWM_CAMERA_NEUTRAL);
66  }
67  }
68 }
69 
70 void CameraInterfaceSeagull::send_keep_alive(bool enable)
71 {
72  // This should alternate between enable and !enable to keep the camera alive
73 
74  if (!_camera_is_on) {
75  return;
76  }
77 
78  for (unsigned i = 0; i < arraySize(_pins); i = i + 2) {
79  if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
80  // Set channel 2 pin to keep_alive or netural signal
81  up_pwm_trigger_set(_pins[i], enable ? PWM_2_CAMERA_KEEP_ALIVE : PWM_CAMERA_NEUTRAL);
82  }
83  }
84 }
85 
86 void CameraInterfaceSeagull::send_toggle_power(bool enable)
87 {
88 
89  // This should alternate between enable and !enable to toggle camera power
90 
91  for (unsigned i = 0; i < arraySize(_pins); i = i + 2) {
92  if (_pins[i] >= 0 && _pins[i + 1] >= 0) {
93  // Set channel 1 to neutral
94  up_pwm_trigger_set(_pins[i + 1], PWM_CAMERA_NEUTRAL);
95  // Set channel 2 to on_off or neutral signal
96  up_pwm_trigger_set(_pins[i], enable ? PWM_2_CAMERA_ON_OFF : PWM_CAMERA_NEUTRAL);
97  }
98  }
99 
100  if (!enable) { _camera_is_on = !_camera_is_on; }
101 }
102 
104 {
105  PX4_INFO("PWM trigger mode (Seagull MAP2) , pins enabled : [%d][%d][%d][%d][%d][%d]",
106  _pins[5], _pins[4], _pins[3], _pins[2], _pins[1], _pins[0]);
107 }
108 
109 #endif /* ifdef __PX4_NUTTX */
__EXPORT void up_pwm_trigger_deinit(void)
De-initialise the PWM trigger outputs.
int info()
Print a little info about the driver.
Interface supported cameras using a Seagull MAP2 interface.
__BEGIN_DECLS __EXPORT int up_pwm_trigger_init(uint32_t channel_mask)
Intialise the PWM servo outputs using the specified configuration.
#define arraySize(a)
__EXPORT int up_pwm_trigger_set(unsigned channel, uint16_t value)
Set the current output value for a channel.