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 <stdint.h>
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "ErrorBase.h"
16 #include "JoystickBase.h"
17 
18 namespace frc {
19 
20 class DriverStation;
21 
29 class Joystick : public JoystickBase, public ErrorBase {
30  public:
31  static const int kDefaultXAxis = 0;
32  static const int kDefaultYAxis = 1;
33  static const int kDefaultZAxis = 2;
34  static const int kDefaultTwistAxis = 2;
35  static const int kDefaultThrottleAxis = 3;
36 
37  typedef enum {
38  kXAxis,
39  kYAxis,
40  kZAxis,
41  kTwistAxis,
42  kThrottleAxis,
43  kNumAxisTypes
44  } AxisType;
45 
46  static const int kDefaultTriggerButton = 1;
47  static const int kDefaultTopButton = 2;
48 
49  typedef enum { kTriggerButton, kTopButton, kNumButtonTypes } ButtonType;
50 
51  explicit Joystick(int port);
52  Joystick(int port, int numAxisTypes, int numButtonTypes);
53  virtual ~Joystick() = default;
54 
55  Joystick(const Joystick&) = delete;
56  Joystick& operator=(const Joystick&) = delete;
57 
58  int GetAxisChannel(AxisType axis) const;
59  void SetAxisChannel(AxisType axis, int channel);
60 
61  double GetX(JoystickHand hand = kRightHand) const override;
62  double GetY(JoystickHand hand = kRightHand) const override;
63  double GetZ(JoystickHand hand = kRightHand) const override;
64  double GetTwist() const override;
65  double GetThrottle() const override;
66  virtual double GetAxis(AxisType axis) const;
67 
68  bool GetTrigger(JoystickHand hand = kRightHand) const override;
69  bool GetTop(JoystickHand hand = kRightHand) const override;
70  bool GetButton(ButtonType button) const;
71  static Joystick* GetStickForPort(int port);
72 
73  virtual double GetMagnitude() const;
74  virtual double GetDirectionRadians() const;
75  virtual double GetDirectionDegrees() const;
76 
77  int GetAxisType(int axis) const;
78 
79  int GetAxisCount() const;
80  int GetButtonCount() const;
81 
82  private:
83  DriverStation& m_ds;
84  std::vector<int> m_axes;
85  std::vector<int> m_buttons;
86 };
87 
88 } // namespace frc
Definition: Timer.cpp:18
virtual double GetAxis(AxisType axis) const
For the current joystick, return the axis determined by the argument.
Definition: Joystick.cpp:145
virtual double GetDirectionRadians() const
Get the direction of the vector formed by the joystick and its origin in radians. ...
Definition: Joystick.cpp:267
double GetX(JoystickHand hand=kRightHand) const override
Get the X value of the joystick.
Definition: Joystick.cpp:94
bool GetTrigger(JoystickHand hand=kRightHand) const override
Read the state of the trigger on the joystick.
Definition: Joystick.cpp:172
Joystick Interface.
Definition: JoystickBase.h:17
Joystick(int port)
Construct an instance of a joystick.
Definition: Joystick.cpp:37
void SetAxisChannel(AxisType axis, int channel)
Set the channel associated with a specified axis.
Definition: Joystick.cpp:247
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:28
bool GetTop(JoystickHand hand=kRightHand) const override
Read the state of the top button on the joystick.
Definition: Joystick.cpp:185
int GetAxisType(int axis) const
Get the axis type of a joystick axis.
Definition: Joystick.cpp:220
virtual double GetDirectionDegrees() const
Get the direction of the vector formed by the joystick and its origin in degrees. ...
Definition: Joystick.cpp:280
virtual 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:257
double GetTwist() const override
Get the twist value of the current joystick.
Definition: Joystick.cpp:124
Handle input from standard Joysticks connected to the Driver Station.
Definition: Joystick.h:29
double GetThrottle() const override
Get the throttle value of the current joystick.
Definition: Joystick.cpp:131
Base class for most objects.
Definition: ErrorBase.h:74
int GetButtonCount() const
Get the number of buttons for a joystick.
Definition: Joystick.cpp:229
double GetY(JoystickHand hand=kRightHand) const override
Get the Y value of the joystick.
Definition: Joystick.cpp:106
double GetZ(JoystickHand hand=kRightHand) const override
Get the Z value of the current joystick.
Definition: Joystick.cpp:115
int GetAxisCount() const
Get the number of axis for a joystick.
Definition: Joystick.cpp:213
bool GetButton(ButtonType button) const
Get buttons based on an enumerated type.
Definition: Joystick.cpp:197
int GetAxisChannel(AxisType axis) const
Get the channel currently associated with the specified axis.
Definition: Joystick.cpp:239