src
jsk_teleop_joy
joy_status.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
import
rospy
4
import
roslib
5
6
try
:
7
from
sensor_msgs.msg
import
Joy
8
except
:
9
import
roslib; roslib.load_manifest(
"jsk_teleop_joy"
)
10
from
sensor_msgs.msg
import
Joy
11
12
class
JoyStatus
():
13
def
__init__
(self):
14
15
self.
center
=
False
16
self.
select
=
False
17
self.
start
=
False
18
self.
up
=
False
19
self.
down
=
False
20
self.
left
=
False
21
self.
right
=
False
22
self.
circle
=
False
23
self.
cross
=
False
24
self.
triangle
=
False
25
self.
square
=
False
26
self.
L1
=
False
27
self.
R1
=
False
28
self.
L2
=
False
29
self.
R2
=
False
30
self.
L3
=
False
31
self.
R3
=
False
32
33
self.
left_analog_x
= 0.0
34
self.
left_analog_y
= 0.0
35
self.
right_analog_x
= 0.0
36
self.
right_analog_y
= 0.0
37
38
self.
left_analog_up
=
False
39
self.
left_analog_down
=
False
40
self.
left_analog_left
=
False
41
self.
left_analog_right
=
False
42
43
def
checkAnalogStick
(self):
44
self.
analog_threshold
= 0.8
45
if
self.
left_analog_x
> self.
analog_threshold
:
46
self.
left_analog_left
=
True
47
48
if
self.
left_analog_x
< -self.
analog_threshold
:
49
self.
left_analog_right
=
True
50
51
if
self.
left_analog_y
> self.
analog_threshold
:
52
self.
left_analog_up
=
True
53
54
if
self.
left_analog_y
< -self.
analog_threshold
:
55
self.
left_analog_down
=
True
56
57
58
def
toPS3Msg
(self):
59
joy = Joy()
60
joy.header = self.orig_msg.header
61
joy.buttons = [0] * 17
62
joy.axes = [0] * 20
63
if
self.
center
:
64
joy.buttons[16] = 1
65
if
self.
select
:
66
joy.buttons[0] = 1
67
if
self.
start
:
68
joy.buttons[3] = 1
69
if
self.
L3
:
70
joy.buttons[1] = 1
71
if
self.
R3
:
72
joy.buttons[2] = 1
73
if
self.
square
:
74
joy.axes[15] = -1.0
75
joy.buttons[15] = 1
76
if
self.
up
:
77
joy.axes[4] = -1.0
78
joy.buttons[4] = 1
79
if
self.
down
:
80
joy.axes[6] = -1.0
81
joy.buttons[6] = 1
82
if
self.
left
:
83
joy.axes[7] = -1.0
84
joy.buttons[7] = 1
85
if
self.
right
:
86
joy.axes[5] = -1.0
87
joy.buttons[5] = 1
88
if
self.
triangle
:
89
joy.axes[12] = -1.0
90
joy.buttons[12] = 1
91
if
self.
cross
:
92
joy.axes[14] = -1.0
93
joy.buttons[14] = 1
94
if
self.
circle
:
95
joy.axes[13] = -1.0
96
joy.buttons[13] = 1
97
if
self.
L1
:
98
joy.axes[10] = -1.0
99
joy.buttons[10] = 1
100
if
self.
R1
:
101
joy.axes[11] = -1.0
102
joy.buttons[11] = 1
103
if
self.
L2
:
104
joy.axes[8] = -1.0
105
joy.buttons[8] = 1
106
if
self.
R2
:
107
joy.axes[9] = -1.0
108
joy.buttons[9] = 1
109
joy.axes[0] = self.
left_analog_x
110
joy.axes[1] = self.
left_analog_y
111
joy.axes[2] = self.
right_analog_x
112
joy.axes[3] = self.
right_analog_y
113
return
joy
114
115
116
class
IpegaStatus
(
JoyStatus
):
117
def
__init__
(self, msg):
118
'''
119
ipaga game pad
120
No home button
121
Y button => triangle
122
X button => square
123
B button => circle
124
A button => cross
125
'''
126
JoyStatus.__init__(self)
127
self.
center
=
False
128
if
msg.buttons[10] == 1:
129
self.
select
=
True
130
else
:
131
self.
select
=
False
132
if
msg.buttons[11] == 1:
133
self.
start
=
True
134
else
:
135
self.
start
=
False
136
if
msg.buttons[13] == 1:
137
self.
L3
=
True
138
else
:
139
self.
L3
=
False
140
if
msg.buttons[14] == 1:
141
self.
R3
=
True
142
else
:
143
self.
R3
=
False
144
if
msg.buttons[3] == 1:
145
self.
square
=
True
146
else
:
147
self.
square
=
False
148
if
msg.buttons[1] == 1:
149
self.
circle
=
True
150
else
:
151
self.
circle
=
False
152
if
msg.axes[7] > 0.1:
153
self.
up
=
True
154
else
:
155
self.
up
=
False
156
if
msg.axes[7] < -0.1:
157
self.
down
=
True
158
else
:
159
self.
down
=
False
160
if
msg.axes[6] > 0.1:
161
self.
left
=
True
162
else
:
163
self.
left
=
False
164
if
msg.axes[6] < -0.1:
165
self.
right
=
True
166
else
:
167
self.
right
=
False
168
if
msg.buttons[4] == 1:
169
self.
triangle
=
True
170
else
:
171
self.
triangle
=
False
172
if
msg.buttons[0] == 1:
173
self.
cross
=
True
174
else
:
175
self.
cross
=
False
176
if
msg.buttons[6] == 1:
177
self.
L1
=
True
178
else
:
179
self.
L1
=
False
180
if
msg.buttons[7] == 1:
181
self.
R1
=
True
182
else
:
183
self.
R1
=
False
184
if
msg.axes[5] < -0.5:
185
self.
L2
=
True
186
else
:
187
self.
L2
=
False
188
if
msg.axes[4] < -0.5:
189
self.
R2
=
True
190
else
:
191
self.
R2
=
False
192
self.
left_analog_x
= msg.axes[0]
193
self.
left_analog_y
= msg.axes[1]
194
self.
right_analog_x
= msg.axes[2]
195
self.
right_analog_y
= msg.axes[3]
196
self.
checkAnalogStick
()
197
self.
orig_msg
= msg
198
199
class
XBoxStatus
(
JoyStatus
):
200
def
__init__
(self, msg):
201
'''
202
Xbox game pad
203
Y button => triangle
204
X button => square
205
B button => circle
206
A button => cross
207
RB => R1
208
LB => L1
209
RT => R2
210
LT => L2
211
'''
212
JoyStatus.__init__(self)
213
if
msg.buttons[8] == 1:
214
self.
center
=
True
215
else
:
216
self.
center
=
False
217
if
msg.buttons[6] == 1:
218
self.
select
=
True
219
else
:
220
self.
select
=
False
221
if
msg.buttons[7] == 1:
222
self.
start
=
True
223
else
:
224
self.
start
=
False
225
if
msg.buttons[9] == 1:
226
self.
L3
=
True
227
else
:
228
self.
L3
=
False
229
if
msg.buttons[10] == 1:
230
self.
R3
=
True
231
else
:
232
self.
R3
=
False
233
if
msg.buttons[2] == 1:
234
self.
square
=
True
235
else
:
236
self.
square
=
False
237
if
msg.buttons[1] == 1:
238
self.
circle
=
True
239
else
:
240
self.
circle
=
False
241
if
msg.axes[7] > 0.1:
242
self.
up
=
True
243
else
:
244
self.
up
=
False
245
if
msg.axes[7] < -0.1:
246
self.
down
=
True
247
else
:
248
self.
down
=
False
249
if
msg.axes[6] > 0.1:
250
self.
left
=
True
251
else
:
252
self.
left
=
False
253
if
msg.axes[6] < -0.1:
254
self.
right
=
True
255
else
:
256
self.
right
=
False
257
if
msg.buttons[3] == 1:
258
self.
triangle
=
True
259
else
:
260
self.
triangle
=
False
261
if
msg.buttons[0] == 1:
262
self.
cross
=
True
263
else
:
264
self.
cross
=
False
265
if
msg.buttons[4] == 1:
266
self.
L1
=
True
267
else
:
268
self.
L1
=
False
269
if
msg.buttons[5] == 1:
270
self.
R1
=
True
271
else
:
272
self.
R1
=
False
273
if
msg.axes[2] < -0.5:
274
self.
L2
=
True
275
else
:
276
self.
L2
=
False
277
if
msg.axes[5] < -0.5:
278
self.
R2
=
True
279
else
:
280
self.
R2
=
False
281
self.
left_analog_x
= msg.axes[0]
282
self.
left_analog_y
= msg.axes[1]
283
self.
right_analog_x
= msg.axes[3]
284
self.
right_analog_y
= msg.axes[4]
285
self.
checkAnalogStick
()
286
self.
orig_msg
= msg
287
288
class
PS3Status
(
JoyStatus
):
289
def
__init__
(self, msg):
290
JoyStatus.__init__(self)
291
# creating from sensor_msgs/Joy
292
if
msg.buttons[16] == 1:
293
self.
center
=
True
294
else
:
295
self.
center
=
False
296
if
msg.buttons[0] == 1:
297
self.
select
=
True
298
else
:
299
self.
select
=
False
300
if
msg.buttons[3] == 1:
301
self.
start
=
True
302
else
:
303
self.
start
=
False
304
if
msg.buttons[1] == 1:
305
self.
L3
=
True
306
else
:
307
self.
L3
=
False
308
if
msg.buttons[2] == 1:
309
self.
R3
=
True
310
else
:
311
self.
R3
=
False
312
if
msg.axes[15] < 0:
313
self.
square
=
True
314
else
:
315
self.
square
=
False
316
if
msg.axes[4] < 0:
317
self.
up
=
True
318
else
:
319
self.
up
=
False
320
if
msg.axes[6] < 0:
321
self.
down
=
True
322
else
:
323
self.
down
=
False
324
if
msg.axes[7] < 0:
325
self.
left
=
True
326
else
:
327
self.
left
=
False
328
if
msg.axes[5] < 0:
329
self.
right
=
True
330
else
:
331
self.
right
=
False
332
if
msg.axes[12] < 0:
333
self.
triangle
=
True
334
else
:
335
self.
triangle
=
False
336
if
msg.axes[14] < 0:
337
self.
cross
=
True
338
else
:
339
self.
cross
=
False
340
if
msg.axes[13] < 0:
341
self.
circle
=
True
342
else
:
343
self.
circle
=
False
344
if
msg.axes[10] < 0:
345
self.
L1
=
True
346
else
:
347
self.
L1
=
False
348
if
msg.axes[11] < 0:
349
self.
R1
=
True
350
else
:
351
self.
R1
=
False
352
if
msg.axes[8] < 0:
353
self.
L2
=
True
354
else
:
355
self.
L2
=
False
356
if
msg.axes[9] < 0:
357
self.
R2
=
True
358
else
:
359
self.
R2
=
False
360
self.
left_analog_x
= msg.axes[0]
361
self.
left_analog_y
= msg.axes[1]
362
self.
right_analog_x
= msg.axes[2]
363
self.
right_analog_y
= msg.axes[3]
364
self.
checkAnalogStick
()
365
self.
orig_msg
= msg
366
367
class
PS3WiredStatus
(
JoyStatus
):
368
def
__init__
(self, msg):
369
JoyStatus.__init__(self)
370
# creating from sensor_msgs/Joy
371
if
msg.buttons[16] == 1:
372
self.
center
=
True
373
else
:
374
self.
center
=
False
375
if
msg.buttons[0] == 1:
376
self.
select
=
True
377
else
:
378
self.
select
=
False
379
if
msg.buttons[3] == 1:
380
self.
start
=
True
381
else
:
382
self.
start
=
False
383
if
msg.buttons[1] == 1:
384
self.
L3
=
True
385
else
:
386
self.
L3
=
False
387
if
msg.buttons[2] == 1:
388
self.
R3
=
True
389
else
:
390
self.
R3
=
False
391
if
msg.buttons[15] == 1:
392
self.
square
=
True
393
else
:
394
self.
square
=
False
395
if
msg.buttons[4] == 1:
396
self.
up
=
True
397
else
:
398
self.
up
=
False
399
if
msg.buttons[6] == 1:
400
self.
down
=
True
401
else
:
402
self.
down
=
False
403
if
msg.buttons[7] == 1:
404
self.
left
=
True
405
else
:
406
self.
left
=
False
407
if
msg.buttons[5] == 1:
408
self.
right
=
True
409
else
:
410
self.
right
=
False
411
if
msg.buttons[12] == 1:
412
self.
triangle
=
True
413
else
:
414
self.
triangle
=
False
415
if
msg.buttons[14] == 1:
416
self.
cross
=
True
417
else
:
418
self.
cross
=
False
419
if
msg.buttons[13] == 1:
420
self.
circle
=
True
421
else
:
422
self.
circle
=
False
423
if
msg.buttons[10] == 1:
424
self.
L1
=
True
425
else
:
426
self.
L1
=
False
427
if
msg.buttons[11] == 1:
428
self.
R1
=
True
429
else
:
430
self.
R1
=
False
431
if
msg.buttons[8] == 1:
432
self.
L2
=
True
433
else
:
434
self.
L2
=
False
435
if
msg.buttons[9] == 1:
436
self.
R2
=
True
437
else
:
438
self.
R2
=
False
439
self.
left_analog_x
= msg.axes[0]
440
self.
left_analog_y
= msg.axes[1]
441
self.
right_analog_x
= msg.axes[2]
442
self.
right_analog_y
= msg.axes[3]
443
self.
checkAnalogStick
()
444
self.
orig_msg
= msg
jsk_teleop_joy.joy_status.JoyStatus.cross
cross
Definition:
joy_status.py:23
jsk_teleop_joy.joy_status.PS3WiredStatus
Definition:
joy_status.py:367
jsk_teleop_joy.joy_status.JoyStatus.select
select
Definition:
joy_status.py:16
jsk_teleop_joy.joy_status.IpegaStatus.orig_msg
orig_msg
Definition:
joy_status.py:197
jsk_teleop_joy.joy_status.JoyStatus.circle
circle
Definition:
joy_status.py:22
jsk_teleop_joy.joy_status.JoyStatus.R3
R3
Definition:
joy_status.py:31
jsk_teleop_joy.joy_status.PS3Status
Definition:
joy_status.py:288
jsk_teleop_joy.joy_status.JoyStatus.start
start
Definition:
joy_status.py:17
jsk_teleop_joy.joy_status.JoyStatus.analog_threshold
analog_threshold
Definition:
joy_status.py:44
jsk_teleop_joy.joy_status.JoyStatus.L1
L1
Definition:
joy_status.py:26
jsk_teleop_joy.joy_status.PS3Status.orig_msg
orig_msg
Definition:
joy_status.py:365
jsk_teleop_joy.joy_status.JoyStatus.L3
L3
Definition:
joy_status.py:30
jsk_teleop_joy.joy_status.JoyStatus.left_analog_y
left_analog_y
Definition:
joy_status.py:34
jsk_teleop_joy.joy_status.IpegaStatus
Definition:
joy_status.py:116
jsk_teleop_joy.joy_status.JoyStatus.left_analog_up
left_analog_up
analog as buttons
Definition:
joy_status.py:38
jsk_teleop_joy.joy_status.JoyStatus.left_analog_x
left_analog_x
analog axis
Definition:
joy_status.py:33
jsk_teleop_joy.joy_status.JoyStatus.left_analog_down
left_analog_down
Definition:
joy_status.py:39
jsk_teleop_joy.joy_status.JoyStatus.right
right
Definition:
joy_status.py:21
jsk_teleop_joy.joy_status.PS3WiredStatus.orig_msg
orig_msg
Definition:
joy_status.py:444
jsk_teleop_joy.joy_status.JoyStatus.toPS3Msg
def toPS3Msg(self)
Definition:
joy_status.py:58
jsk_teleop_joy.joy_status.IpegaStatus.__init__
def __init__(self, msg)
Definition:
joy_status.py:117
jsk_teleop_joy.joy_status.JoyStatus.left
left
Definition:
joy_status.py:20
jsk_teleop_joy.joy_status.JoyStatus.up
up
Definition:
joy_status.py:18
jsk_teleop_joy.joy_status.XBoxStatus.orig_msg
orig_msg
Definition:
joy_status.py:286
jsk_teleop_joy.joy_status.JoyStatus.L2
L2
Definition:
joy_status.py:28
jsk_teleop_joy.joy_status.JoyStatus.left_analog_left
left_analog_left
Definition:
joy_status.py:40
jsk_teleop_joy.joy_status.JoyStatus
Definition:
joy_status.py:12
jsk_teleop_joy.joy_status.PS3Status.__init__
def __init__(self, msg)
Definition:
joy_status.py:289
jsk_teleop_joy.joy_status.JoyStatus.R2
R2
Definition:
joy_status.py:29
jsk_teleop_joy.joy_status.JoyStatus.square
square
Definition:
joy_status.py:25
jsk_teleop_joy.joy_status.JoyStatus.right_analog_x
right_analog_x
Definition:
joy_status.py:35
jsk_teleop_joy.joy_status.JoyStatus.__init__
def __init__(self)
Definition:
joy_status.py:13
jsk_teleop_joy.joy_status.JoyStatus.down
down
Definition:
joy_status.py:19
jsk_teleop_joy.joy_status.XBoxStatus.__init__
def __init__(self, msg)
Definition:
joy_status.py:200
jsk_teleop_joy.joy_status.JoyStatus.triangle
triangle
Definition:
joy_status.py:24
jsk_teleop_joy.joy_status.JoyStatus.checkAnalogStick
def checkAnalogStick(self)
Definition:
joy_status.py:43
jsk_teleop_joy.joy_status.XBoxStatus
Definition:
joy_status.py:199
jsk_teleop_joy.joy_status.JoyStatus.center
center
buttons
Definition:
joy_status.py:15
jsk_teleop_joy.joy_status.PS3WiredStatus.__init__
def __init__(self, msg)
Definition:
joy_status.py:368
jsk_teleop_joy.joy_status.JoyStatus.left_analog_right
left_analog_right
Definition:
joy_status.py:41
jsk_teleop_joy.joy_status.JoyStatus.R1
R1
Definition:
joy_status.py:27
jsk_teleop_joy.joy_status.JoyStatus.right_analog_y
right_analog_y
Definition:
joy_status.py:36
msg
jsk_teleop_joy
Author(s): Ryohei Ueda
autogenerated on Wed Jan 24 2024 04:05:49