|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright (c) 2016, Kentaro Wada |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# |
| 9 | +# 1. Redistributions of source code must retain the above copyright notice, |
| 10 | +# this list of conditions and the following disclaimer. |
| 11 | +# 2. Redistributions in binary form must reproduce the above copyright |
| 12 | +# notice, this list of conditions and the following disclaimer in the |
| 13 | +# documentation and/or other materials provided with the distribution. |
| 14 | +# 3. Neither the name of the Kentaro Wada nor the names of its |
| 15 | +# contributors may be used to endorse or promote products derived from |
| 16 | +# this software without specific prior written permission. |
| 17 | +# |
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 22 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | +# POSSIBILITY OF SUCH DAMAGE. |
| 29 | + |
| 30 | +import os |
| 31 | + |
| 32 | +from dynamic_reconfigure.server import Server |
| 33 | +import rospy |
| 34 | +from std_msgs.msg import Empty |
| 35 | + |
| 36 | +from baxter_interface.cfg import SuppressRealtimeMonitoringServerConfig |
| 37 | + |
| 38 | + |
| 39 | +class SuppressRealtimeMonitoringServer(object): |
| 40 | + |
| 41 | + arms = ['left', 'right'] |
| 42 | + |
| 43 | + params = [ |
| 44 | + 'suppress_body_avoidance', |
| 45 | + 'suppress_collision_avoidance', |
| 46 | + 'suppress_contact_safety', |
| 47 | + 'suppress_cuff_interaction', |
| 48 | + 'suppress_gravity_compensation', |
| 49 | + 'suppress_hand_overwrench_safety', |
| 50 | + ] |
| 51 | + |
| 52 | + def __init__(self): |
| 53 | + # Initialize config and set dynamic parameter server |
| 54 | + self.config = {} |
| 55 | + self.dynparam_server = Server( |
| 56 | + SuppressRealtimeMonitoringServerConfig, self._dynparam_cb) |
| 57 | + # Initialize config and publishers |
| 58 | + self.publishers = {} |
| 59 | + for arm in self.arms: |
| 60 | + for param in self.params: |
| 61 | + key = arm + '_' + param |
| 62 | + self.publishers[key] = rospy.Publisher( |
| 63 | + os.path.join('/robot/limb', arm, param), Empty, |
| 64 | + queue_size=1) |
| 65 | + # Set timer with 10Hz |
| 66 | + # and it's enough because 5Hz is requested for supression |
| 67 | + self.timer = rospy.Timer( |
| 68 | + rospy.Duration(1.0 / 10), self.suppress_timer_cb) |
| 69 | + |
| 70 | + def _dynparam_cb(self, config, level): |
| 71 | + for arm in self.arms: |
| 72 | + for param in self.params: |
| 73 | + key = arm + '_' + param |
| 74 | + self.config[key] = config[key] |
| 75 | + return config |
| 76 | + |
| 77 | + def suppress_timer_cb(self, event): |
| 78 | + for key, pub in self.publishers.items(): |
| 79 | + if self.config[key]: |
| 80 | + pub.publish(Empty()) |
| 81 | + |
| 82 | + |
| 83 | +if __name__ == '__main__': |
| 84 | + rospy.init_node('suppress_realtime_monitoring_server') |
| 85 | + server = SuppressRealtimeMonitoringServer() |
| 86 | + rospy.spin() |
0 commit comments