31 std::vector<bool> buttons;
35 const int nJoystick = 0;
37 printf(
"Press any key to stop program...\n");
44 double t = tictac.
Tac();
46 printf(
"Joystick readings: %.03f, %.03f, %.03f (",
x,
y,
z);
47 for (
unsigned b = 0;
b < buttons.size();
b++)
48 printf(
"B%u:%c ",
b, buttons[
b] ?
'X' :
'-');
49 printf(
") [Query %uus] \r", (
unsigned)(
t * 1e6));
56 "Error reading from joystick, please connect one to the " 60 std::this_thread::sleep_for(20ms);
75 catch (std::exception& e)
77 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
82 printf(
"Untyped exception!!");
double Tac() noexcept
Stops the stopwatch.
A high-performance stopwatch, with typical resolution of nanoseconds.
Contains classes for various device interfaces.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool getJoystickPosition(int nJoy, float &x, float &y, float &z, std::vector< bool > &buttons, int *raw_x_pos=nullptr, int *raw_y_pos=nullptr, int *raw_z_pos=nullptr)
Gets joystick information.
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
void Tic() noexcept
Starts the stopwatch.
Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the ...