1
1
#!/usr/bin/env python3
2
2
3
3
# ####################################################################
4
- # Copyright (c) 2013 Shadow Robot Company Ltd.
4
+ # Copyright (c) 2013, 2022 Shadow Robot Company Ltd.
5
5
# All rights reserved.
6
6
# This code is proprietary and may not be used, copied, distributed without
7
7
# prior authorisation and agreement from Shadow Robot Company Ltd. *
11
11
see README.md
12
12
"""
13
13
14
- from logitech_r400 .msg import LogitechR400
15
- import rospy
16
- import rospkg
17
14
from sys import exit as sysexit
18
15
from time import sleep
16
+
17
+ import rospkg
18
+ import rospy
19
19
import usb .core
20
20
import usb .util
21
21
import yaml
22
+ from logitech_r400 .msg import LogitechR400
22
23
23
24
24
- class LogitechR400Usb ( object ) :
25
+ class LogitechR400Usb :
25
26
"""
26
27
Usb driver for the Logitech R400.
27
28
@@ -64,16 +65,16 @@ class LogitechR400Usb(object):
64
65
def __enter__ (self ):
65
66
return self
66
67
67
- def __exit__ (self , type , value , traceback ):
68
+ def __exit__ (self , type_ , value , traceback ):
68
69
for device in self ._devices :
69
70
self ._release_device (device )
70
71
71
72
def _read_config (self ):
72
- configs_file_path = rospkg .RosPack ().get_path ('logitech_r400' ) + ' /config/config.yaml'
73
- with open (configs_file_path , 'r' ) as stream :
73
+ configs_file_path = f" { rospkg .RosPack ().get_path ('logitech_r400' )} /config/config.yaml"
74
+ with open (configs_file_path , 'r' , encoding = "utf8" ) as stream :
74
75
self ._configs = yaml .load (stream )
75
76
76
- def _is_R400 (self , dev ):
77
+ def _is_r400 (self , dev ):
77
78
for idx , config in enumerate (self ._configs ):
78
79
if dev .idVendor == config ['vendor' ] and dev .idProduct == config ['product' ]:
79
80
self ._used_config_idx = idx
@@ -85,7 +86,7 @@ class LogitechR400Usb(object):
85
86
Finds the usb devices in the system.
86
87
"""
87
88
88
- devices = list (usb .core .find (find_all = True , custom_match = self ._is_R400 ))
89
+ devices = list (usb .core .find (find_all = True , custom_match = self ._is_r400 ))
89
90
return devices
90
91
91
92
def _grab_device (self , device ):
@@ -99,7 +100,7 @@ class LogitechR400Usb(object):
99
100
device .detach_kernel_driver (self .__interface )
100
101
rospy .logdebug ("kernel driver detached" )
101
102
except usb .core .USBError as usb_exc :
102
- sysexit ("Could not detach kernel driver: %s" % str ( usb_exc ) )
103
+ sysexit (f "Could not detach kernel driver: { usb_exc } " )
103
104
104
105
device .set_configuration ()
105
106
usb .util .claim_interface (device , self .__interface )
0 commit comments