-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurret.java
More file actions
72 lines (64 loc) · 3.08 KB
/
Turret.java
File metadata and controls
72 lines (64 loc) · 3.08 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
62
63
64
65
66
67
68
69
70
71
72
package com.nutrons.steamworks;
import com.nutrons.framework.Subsystem;
import com.nutrons.framework.controllers.Events;
import com.nutrons.framework.controllers.Talon;
import com.nutrons.framework.subsystems.WpiSmartDashboard;
import com.nutrons.framework.util.FlowOperators;
import io.reactivex.Flowable;
public class Turret implements Subsystem {
private static final double PVAL = 0.03;
private static final double IVAL = 0.0;
private static final double DVAL = 0.0;
private static final double FVAL = 0.0;
private static final double MOTOR_ROTATIONS_TO_TURRET_ROTATIONS = (double) 104 / 22;
private final Flowable<Double> angle;
private final Flowable<String> state;
private final Talon hoodMaster;
private final Flowable<Boolean> revLim;
private final Flowable<Boolean> fwdLim;
private final Flowable<Double> joyControl; //TODO: Remoove
/**
* The Turret System that is used for aiming our shooter.
*
* @param angle The flowable of doubles that is represent the angle the turret should be facing.
* @param master The talon controlling the movement of the turret.
*/
public Turret(Flowable<Double> angle, Flowable<String> state, Talon master,
Flowable<Double> joyControl) { //TODO: remove joycontrol
this.angle = angle;
this.state = state;
this.hoodMaster = master;
Events.resetPosition(0.0).actOn(this.hoodMaster);
this.revLim = FlowOperators.toFlow(this.hoodMaster::revLimitSwitchClosed);
this.fwdLim = FlowOperators.toFlow(this.hoodMaster::fwdLimitSwitchClosed);
this.joyControl = joyControl;
}
@Override
public void registerSubscriptions() {
FlowOperators.deadband(joyControl).map(x -> Events.power(x / 4))
.subscribe(hoodMaster); //TODO: remove this joystick
/*this.fwdLim.map(b -> b ?
Events.combine(Events.mode(ControlMode.MANUAL), Events.power(-0.5)) //TODO: edit these signs
: Events.combine(Events.power(0.0), Events.mode(ControlMode.LOOP_POSITION)))
.subscribe(hoodMaster);
this.revLim.map(b -> b ?
Events.combine(Events.mode(ControlMode.MANUAL), Events.power(0.5)) //TODO: edit these signs
: Events.combine(Events.power(0.0), Events.mode(ControlMode.LOOP_POSITION)))
.subscribe(hoodMaster);
**/
/*
Flowable<ControllerEvent> source = this.angle
.map(x -> x * MOTOR_ROTATIONS_TO_TURRET_ROTATIONS / 360.0)
.map(x -> Events.pid(hoodMaster.position() + x, PVAL, IVAL, DVAL, FVAL));
*/
Flowable<Double> setpoint = this.angle.map(x -> x * MOTOR_ROTATIONS_TO_TURRET_ROTATIONS / 360.0)
.map(x -> x + hoodMaster.position());
this.hoodMaster.setPID(PVAL, IVAL, DVAL, FVAL);
setpoint.subscribe(x -> Events.setpoint(x).actOn(hoodMaster));
this.angle.subscribe(new WpiSmartDashboard().getTextFieldDouble("angle"));
this.state.subscribe(new WpiSmartDashboard().getTextFieldString("state"));
this.revLim.subscribe(new WpiSmartDashboard().getTextFieldBoolean("revLim"));
this.fwdLim.subscribe(new WpiSmartDashboard().getTextFieldBoolean("fwdLim"));
setpoint.subscribe(new WpiSmartDashboard().getTextFieldDouble("setpoint"));
}
}