7 #include <linux/joystick.h>
33 Joystick(
const std::string& device_path =
"/dev/input/js0");
39 inline bool present() const noexcept {
return (fd_ >= 0); }
42 inline std::string
prefix() const noexcept final {
return "joystick"; }
48 void write(Dictionary& output)
final;
59 struct js_event event_;
62 Eigen::Vector2d left_axis_ = Eigen::Vector2d::Zero();
65 double left_trigger_ = -1.0;
68 Eigen::Vector2d right_axis_ = Eigen::Vector2d::Zero();
71 double right_trigger_ = -1.0;
74 Eigen::Vector2d pad_axis_ = Eigen::Vector2d::Zero();
77 bool cross_button_ =
false;
80 bool left_button_ =
false;
83 bool right_button_ =
false;
86 bool square_button_ =
false;
89 bool triangle_button_ =
false;
Source for a joystick controller.
std::string prefix() const noexcept final
Prefix of output in the observation dictionary.
~Joystick() override
Close device file.
bool present() const noexcept
Check if the device file was opened successfully.
void write(Dictionary &output) final
Write output to a dictionary.
Joystick(const std::string &device_path="/dev/input/js0")
Open the device file.
constexpr double kJoystickDeadband
Deadband between 0.0 and 1.0.