Main MRPT website
>
C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1
/* +------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| http://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6
| See: http://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See details in http://www.mrpt.org/License |
8
+------------------------------------------------------------------------+ */
9
10
#include <
mrpt/hwdrivers/CJoystick.h
>
11
#include <
mrpt/system/CTicTac.h
>
12
#include <
mrpt/system/os.h
>
13
14
#include <cstdio>
15
#include <iostream>
16
#include <thread>
17
18
using namespace
std;
19
using namespace
mrpt
;
20
using namespace
mrpt::system
;
21
using namespace
mrpt::hwdrivers
;
22
23
// ------------------------------------------------------
24
// TestJoystick
25
// ------------------------------------------------------
26
void
TestJoystick
()
27
{
28
// Open first joystick:
29
// ---------------------------
30
float
x
,
y
,
z
;
31
std::vector<bool> buttons;
32
CTicTac
tictac;
33
CJoystick
joy;
34
35
const
int
nJoystick = 0;
// The first one
36
37
printf(
"Press any key to stop program...\n"
);
38
39
while
(!
mrpt::system::os::kbhit
())
40
{
41
tictac.
Tic
();
42
if
(joy.
getJoystickPosition
(nJoystick,
x
,
y
,
z
, buttons))
43
{
44
double
t
= tictac.
Tac
();
45
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));
50
51
fflush(stdout);
52
}
53
else
54
{
55
printf(
56
"Error reading from joystick, please connect one to the "
57
"system...\r"
);
58
}
59
60
std::this_thread::sleep_for(20ms);
61
}
62
}
63
64
// ------------------------------------------------------
65
// MAIN
66
// ------------------------------------------------------
67
int
main
()
68
{
69
try
70
{
71
TestJoystick
();
72
73
return
0;
74
}
75
catch
(std::exception& e)
76
{
77
std::cout <<
"MRPT exception caught: "
<< e.what() << std::endl;
78
return
-1;
79
}
80
catch
(...)
81
{
82
printf(
"Untyped exception!!"
);
83
return
-1;
84
}
85
}
mrpt::system::os::kbhit
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition:
os.cpp:390
os.h
t
GLdouble GLdouble t
Definition:
glext.h:3689
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition:
system/CTicTac.h:19
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition:
C2DRangeFinderAbstract.h:22
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition:
CKalmanFilterCapable.h:30
mrpt::hwdrivers::CJoystick
Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the ...
Definition:
CJoystick.h:25
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition:
CTicTac.cpp:90
main
int main()
Definition:
vision_stereo_rectify/test.cpp:78
b
GLubyte GLubyte b
Definition:
glext.h:6279
CJoystick.h
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition:
CTicTac.cpp:79
CTicTac.h
TestJoystick
void TestJoystick()
Definition:
vision_stereo_rectify/test.cpp:26
z
GLdouble GLdouble z
Definition:
glext.h:3872
mrpt::hwdrivers::CJoystick::getJoystickPosition
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.
Definition:
CJoystick.cpp:113
y
GLenum GLint GLint y
Definition:
glext.h:3538
x
GLenum GLint x
Definition:
glext.h:3538
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition:
math_frwds.h:25
Page generated by
Doxygen 1.8.17
for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST