Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 import rospy
00022 from geometry_msgs.msg import WrenchStamped
00023
00024
00025 class ForceTorquePlay(object):
00026 def __init__(self):
00027 self.last_msg = None
00028 self.force_torque_sub = rospy.Subscriber('/wrist_ft',
00029 WrenchStamped,
00030 self.force_torque_cb,
00031 queue_size=1)
00032 rospy.loginfo(
00033 "Subscribed to: '" + str(self.force_torque_sub.resolved_name) + "' topic.")
00034 self.run()
00035
00036 def force_torque_cb(self, msg):
00037 """
00038 :type msg: WrenchStamped
00039 """
00040 self.last_msg = msg
00041
00042 def run(self):
00043 """Show information on what was found in the joint states current"""
00044 rospy.loginfo("Waiting for first WrenchStamped message...")
00045 while not rospy.is_shutdown() and self.last_msg is None:
00046 rospy.sleep(0.2)
00047
00048
00049 r = rospy.Rate(2)
00050 while not rospy.is_shutdown():
00051 self.do_stuff_with_last_msg()
00052 r.sleep()
00053
00054 def do_stuff_with_last_msg(self):
00055 """Print funny sentences about what we can guess of our status thanks to the force torque sensor"""
00056
00057 f = self.last_msg.wrench.force
00058 t = self.last_msg.wrench.torque
00059 total_torque = abs(t.x) + abs(t.y) + abs(t.z)
00060 if f.z > 10.0:
00061 rospy.loginfo("Looks someone is pulling from my hand!")
00062 elif f.z < -10.0:
00063 rospy.loginfo("Looks someone is pushing my hand!")
00064 elif total_torque > 2.0:
00065 rospy.loginfo("Hey, why are you twisting my hand? :(")
00066 else:
00067 rospy.loginfo(
00068 "Do something with my hand and I'll tell you what I feel")
00069
00070
00071 if __name__ == '__main__':
00072 rospy.init_node('force_torque_play')
00073 ftp = ForceTorquePlay()
00074 rospy.spin()