fake_driver.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 from std_srvs.srv import *
20 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus
21 
22 class FakeDriver():
23 
24  def __init__(self):
25  self.init_srv = rospy.Service('driver/init', Trigger, self.srv_cb)
26  self.recover_srv = rospy.Service('driver/recover', Trigger, self.srv_cb)
27  self.halt_srv = rospy.Service('driver/halt', Trigger, self.srv_cb)
28  self.shutdown_srv = rospy.Service('driver/shutdown', Trigger, self.srv_cb)
29 
30  self._fake_diag_pub = rospy.Publisher('/diagnostics', DiagnosticArray, queue_size=1)
31  rospy.Timer(rospy.Duration(1.0), self.publish_diagnostics)
32 
33  def publish_diagnostics(self, event):
34  msg = DiagnosticArray()
35  msg.header.stamp = rospy.get_rostime()
36 
37  status = DiagnosticStatus()
38  status.name = rospy.get_name()
39  status.level = DiagnosticStatus.OK
40  status.message = "fake diagnostics"
41  status.hardware_id = rospy.get_name()
42  msg.status.append(status)
43 
44  self._fake_diag_pub.publish(msg)
45 
46  def srv_cb(self, req):
47  resp = TriggerResponse()
48  resp.success = True
49  return resp
50 
51 
52 if __name__ == "__main__":
53  rospy.init_node('fake_driver')
54  FakeDriver()
55  rospy.loginfo("fake_driver running")
56  rospy.spin()
57 
def srv_cb(self, req)
Definition: fake_driver.py:46
def publish_diagnostics(self, event)
Definition: fake_driver.py:33


cob_helper_tools
Author(s): Felix Messmer
autogenerated on Wed Apr 7 2021 03:03:09