WPILibC++  2020.3.2-60-g3011ebe
Joystick.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <array>
11 
12 #include <wpi/deprecated.h>
13 
14 #include "frc/GenericHID.h"
15 
16 namespace frc {
17 
26 class Joystick : public GenericHID {
27  public:
28  static constexpr int kDefaultXChannel = 0;
29  static constexpr int kDefaultYChannel = 1;
30  static constexpr int kDefaultZChannel = 2;
31  static constexpr int kDefaultTwistChannel = 2;
32  static constexpr int kDefaultThrottleChannel = 3;
33 
34  enum AxisType { kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis };
35  enum ButtonType { kTriggerButton, kTopButton };
36 
45  explicit Joystick(int port);
46 
47  virtual ~Joystick() = default;
48 
49  Joystick(Joystick&&) = default;
50  Joystick& operator=(Joystick&&) = default;
51 
57  void SetXChannel(int channel);
58 
65  void SetYChannel(int channel);
66 
73  void SetZChannel(int channel);
74 
81  void SetTwistChannel(int channel);
82 
89  void SetThrottleChannel(int channel);
90 
96  int GetXChannel() const;
97 
103  int GetYChannel() const;
104 
110  int GetZChannel() const;
111 
117  int GetTwistChannel() const;
118 
124  int GetThrottleChannel() const;
125 
134  double GetX(JoystickHand hand = kRightHand) const override;
135 
144  double GetY(JoystickHand hand = kRightHand) const override;
145 
151  double GetZ() const;
152 
158  double GetTwist() const;
159 
165  double GetThrottle() const;
166 
174  bool GetTrigger() const;
175 
181  bool GetTriggerPressed();
182 
188  bool GetTriggerReleased();
189 
197  bool GetTop() const;
198 
204  bool GetTopPressed();
205 
211  bool GetTopReleased();
212 
219  double GetMagnitude() const;
220 
227  double GetDirectionRadians() const;
228 
235  double GetDirectionDegrees() const;
236 
237  private:
238  enum Axis { kX, kY, kZ, kTwist, kThrottle, kNumAxes };
239  enum Button { kTrigger = 1, kTop = 2 };
240 
241  std::array<int, Axis::kNumAxes> m_axes;
242 };
243 
244 } // namespace frc
frc::Joystick::GetTwist
double GetTwist() const
Get the twist value of the current joystick.
frc::Joystick::GetTwistChannel
int GetTwistChannel() const
Get the channel currently associated with the twist axis.
frc::Joystick::SetZChannel
void SetZChannel(int channel)
Set the channel associated with the Z axis.
frc::Joystick::GetThrottle
double GetThrottle() const
Get the throttle value of the current joystick.
frc::Joystick::GetY
double GetY(JoystickHand hand=kRightHand) const override
Get the Y value of the joystick.
frc::Joystick::GetTrigger
bool GetTrigger() const
Read the state of the trigger on the joystick.
frc::Joystick::SetTwistChannel
void SetTwistChannel(int channel)
Set the channel associated with the twist axis.
frc::Joystick::GetX
double GetX(JoystickHand hand=kRightHand) const override
Get the X value of the joystick.
frc::Joystick::GetDirectionDegrees
double GetDirectionDegrees() const
Get the direction of the vector formed by the joystick and its origin in degrees.
frc::Joystick::GetTopPressed
bool GetTopPressed()
Whether the top button was pressed since the last check.
frc::Joystick::GetYChannel
int GetYChannel() const
Get the channel currently associated with the Y axis.
frc::Joystick::GetTop
bool GetTop() const
Read the state of the top button on the joystick.
frc::Joystick::GetTopReleased
bool GetTopReleased()
Whether the top button was released since the last check.
frc::Joystick::GetZ
double GetZ() const
Get the Z value of the current joystick.
frc::Joystick::GetMagnitude
double GetMagnitude() const
Get the magnitude of the direction vector formed by the joystick's current position relative to its o...
frc::Joystick::GetZChannel
int GetZChannel() const
Get the channel currently associated with the Z axis.
frc::Joystick
Handle input from standard Joysticks connected to the Driver Station.
Definition: Joystick.h:26
frc::Joystick::GetDirectionRadians
double GetDirectionRadians() const
Get the direction of the vector formed by the joystick and its origin in radians.
frc::Joystick::GetTriggerPressed
bool GetTriggerPressed()
Whether the trigger was pressed since the last check.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::Joystick::SetXChannel
void SetXChannel(int channel)
Set the channel associated with the X axis.
frc::Joystick::GetThrottleChannel
int GetThrottleChannel() const
Get the channel currently associated with the throttle axis.
frc::Joystick::SetYChannel
void SetYChannel(int channel)
Set the channel associated with the Y axis.
frc::Joystick::GetTriggerReleased
bool GetTriggerReleased()
Whether the trigger was released since the last check.
frc::Joystick::GetXChannel
int GetXChannel() const
Get the channel currently associated with the X axis.
frc::GenericHID
GenericHID Interface.
Definition: GenericHID.h:23
frc::Joystick::Joystick
Joystick(int port)
Construct an instance of a joystick.
frc::Joystick::SetThrottleChannel
void SetThrottleChannel(int channel)
Set the channel associated with the throttle axis.