WPILibC++  unspecified
Joystick.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 <vector>
11 
12 #include <support/deprecated.h>
13 
14 #include "GenericHID.h"
15 
16 namespace frc {
17 
26 class Joystick : public GenericHID {
27  public:
28  static constexpr int kDefaultXAxis = 0;
29  static constexpr int kDefaultYAxis = 1;
30  static constexpr int kDefaultZAxis = 2;
31  static constexpr int kDefaultTwistAxis = 2;
32  static constexpr int kDefaultThrottleAxis = 3;
33  static constexpr int kMinNumAxes = 4;
34 
35  enum AxisType { kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis };
36  enum ButtonType { kTriggerButton, kTopButton };
37 
38  explicit Joystick(int port);
39  virtual ~Joystick() = default;
40 
41  Joystick(const Joystick&) = delete;
42  Joystick& operator=(const Joystick&) = delete;
43 
44  void SetXChannel(int channel);
45  void SetYChannel(int channel);
46  void SetZChannel(int channel);
47  void SetTwistChannel(int channel);
48  void SetThrottleChannel(int channel);
49 
50  WPI_DEPRECATED("Use the more specific axis channel setter functions.")
51  void SetAxisChannel(AxisType axis, int channel);
52 
53  int GetXChannel() const;
54  int GetYChannel() const;
55  int GetZChannel() const;
56  int GetTwistChannel() const;
57  int GetThrottleChannel() const;
58 
59  WPI_DEPRECATED("Use the more specific axis channel getter functions.")
60  int GetAxisChannel(AxisType axis) const;
61 
62  double GetX(JoystickHand hand = kRightHand) const override;
63  double GetY(JoystickHand hand = kRightHand) const override;
64  double GetZ() const;
65  double GetTwist() const;
66  double GetThrottle() const;
67 
68  WPI_DEPRECATED("Use the more specific axis channel getter functions.")
69  double GetAxis(AxisType axis) const;
70 
71  bool GetTrigger() const;
72  bool GetTriggerPressed();
73  bool GetTriggerReleased();
74 
75  bool GetTop() const;
76  bool GetTopPressed();
77  bool GetTopReleased();
78 
79  WPI_DEPRECATED("Use Joystick instances instead.")
80  static Joystick* GetStickForPort(int port);
81 
82  WPI_DEPRECATED("Use the more specific button getter functions.")
83  bool GetButton(ButtonType button) const;
84 
85  double GetMagnitude() const;
86  double GetDirectionRadians() const;
87  double GetDirectionDegrees() const;
88 
89  private:
90  enum class Axis { kX, kY, kZ, kTwist, kThrottle };
91  enum class Button { kTrigger = 1, kTop = 2 };
92 
93  std::vector<int> m_axes;
94 };
95 
96 } // namespace frc
Definition: Timer.cpp:18
double GetAxis(AxisType axis) const
For the current joystick, return the axis determined by the argument.
Definition: Joystick.cpp:201
double GetDirectionRadians() const
Get the direction of the vector formed by the joystick and its origin in radians. ...
Definition: Joystick.cpp:317
double GetX(JoystickHand hand=kRightHand) const override
Get the X value of the joystick.
Definition: Joystick.cpp:150
int GetTwistChannel() const
Get the channel currently associated with the twist axis.
Definition: Joystick.cpp:129
void SetTwistChannel(int channel)
Set the channel associated with the twist axis.
Definition: Joystick.cpp:89
int GetZChannel() const
Get the channel currently associated with the Z axis.
Definition: Joystick.cpp:122
int GetXChannel() const
Get the channel currently associated with the X axis.
Definition: Joystick.cpp:108
Joystick(int port)
Construct an instance of a joystick.
Definition: Joystick.cpp:33
bool GetTopReleased()
Whether the top button was released since the last check.
Definition: Joystick.cpp:273
void SetAxisChannel(AxisType axis, int channel)
Set the channel associated with a specified axis.
Definition: Joystick.cpp:50
int GetYChannel() const
Get the channel currently associated with the Y axis.
Definition: Joystick.cpp:115
void SetYChannel(int channel)
Set the channel associated with the Y axis.
Definition: Joystick.cpp:69
double GetTwist() const
Get the twist value of the current joystick.
Definition: Joystick.cpp:178
void SetXChannel(int channel)
Set the channel associated with the X axis.
Definition: Joystick.cpp:59
bool GetTopPressed()
Whether the top button was pressed since the last check.
Definition: Joystick.cpp:264
double GetThrottle() const
Get the throttle value of the current joystick.
Definition: Joystick.cpp:187
double GetDirectionDegrees() const
Get the direction of the vector formed by the joystick and its origin in degrees. ...
Definition: Joystick.cpp:330
double GetMagnitude() const
Get the magnitude of the direction vector formed by the joystick&#39;s current position relative to its o...
Definition: Joystick.cpp:307
Handle input from standard Joysticks connected to the Driver Station.
Definition: Joystick.h:26
int GetThrottleChannel() const
Get the channel currently associated with the throttle axis.
Definition: Joystick.cpp:138
void SetThrottleChannel(int channel)
Set the channel associated with the throttle axis.
Definition: Joystick.cpp:99
double GetY(JoystickHand hand=kRightHand) const override
Get the Y value of the joystick.
Definition: Joystick.cpp:162
bool GetTriggerReleased()
Whether the trigger was released since the last check.
Definition: Joystick.cpp:244
GenericHID Interface.
Definition: GenericHID.h:23
bool GetTop() const
Read the state of the top button on the joystick.
Definition: Joystick.cpp:255
bool GetTrigger() const
Read the state of the trigger on the joystick.
Definition: Joystick.cpp:226
bool GetButton(ButtonType button) const
Get buttons based on an enumerated type.
Definition: Joystick.cpp:296
bool GetTriggerPressed()
Whether the trigger was pressed since the last check.
Definition: Joystick.cpp:235
void SetZChannel(int channel)
Set the channel associated with the Z axis.
Definition: Joystick.cpp:79
double GetZ() const
Get the Z value of the current joystick.
Definition: Joystick.cpp:171