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


sr_hand
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:24