-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurret.cpp
95 lines (74 loc) · 1.78 KB
/
Turret.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* \file
* \brief Turret class implementation.
* \author Vasiliy Polyakov <[email protected]>
* \author RobotPSU https://robot.psu.ru/
* \date 2017-2018
*/
#include "Turret.h"
Turret::Turret() {
_pinLaser = 0;
_h = h0 = TURRET_START_H;
_v = v0 = TURRET_START_V;
_dH = TURRET_DELTA_H;
_dV = TURRET_DELTA_V;
_minH = TURRET_MIN_H; _maxH = TURRET_MAX_H;
_minV = TURRET_MIN_V; _maxV = TURRET_MAX_V;
_enabled = true;
}
void Turret::setRange(uint8_t minH, uint8_t maxH, uint8_t minV, uint8_t maxV) {
_minH = minH; _maxH = maxH;
_minV = minV; _maxV = maxV;
}
void Turret::setDelta(uint8_t dH, uint8_t dV) {
_dH = dH;
_dV = dV;
}
void Turret::attach(uint8_t pinLaser) {
pinMode(_pinLaser = pinLaser, OUTPUT);
}
void Turret::attach(uint8_t pinLaser, uint8_t pinH, uint8_t pinV) {
attach(pinLaser);
_servoH.attach(pinH);
_servoV.attach(pinV);
}
void Turret::enable() {
_enabled = true;
}
void Turret::disable() {
_enabled = false;
}
uint8_t Turret::getH() {
return _servoH.read();
}
uint8_t Turret::getV() {
return _servoV.read();
}
void Turret::reset() {
if (_servoH.attached() && _servoV.attached()) {
_servoH.write(_h = h0);
_servoV.write(_v = v0);
}
}
void Turret::up() {
if (_enabled && _servoV.attached() && _v < _maxV)
_servoV.write(_v += _dV);
}
void Turret::down() {
if (_enabled && _servoV.attached() && _v > _minV)
_servoV.write(_v -= _dV);
}
void Turret::left() {
if (_enabled && _servoH.attached() && _h < _maxH)
_servoH.write(_h += _dH);
}
void Turret::right() {
if (_enabled && _servoH.attached() && _h > _minH)
_servoH.write(_h -= _dH);
}
void Turret::impulse(unsigned long length) {
digitalWrite(_pinLaser, HIGH);
delay(length);
digitalWrite(_pinLaser, LOW);
}
/* vim: set ft=arduino et sw=2 ts=2: */