tactile_receiver.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # Copyright 2014 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 2 of the License, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 import rospy
19 
20 from sr_robot_msgs.msg import BiotacAll, ShadowPST, UBI0All
21 
22 
23 class TactileReceiver(object):
24 
25  """
26  Module that receives the tactile values.
27  """
28 
29  def __init__(self, prefix=""):
30  """
31  Receives the tactile information from a Shadow Hand
32  @param prefix - prefix for the tactile topic
33  """
34  # appends trailing slash if necessary
35  if not prefix.endswith("/"):
36  # kind of a hack to remove trailing underscores
37  if prefix.endswith("_"):
38  prefix = prefix[:-1]
39  prefix += "/"
40 
41  self._prefix = prefix
42 
44  self.tactile_state = None
45 
46  if self.tactile_type == "PST":
47  self.tactile_listener = rospy.Subscriber(
48  prefix + "tactile", ShadowPST, self.tactile_callback, queue_size=1)
49  elif self.tactile_type == "biotac":
50  self.tactile_listener = rospy.Subscriber(
51  prefix + "tactile", BiotacAll, self.tactile_callback, queue_size=1)
52  elif self.tactile_type == "UBI0":
53  self.tactile_listener = rospy.Subscriber(
54  prefix + "tactile", UBI0All, self.tactile_callback, queue_size=1)
55 
56  def find_tactile_type(self):
57  try:
58  rospy.wait_for_message(
59  self._prefix + "tactile", ShadowPST, timeout=1.0)
60  return "PST"
61  except (rospy.ROSException, rospy.ROSInterruptException):
62  pass
63 
64  try:
65  rospy.wait_for_message(
66  self._prefix + "tactile", BiotacAll, timeout=1.0)
67  return "biotac"
68  except (rospy.ROSException, rospy.ROSInterruptException):
69  pass
70 
71  try:
72  rospy.wait_for_message(
73  self._prefix + "tactile", UBI0All, timeout=1.0)
74  return "UBI0"
75  except (rospy.ROSException, rospy.ROSInterruptException):
76  rospy.logwarn(
77  "No tactile topic found. This is normal for a simulated hand")
78 
79  return None
80 
81  def tactile_callback(self, tactile_msg):
82  self.tactile_state = tactile_msg
83 
84  def get_tactile_type(self):
85  return self.tactile_type
86 
87  def get_tactile_state(self):
88  return self.tactile_state


sr_hand
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:53