RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
POVDirection.java
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
package
org.wpilib.driverstation;
6
7
import
java.util.Optional;
8
import
org.wpilib.math.geometry.Rotation2d;
9
import
org.wpilib.system.Timer;
10
12
public
enum
POVDirection {
14
CENTER
(0x00),
16
UP
(0x01),
18
UP_RIGHT
(0x01 | 0x02),
20
RIGHT
(0x02),
22
DOWN_RIGHT
(0x02 | 0x04),
24
DOWN
(0x04),
26
DOWN_LEFT
(0x04 | 0x08),
28
LEFT
(0x08),
30
UP_LEFT
(0x01 | 0x08);
31
32
private
static
final
double
INVALID_POV_VALUE_INTERVAL = 1.0;
33
private
static
double
s_nextMessageTime;
34
42
public
static
POVDirection
of
(
byte
value
) {
43
for
(var direction : values()) {
44
if
(direction.value ==
value
) {
45
return
direction;
46
}
47
}
48
double
currentTime =
Timer
.
getTimestamp
();
49
if
(currentTime > s_nextMessageTime) {
50
DriverStationErrors
.
reportError
(
"Invalid POV value "
+
value
+
"!"
,
false
);
51
s_nextMessageTime = currentTime + INVALID_POV_VALUE_INTERVAL;
52
}
53
return
CENTER
;
54
}
55
57
public
final
byte
value
;
58
59
POVDirection(
int
value
) {
60
this.value = (byte)
value
;
61
}
62
69
public
Optional<Rotation2d>
getAngle
() {
70
return
switch
(
this
) {
71
case
CENTER
-> Optional.empty();
72
case
UP
-> Optional.of(
Rotation2d
.
fromDegrees
(0));
73
case
UP_RIGHT
-> Optional.of(
Rotation2d
.
fromDegrees
(45));
74
case
RIGHT
-> Optional.of(
Rotation2d
.
fromDegrees
(90));
75
case
DOWN_RIGHT
-> Optional.of(
Rotation2d
.
fromDegrees
(135));
76
case
DOWN
-> Optional.of(
Rotation2d
.
fromDegrees
(180));
77
case
DOWN_LEFT
-> Optional.of(
Rotation2d
.
fromDegrees
(225));
78
case
LEFT
-> Optional.of(
Rotation2d
.
fromDegrees
(270));
79
case
UP_LEFT
-> Optional.of(
Rotation2d
.
fromDegrees
(315));
80
};
81
}
82
}
org.wpilib.driverstation.DriverStationErrors
Definition
DriverStationErrors.java:10
org.wpilib.driverstation.DriverStationErrors.reportError
static void reportError(String error, boolean printTrace)
Definition
DriverStationErrors.java:19
org.wpilib.math.geometry.Rotation2d
Definition
Rotation2d.java:30
org.wpilib.math.geometry.Rotation2d.fromDegrees
static Rotation2d fromDegrees(double degrees)
Definition
Rotation2d.java:175
org.wpilib.system.Timer
Definition
Timer.java:18
org.wpilib.system.Timer.getTimestamp
static double getTimestamp()
Definition
Timer.java:26
org.wpilib.driverstation.POVDirection.getAngle
Optional< Rotation2d > getAngle()
Definition
POVDirection.java:69
org.wpilib.driverstation.POVDirection.LEFT
LEFT
Definition
POVDirection.java:28
org.wpilib.driverstation.POVDirection.DOWN_LEFT
DOWN_LEFT
Definition
POVDirection.java:26
org.wpilib.driverstation.POVDirection.UP_RIGHT
UP_RIGHT
Definition
POVDirection.java:18
org.wpilib.driverstation.POVDirection.RIGHT
RIGHT
Definition
POVDirection.java:20
org.wpilib.driverstation.POVDirection.of
static POVDirection of(byte value)
Definition
POVDirection.java:42
org.wpilib.driverstation.POVDirection.UP
UP
Definition
POVDirection.java:16
org.wpilib.driverstation.POVDirection.CENTER
CENTER
Definition
POVDirection.java:14
org.wpilib.driverstation.POVDirection.value
final byte value
Definition
POVDirection.java:57
org.wpilib.driverstation.POVDirection.DOWN
DOWN
Definition
POVDirection.java:24
org.wpilib.driverstation.POVDirection.UP_LEFT
UP_LEFT
Definition
POVDirection.java:30
org.wpilib.driverstation.POVDirection.DOWN_RIGHT
DOWN_RIGHT
Definition
POVDirection.java:22
org
wpilib
driverstation
POVDirection.java
Generated by
1.18.0