forked from Yet-Another-Software-Suite/YAGSL-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThriftyNovaEncoderSwerve.java
More file actions
116 lines (104 loc) · 2.43 KB
/
ThriftyNovaEncoderSwerve.java
File metadata and controls
116 lines (104 loc) · 2.43 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package swervelib.encoders;
import swervelib.motors.SwerveMotor;
import swervelib.motors.ThriftyNovaSwerve;
/**
* Thrifty Nova absolute encoder, attached through the data port.
*/
public class ThriftyNovaEncoderSwerve extends SwerveAbsoluteEncoder
{
/**
* The absolute encoder is directly interfaced through the Thrifty Nova motor.
*/
protected ThriftyNovaSwerve motor;
/**
* Inversion state of the attached encoder.
*/
protected boolean inverted = false;
/**
* Offset of the absolute encoder.
*/
protected double offset = 0.0;
/**
* Create the {@link ThriftyNovaEncoderSwerve} object as an absolute encoder from the {@link ThriftyNovaSwerve}
* motor.
*
* @param motor {@link SwerveMotor} through which to interface with the attached encoder .
*/
public ThriftyNovaEncoderSwerve(SwerveMotor motor)
{
this.motor = (ThriftyNovaSwerve) motor;
motor.setAbsoluteEncoder(null);
}
@Override
public void close()
{
// ThriftyNova encoder gets closed with the motor
// I don't think an encoder getting closed should
// close the entire motor so i will keep this empty
// sparkFlex.close();
}
/**
* Set factory default.
*/
@Override
public void factoryDefault()
{
}
/**
* Clear sticky faults.
*/
@Override
public void clearStickyFaults()
{
}
/**
* Configure the absolute encoder.
*
* @param inverted Whether the encoder is inverted.
*/
@Override
public void configure(boolean inverted)
{
this.inverted = inverted;
}
/**
* Get the absolute position of the encoder.
*
* @return Absolute position in degrees from [0, 360).
*/
@Override
public double getAbsolutePosition()
{
return (motor.getPosition() + offset) * (inverted ? -1.0 : 1.0);
}
/**
* Get the instantiated absolute encoder Object.
*/
@Override
public Object getAbsoluteEncoder()
{
return null;
}
/**
* Set the absolute encoder offset.
*
* @param offset offset in degrees from [0, 360).
* @return true if successful.
*/
@Override
public boolean setAbsoluteEncoderOffset(double offset)
{
this.offset = offset;
return true;
}
/**
* Get the absolute encoder velocity. WARNING: Angular velocity is generally not measurable at high speeds.
*
* @return Velocity in degrees per second.
*/
@Override
public double getVelocity()
{
return motor.getVelocity();
}
}