Skip to content

Commit 5f4b5ef

Browse files
committed
[jsk_tools/camera_check.py] Add restart camera launch function
1 parent fb5dccf commit 5f4b5ef

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

jsk_tools/src/camera_check.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
from __future__ import division
44

55
import os
6+
import time
67
import collections
78
import fcntl
9+
import subprocess
10+
import traceback
811

912
import rostopic
1013
import rospy
@@ -161,6 +164,38 @@ def is_image_valid(self, msg):
161164
return False
162165
return True
163166

167+
def restart_camera_node(self):
168+
rospy.logerr("Restart camera node")
169+
try:
170+
# 1. usbreset...
171+
self.speak("resetting u s b")
172+
self.reset_usb()
173+
time.sleep(10)
174+
# 2. kill nodelet manager
175+
if self.camera_nodelet_manager_name is not None:
176+
self.speak("something wrong with camera node, "
177+
"I'll restart it, killing nodelet manager")
178+
retcode = subprocess.call(
179+
'rosnode kill %s' %
180+
(self.camera_nodelet_manager_name), shell=True)
181+
time.sleep(10)
182+
183+
# 3. pkill
184+
self.speak("killing child processes")
185+
retcode = subprocess.call(
186+
'pkill -f %s' %
187+
self.child_camera_nodelet_manager_name,
188+
shell=True)
189+
time.sleep(10)
190+
191+
# 4 restarting
192+
self.speak("restarting processes")
193+
retcode = subprocess.call(
194+
self.restart_camera_command, shell=True)
195+
except Exception as e:
196+
rospy.logerr('[%s] Unable to kill kinect node, caught exception:\n%s',
197+
self.__class__.__name__, traceback.format_exc())
198+
164199
def run(self):
165200
while not rospy.is_shutdown():
166201
self.subscribe()

0 commit comments

Comments
 (0)