force_torque_play.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright (c) 2016 PAL Robotics SL. All Rights Reserved
00004 #
00005 # Permission to use, copy, modify, and/or distribute this software for
00006 # any purpose with or without fee is hereby granted, provided that the
00007 # above copyright notice and this permission notice appear in all
00008 # copies.
00009 #
00010 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017 #
00018 # Author:
00019 #   * Sammy Pfeiffer
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         # Check at a 5Hz rate to not spam
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         # self.last_msg = WrenchStamped()  # line for autocompletion pourposes
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()


play_with_sensors
Author(s):
autogenerated on Fri Aug 26 2016 13:20:19