-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcam.cpp
More file actions
61 lines (54 loc) · 2.06 KB
/
cam.cpp
File metadata and controls
61 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Alarms.h"
/************************************************************************************************************/
/**************************** Cam stabilize Servos *******************************/
#if defined(SERVO_TILT)
servo[0] = get_middle(0);
servo[1] = get_middle(1);
if (rcOptions[BOXCAMSTAB]) {
servo[0] += ((int32_t)conf.servoConf[0].rate * att.angle[PITCH]) /50L;
servo[1] += ((int32_t)conf.servoConf[1].rate * att.angle[ROLL]) /50L;
}
#endif
#ifdef SERVO_MIX_TILT
int16_t angleP = get_middle(0) - MIDRC;
int16_t angleR = get_middle(1) - MIDRC;
if (rcOptions[BOXCAMSTAB]) {
angleP += ((int32_t)conf.servoConf[0].rate * att.angle[PITCH]) /50L;
angleR += ((int32_t)conf.servoConf[1].rate * att.angle[ROLL]) /50L;
}
servo[0] = MIDRC+angleP-angleR;
servo[1] = MIDRC-angleP-angleR;
#endif
/**************** Cam trigger Servo ******************/
#if defined(CAMTRIG)
// setup MIDDLE for using as camtrig interval (in msec) or RC channel pointer for interval control
#define CAM_TIME_LOW conf.servoConf[2].middle
static uint8_t camCycle = 0;
static uint8_t camState = 0;
static uint32_t camTime = 0;
static uint32_t ctLow;
if (camCycle==1) {
if (camState == 0) {
camState = 1;
camTime = millis();
} else if (camState == 1) {
if ( (millis() - camTime) > CAM_TIME_HIGH ) {
camState = 2;
camTime = millis();
if(CAM_TIME_LOW < RC_CHANS) {
ctLow = constrain((rcData[CAM_TIME_LOW]-1000)/4, 30, 250);
ctLow *= ctLow;
} else ctLow = CAM_TIME_LOW;
}
} else { //camState ==2
if (((millis() - camTime) > ctLow) || !rcOptions[BOXCAMTRIG] ) {
camState = 0;
camCycle = 0;
}
}
}
if (rcOptions[BOXCAMTRIG]) camCycle=1;
servo[2] =(camState==1) ? conf.servoConf[2].max : conf.servoConf[2].min;
servo[2] = (servo[2]-1500)*SERVODIR(2,1)+1500;
#endif
}