forked from anidev/612-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturret.cpp
95 lines (81 loc) · 2 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
#include "turret.h"
#include "vision_alt.h"
#include "ports.h"
#include <PIDController.h>
#include <Counter.h>
#include <AnalogChannel.h>
#include "612.h"
#include "ports.h"
#include "two_jags.h"
#include "shooter.h"
#include "visionalg.h"
#include "trajectory.h"
#include <cstdlib>
turret::turret(
SpeedController& rotate,
SpeedController& winch_jag,
SpeedController& launcha,
SpeedController& launchb,
Counter& count,
AnalogChannel& pot,
DigitalInput& winch_limit,
DigitalInput& turret_left,
DigitalInput& turret_mid,
DigitalInput& turret_right)
{
lazy_susan = new turntable(rotate, turret_left, turret_mid, turret_right);
winch_obj = new winch(winch_jag, pot, winch_limit);
shooter_wheels = new shooter(count, launcha, launchb);
cur_target = NULL;
enabled = true;
}
turret::~turret() {
delete shooter_wheels;
delete winch_obj;
delete lazy_susan;
}
void turret::align(target& t) {
cur_target = &t;
}
void turret::enable() {
enabled = true;
winch_obj->enable();
shooter_wheels->enable();
lazy_susan->enable();
}
void turret::disable() {
enabled = false;
}
void turret::update_help(void * obj) {
((turret*)obj)->update();
}
void turret::update() {
if (enabled) {
if (cur_target != NULL && cur_target->valid()) {
//auto target mode
if (cur_target->fresh()) {
trajectory traj = projected_trajectory(cur_target);
lazy_susan->new_offset(cur_target->x_offset(), RESOLUTION().X()/2);
shooter_wheels->set_speed(traj.velocity, traj.angle);
winch_obj->set_angle(traj.angle);
}
}
else {
//other mode
}
}
else {
winch_obj->disable();
shooter_wheels->disable();
lazy_susan->disable();
}
}
shooter& turret::Shooter() {
return *shooter_wheels;
}
winch& turret::Winch() {
return *winch_obj;
}
turntable& turret::Susan() {
return *lazy_susan;
}