upkie 7.0.0
Open-source wheeled biped robots
Loading...
Searching...
No Matches
upkie::cpp::sensors::Joystick Class Reference

Sensor for a joystick controller. More...

#include <Joystick.h>

Public Member Functions

 Joystick (const std::string &device_path="/dev/input/js0")
 Open the device file. More...
 
 ~Joystick () override
 Close device file.
 
bool present () const noexcept
 Check if the device file was opened successfully.
 
std::string prefix () const noexcept final
 Prefix of output in the observation dictionary. More...
 
void write (Dictionary &output) final
 Write output to a dictionary. More...
 
- Public Member Functions inherited from upkie::cpp::sensors::Sensor
virtual ~Sensor ()
 Destructor is virtual to deallocate lists of observers properly.
 
virtual std::string prefix () const noexcept
 Prefix of output in the observation dictionary. More...
 
virtual void write (Dictionary &observation)
 Write output to a dictionary. More...
 

Detailed Description

Sensor for a joystick controller.

Note
This sensor only works on Linux.

Axes are the same for PS4 and Xbox controllers, but buttons differ slightly.

Outputs

This sensor has the following outputs:

Buttons

Key Type Description
cross_button float bottom button (cross on PS4, A on Xbox)
square_button float left button (square on PS4, Y on Xbox)
triangle_button float top button (triangle on PS4, X on Xbox)
left_button float L1 on PS4, L on Xbox
right_button float R1 on PS4, R on Xbox

Note that the red button (circle on PS4, B on Xbox) serves as emergency stop 🚨: when it is pressed, the spine will terminate.

Continus axes

Key Type Description
left_axis [float, float] left analog joystick
right_axis [float, float] right analog joystick
left_trigger float left trigger if there is one (L2 on PS4)
right_trigger float right trigger if there is one (R2 on PS4)

Discrete axes

Key Type Description
pad_axis [float, float] directional pad

Constructor & Destructor Documentation

◆ Joystick()

upkie::cpp::sensors::Joystick::Joystick ( const std::string &  device_path = "/dev/input/js0")

Open the device file.

Parameters
[in]device_pathPath to the joystick device file.

Member Function Documentation

◆ prefix()

std::string upkie::cpp::sensors::Joystick::prefix ( ) const
inlinefinalvirtualnoexcept

Prefix of output in the observation dictionary.

Reimplemented from upkie::cpp::sensors::Sensor.

◆ write()

void upkie::cpp::sensors::Joystick::write ( Dictionary &  output)
finalvirtual

Write output to a dictionary.

Parameters
[out]outputDictionary to write observations to.

Reimplemented from upkie::cpp::sensors::Sensor.


The documentation for this class was generated from the following files: