ds4_driver_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from ds4_driver.logger import Logger
4 from ds4_driver.controller_ros import ControllerRos
5 
6 from ds4drv.backends import BluetoothBackend, HidrawBackend
7 from ds4drv.exceptions import BackendError
8 
9 import rospy
10 
11 import signal
12 import sys
13 
14 
15 class SignalHandler(object):
16  def __init__(self, controller):
17  self.controller = controller
18 
19  def __call__(self, signum, frame):
20  rospy.loginfo('Shutting down...')
21  self.controller.exit()
22  sys.exit(0)
23 
24 
25 def main():
26  rospy.init_node('ds4_driver_node')
27 
28  device_addr = rospy.get_param('~device_addr', None)
29  backend_type = rospy.get_param('~backend', 'hidraw')
30 
31  controller = ControllerRos()
32 
33  sigint_handler = SignalHandler(controller)
34  # Since backend.devices is a non-ROS iterator that doesn't consider
35  # rospy.is_shutdown(), the program freezes upon receiving SIGINT when
36  # using rospy.on_shutdown. Thus, we need to define our shutdown sequence
37  # using signal.signal as is done in the original ds4drv script.
38  signal.signal(signal.SIGINT, sigint_handler)
39 
40  if backend_type == 'bluetooth':
41  backend = BluetoothBackend(Logger('backend'))
42  else:
43  backend = HidrawBackend(Logger('backend'))
44 
45  try:
46  backend.setup()
47  except BackendError as err:
48  rospy.logerr(err)
49  rospy.signal_shutdown(str(err))
50  sys.exit(1)
51 
52  for device in backend.devices:
53  rospy.loginfo('Connected to {0}'.format(device.name))
54  if device_addr in (None, '', device.device_addr):
55  controller.setup_device(device)
56  if not controller.is_alive():
57  controller.start()
58  controller.loop.register_event('device-report', controller.cb_report)
59  else:
60  rospy.loginfo("...but it's not the one we're looking for :(")
61 
62 
63 if __name__ == '__main__':
64  main()
def __init__(self, controller)
def __call__(self, signum, frame)


ds4_driver
Author(s): Naoki Mizuno
autogenerated on Fri May 1 2020 03:25:46