CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Camera/AP_Camera_Relay.cpp
Views: 1798
1
#include "AP_Camera_Relay.h"
2
3
#if AP_CAMERA_RELAY_ENABLED
4
5
#include <AP_Relay/AP_Relay.h>
6
7
// update - should be called at 50hz
8
void AP_Camera_Relay::update()
9
{
10
if (trigger_counter > 0) {
11
trigger_counter--;
12
} else {
13
AP_Relay *ap_relay = AP::relay();
14
if (ap_relay == nullptr) {
15
return;
16
}
17
ap_relay->set(AP_Relay_Params::FUNCTION::CAMERA, !_params.relay_on);
18
}
19
20
// call parent update
21
AP_Camera_Backend::update();
22
}
23
24
// entry point to actually take a picture. returns true on success
25
bool AP_Camera_Relay::trigger_pic()
26
{
27
// fail if have not completed previous picture
28
if (trigger_counter > 0) {
29
return false;
30
}
31
32
// exit immediately if no relay is setup
33
AP_Relay *ap_relay = AP::relay();
34
if (ap_relay == nullptr) {
35
return false;
36
}
37
38
ap_relay->set(AP_Relay_Params::FUNCTION::CAMERA, _params.relay_on);
39
40
// set counter to move servo to off position after this many iterations of update (assumes 50hz update rate)
41
trigger_counter = constrain_float(_params.trigger_duration * 50, 0, UINT16_MAX);
42
43
return true;
44
}
45
46
#endif // AP_CAMERA_RELAY_ENABLED
47
48