Go to the documentation of this file.00001
00002
00003 import math
00004
00005 import roslib; roslib.load_manifest('assistive_teleop')
00006 import rospy
00007 import actionlib
00008 from std_msgs.msg import Int8
00009 from geometry_msgs.msg import WrenchStamped
00010 from assistive_teleop.msg import FtHoldAction, FtHoldFeedback, FtHoldResult
00011
00012
00013 class FtHolder:
00014
00015 def __init__(self):
00016 self.hold_server = actionlib.SimpleActionServer('ft_hold_action', FtHoldAction, self.hold, False)
00017 self.trans_pub = rospy.Publisher('shaving_state', Int8, latch=True)
00018 rospy.Subscriber('/netft_gravity_zeroing/wrench_zeroed', WrenchStamped, self.get_netft_state)
00019 self.hold_server.start()
00020
00021 def get_netft_state(self, ws):
00022 self.netft_wrench = ws
00023 self.ft_mag = math.sqrt(ws.wrench.force.x**2 + ws.wrench.force.y**2 + ws.wrench.force.z**2)
00024
00025 def hold(self, goal):
00026 rospy.loginfo("Holding Position: Will retreat with inactivity or high forces")
00027 ft_active = rospy.Time.now()
00028 hold_rate=rospy.Rate(200)
00029 result=FtHoldResult()
00030 print "Check ft mag init"
00031 print self.ft_mag
00032 self.trans_pub.publish(15)
00033 while not rospy.is_shutdown():
00034
00035 if self.hold_server.is_preempt_requested():
00036 print "FtHolder: Preempt requested"
00037 self.hold_server.set_preempted()
00038 rospy.loginfo("Hold Action Server Goal Preempted")
00039 break
00040
00041 if self.ft_mag > goal.activity_thresh:
00042 ft_active = rospy.Time.now()
00043 elif rospy.Time.now()-ft_active > goal.timeout:
00044 result.timeout = True
00045 self.hold_server.set_succeeded(result, "Inactive for %ss, finished holding" %goal.timeout.secs)
00046 rospy.loginfo("Inactive for %ss, finished holding" %goal.timeout.secs)
00047 break
00048
00049 if self.ft_mag > goal.mag_thresh:
00050 result.unsafe = True
00051 self.hold_server.set_aborted(result, "Unsafe Force Magnitude! Felt %f, Safety Threshold is %f" \
00052 %(self.ft_mag, goal.mag_thresh))
00053 rospy.loginfo("Unsafe Force Magnitude! Felt %f, Safety Threshold is %f"\
00054 %(self.ft_mag, goal.mag_thresh))
00055 break
00056
00057 if self.netft_wrench.wrench.force.z > goal.z_thresh:
00058 result.unsafe = True
00059 self.hold_server.set_aborted(result, "Unsafe Normal Forces! Felt %f, Safety Threshold is %f" \
00060 %(self.netft_wrench.wrench.force.z, goal.z_thresh))
00061 rospy.loginfo("Unsafe Normal Forces! Felt %f, Safety Threshold is %f"\
00062 %(self.netft_wrench.wrench.force.z, goal.z_thresh))
00063 break
00064
00065
00066 hold_rate.sleep()
00067
00068 if __name__ == '__main__':
00069 rospy.init_node('hold_action')
00070 fth = FtHolder()
00071 while not rospy.is_shutdown():
00072 rospy.spin()