librmb 1.0
Rambunction 4330 Utility Library
Loading...
Searching...
No Matches
LogitechJoystick.h
1
2#pragma once
3
4#include <frc2/command/button/CommandGenericHID.h>
5#include <frc2/command/button/Trigger.h>
6
7namespace rmb {
8
9class LogitechJoystick : public frc2::CommandGenericHID {
10public:
11 struct Axes {
12 constexpr static int X = 1;
13 constexpr static int Y = 0;
14 constexpr static int twist = 2;
15 constexpr static int throttle = 3;
16 };
17
18 LogitechJoystick(int channel, double deadZone = 0.0,
19 bool squareOutputs = false)
20 : frc2::CommandGenericHID(channel), deadZone(deadZone),
21 squareOutputs(squareOutputs){};
22
23 double GetX() const {
24 double raw = -GetRawAxis(Axes::X);
25 if (std::abs(raw) < deadZone) {
26 return 0.0;
27 }
28 return squareOutputs ? std::copysign(raw * raw, raw) : raw;
29 }
30
31 frc2::Trigger XLessThan(double threshold) const {
32 return AxisLessThan(Axes::X, threshold);
33 }
34 frc2::Trigger XMoreThan(double threshold) const {
35 return AxisGreaterThan(Axes::X, threshold);
36 }
37
38 double GetY() const {
39 double raw = GetRawAxis(Axes::Y);
40 if (std::abs(raw) < deadZone) {
41 return 0.0;
42 }
43 return squareOutputs ? std::copysign(raw * raw, raw) : raw;
44 }
45
46 frc2::Trigger YLessThan(double threshold) const {
47 return AxisLessThan(Axes::Y, threshold);
48 }
49
50 frc2::Trigger YMoreThan(double threshold) const {
51 return AxisGreaterThan(Axes::Y, threshold);
52 }
53
54 double GetTwist() const {
55 double raw = GetRawAxis(Axes::twist);
56 if (std::abs(raw) < deadZone) {
57 return 0.0;
58 }
59 return squareOutputs ? std::copysign(raw * raw, raw) : raw;
60 }
61
62 frc2::Trigger TwistLessThan(double threshold) const {
63 return AxisLessThan(Axes::twist, threshold);
64 }
65 frc2::Trigger TwistMoreThan(double threshold) const {
66 return AxisGreaterThan(Axes::twist, threshold);
67 }
68
69 double GetThrottle() const {
70 double raw = (-GetRawAxis(Axes::throttle) + 1.0) / 2.0;
71 return raw;
72 }
73
74 frc2::Trigger ThrottleLessThan(double threshold) const {
75 return AxisLessThan(Axes::throttle, threshold);
76 }
77 frc2::Trigger ThrottleMoreThan(double threshold) const {
78 return AxisGreaterThan(Axes::throttle, threshold);
79 }
80
81 bool GetTrigger() const { return GetRawButton(1); }
82 bool GetTriggerPressed() { return GetRawButtonPressed(1); }
83 bool GetTriggerReleased() { return GetRawButtonReleased(1); }
84 frc2::Trigger Trigger() const { return Button(1); }
85
86private:
87 double deadZone;
88 bool squareOutputs;
89};
90} // namespace rmb
Definition LogitechJoystick.h:9
the master namespace of librmb
Definition LogitechGamepad.h:9
Definition LogitechJoystick.h:11