Main Page
Classes
Files
File List
File Members
src
uos_diffdrive_teleop_key.cpp
Go to the documentation of this file.
1
/*
2
*
3
* Copyright (C) 2015 University of Osnabrück, Germany
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
*
19
* uos_diffdrive_teleop_key.cpp
20
*
21
* Created on: 16.02.2015
22
* Author: Sebastian Pütz <spuetz@uos.de>
23
*/
24
25
#include <
uos_diffdrive_teleop_key.h
>
26
27
int
kfd
= 0;
28
struct
termios cooked,
raw
;
29
30
TeleopKeyboard::TeleopKeyboard
(){
31
ros::NodeHandle
n_private(
"~"
);
32
n_private.
param
(
"normal_x"
,
normal_x
, 0.5);
33
n_private.
param
(
"normal_y"
,
normal_y
, 0.5);
34
n_private.
param
(
"high_x"
,
high_x
, 1.0);
35
n_private.
param
(
"high_y"
,
high_y
, 1.0);
36
37
// get the console in raw mode
38
tcgetattr(
kfd
, &cooked);
39
memcpy(&
raw
, &cooked,
sizeof
(
struct
termios));
40
raw
.c_lflag &=~ (ICANON | ECHO);
41
// Setting a new line, then end of file
42
raw
.c_cc[VEOL] = 1;
43
raw
.c_cc[VEOF] = 2;
44
raw
.c_cc[VMIN] = 0;
45
raw
.c_cc[VTIME] = 5;
46
tcsetattr(
kfd
, TCSANOW, &
raw
);
47
48
puts(
"Reading from keyboard"
);
49
puts(
"---------------------------"
);
50
puts(
"Use 'WS' to translate"
);
51
puts(
"Use 'AD' to yaw"
);
52
puts(
"Use 'QE' to translate and yaw"
);
53
puts(
"Press 'Shift' to run"
);
54
}
55
56
void
TeleopKeyboard::readKeyboard
()
57
{
58
c
= 0;
59
// get the next event from
60
// the keyboard
61
if
(read(
kfd
, &
c
, 1) < 0)
62
{
63
perror(
"read():"
);
64
exit(-1);
65
}
66
67
in
.
updated
=
true
;
68
69
switch
(
c
)
70
{
71
// Walking
72
case
73
KEYCODE_W
:
74
in
.
forwards
=
normal_y
;
75
break
;
76
case
77
KEYCODE_S
:
78
in
.
forwards
= -
normal_y
;
79
break
;
80
case
81
KEYCODE_A
:
82
in
.
left
=
normal_x
;
83
break
;
84
case
85
KEYCODE_D
:
86
in
.
left
= -
normal_x
;
87
break
;
88
case
89
KEYCODE_Q
:
90
in
.
forwards
=
normal_y
;
91
in
.
left
=
normal_x
;
92
break
;
93
case
94
KEYCODE_E
:
95
in
.
forwards
=
normal_y
;
96
in
.
left
= -
normal_x
;
97
break
;
98
99
// Running
100
case
101
KEYCODE_W_CAP
:
102
in
.
forwards
=
high_y
;
103
break
;
104
case
105
KEYCODE_S_CAP
:
106
in
.
forwards
= -
high_y
;
107
break
;
108
case
109
KEYCODE_A_CAP
:
110
in
.
left
=
high_x
;
111
break
;
112
case
113
KEYCODE_D_CAP
:
114
in
.
left
= -
high_x
;
115
break
;
116
case
117
KEYCODE_Q_CAP
:
118
in
.
forwards
=
high_y
;
119
in
.
left
=
high_x
;
120
break
;
121
case
122
KEYCODE_E_CAP
:
123
in
.
forwards
=
high_y
;
124
in
.
left
= -
high_x
;
125
break
;
126
default
:
127
in
.
updated
=
false
;
128
}
129
}
130
131
void
quit
(
int
sig)
132
{
133
tcsetattr(
kfd
, TCSANOW, &cooked);
134
exit(0);
135
}
136
137
int
main
(
int
argc,
char
** argv)
138
{
139
ros::init
(argc, argv,
"uos_diffdrive_teleop_key"
);
140
TeleopKeyboard
teleop;
141
signal(SIGINT,
quit
);
142
ros::AsyncSpinner
spinner(1);
143
spinner.
start
();
144
145
while
(
ros::ok
()){
146
teleop.
readKeyboard
();
147
}
148
return
EXIT_SUCCESS;
149
}
KEYCODE_S
#define KEYCODE_S
Definition:
uos_diffdrive_teleop_key.h:39
TeleopKeyboard::high_y
double high_y
Definition:
uos_diffdrive_teleop_key.h:64
KEYCODE_D
#define KEYCODE_D
Definition:
uos_diffdrive_teleop_key.h:38
ros::NodeHandle
KEYCODE_Q_CAP
#define KEYCODE_Q_CAP
Definition:
uos_diffdrive_teleop_key.h:48
TeleopKeyboard::readKeyboard
void readKeyboard()
Definition:
uos_diffdrive_teleop_key.cpp:56
ros::init
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
uos_diffdrive_teleop_key.h
kfd
int kfd
Definition:
uos_diffdrive_teleop_key.cpp:27
quit
void quit(int sig)
Definition:
uos_diffdrive_teleop_key.cpp:131
KEYCODE_E
#define KEYCODE_E
Definition:
uos_diffdrive_teleop_key.h:42
raw
struct termios cooked raw
Definition:
uos_diffdrive_teleop_key.cpp:28
KEYCODE_A
#define KEYCODE_A
Definition:
uos_diffdrive_teleop_key.h:37
TeleopKeyboard
Definition:
uos_diffdrive_teleop_key.h:53
ros::AsyncSpinner::start
void start()
ros::NodeHandle::param
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Teleop::inputs::updated
bool updated
Definition:
uos_diffdrive_teleop.h:70
ros::ok
ROSCPP_DECL bool ok()
Teleop::inputs::forwards
double forwards
Definition:
uos_diffdrive_teleop.h:71
main
int main(int argc, char **argv)
Definition:
uos_diffdrive_teleop_key.cpp:137
TeleopKeyboard::normal_x
double normal_x
Definition:
uos_diffdrive_teleop_key.h:61
Teleop::inputs::left
double left
Definition:
uos_diffdrive_teleop.h:72
KEYCODE_D_CAP
#define KEYCODE_D_CAP
Definition:
uos_diffdrive_teleop_key.h:45
KEYCODE_W
#define KEYCODE_W
Definition:
uos_diffdrive_teleop_key.h:40
KEYCODE_W_CAP
#define KEYCODE_W_CAP
Definition:
uos_diffdrive_teleop_key.h:47
TeleopKeyboard::normal_y
double normal_y
Definition:
uos_diffdrive_teleop_key.h:62
TeleopKeyboard::c
char c
Definition:
uos_diffdrive_teleop_key.h:60
TeleopKeyboard::TeleopKeyboard
TeleopKeyboard()
Definition:
uos_diffdrive_teleop_key.cpp:30
KEYCODE_S_CAP
#define KEYCODE_S_CAP
Definition:
uos_diffdrive_teleop_key.h:46
KEYCODE_Q
#define KEYCODE_Q
Definition:
uos_diffdrive_teleop_key.h:41
KEYCODE_A_CAP
#define KEYCODE_A_CAP
Definition:
uos_diffdrive_teleop_key.h:44
ros::AsyncSpinner
KEYCODE_E_CAP
#define KEYCODE_E_CAP
Definition:
uos_diffdrive_teleop_key.h:49
Teleop::in
inputs in
Definition:
uos_diffdrive_teleop.h:85
TeleopKeyboard::high_x
double high_x
Definition:
uos_diffdrive_teleop_key.h:63
uos_diffdrive_teleop
Author(s): Jochen Sprickerhof, Sebastian Pütz
autogenerated on Mon Jun 10 2019 15:49:27