WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
POVDirection.hpp
Go to the documentation of this file.
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#pragma once
6
7#include <cstdint>
8#include <optional>
9
12
13namespace wpi {
14
15/**
16 * A controller POV direction.
17 */
18enum class POVDirection : uint8_t {
19 /// POV center.
20 CENTER = HAL_JOYSTICK_POV_CENTERED,
21 /// POV up.
22 UP = HAL_JOYSTICK_POV_UP,
23 /// POV up right.
24 UP_RIGHT = HAL_JOYSTICK_POV_RIGHT_UP,
25 /// POV right.
26 RIGHT = HAL_JOYSTICK_POV_RIGHT,
27 /// POV down right.
28 DOWN_RIGHT = HAL_JOYSTICK_POV_RIGHT_DOWN,
29 /// POV down.
30 DOWN = HAL_JOYSTICK_POV_DOWN,
31 /// POV down left.
32 DOWN_LEFT = HAL_JOYSTICK_POV_LEFT_DOWN,
33 /// POV left.
34 LEFT = HAL_JOYSTICK_POV_LEFT,
35 /// POV up left.
36 UP_LEFT = HAL_JOYSTICK_POV_LEFT_UP,
37};
38
39/**
40 * Gets the angle of a POVDirection.
41 *
42 * @param angle The POVDirection to convert.
43 * @return The angle clockwise from straight up, or std::nullopt if the
44 * POVDirection is CENTER.
45 */
46constexpr std::optional<wpi::math::Rotation2d> GetPOVAngle(POVDirection angle) {
47 using enum POVDirection;
48 switch (angle) {
49 case CENTER:
50 return std::nullopt;
51 case UP:
52 return wpi::math::Rotation2d{0_deg};
53 case UP_RIGHT:
54 return wpi::math::Rotation2d{45_deg};
55 case RIGHT:
56 return wpi::math::Rotation2d{90_deg};
57 case DOWN_RIGHT:
58 return wpi::math::Rotation2d{135_deg};
59 case DOWN:
60 return wpi::math::Rotation2d{180_deg};
61 case DOWN_LEFT:
62 return wpi::math::Rotation2d{225_deg};
63 case LEFT:
64 return wpi::math::Rotation2d{270_deg};
65 case UP_LEFT:
66 return wpi::math::Rotation2d{315_deg};
67 default:
68 return std::nullopt;
69 }
70}
71
72} // namespace wpi
A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
Definition Rotation2d.hpp:29
Definition CvSource.hpp:15
constexpr std::optional< wpi::math::Rotation2d > GetPOVAngle(POVDirection angle)
Gets the angle of a POVDirection.
Definition POVDirection.hpp:46
POVDirection
A controller POV direction.
Definition POVDirection.hpp:18
@ RIGHT
POV right.
Definition POVDirection.hpp:26
@ UP_LEFT
POV up left.
Definition POVDirection.hpp:36
@ LEFT
POV left.
Definition POVDirection.hpp:34
@ DOWN_LEFT
POV down left.
Definition POVDirection.hpp:32
@ CENTER
POV center.
Definition POVDirection.hpp:20
@ DOWN
POV down.
Definition POVDirection.hpp:30
@ DOWN_RIGHT
POV down right.
Definition POVDirection.hpp:28
@ UP_RIGHT
POV up right.
Definition POVDirection.hpp:24
@ UP
POV up.
Definition POVDirection.hpp:22