Go to the documentation of this file.00001
00002
00003 import rospy
00004 from jsk_footstep_msgs.msg import ExecFootstepsAction
00005 from jsk_footstep_controller.msg import GroundContactState
00006 from jsk_footstep_controller.srv import RequireMonitorStatus, RequireMonitorStatusResponse
00007 from threading import Lock
00008 from math import pi
00009 import actionlib
00010
00011 g_lock = Lock()
00012 g_contact_state = None
00013
00014 def requireMonitorCallback(req):
00015 requested_stamp = req.header.stamp
00016
00017 r = rospy.Rate(10)
00018 while not rospy.is_shutdown():
00019 with g_lock:
00020 if g_contact_state and requested_stamp < g_contact_state.header.stamp:
00021 break
00022 else:
00023 rospy.loginfo("Waiting for newer message")
00024 r.sleep()
00025 with g_lock:
00026 if abs(g_contact_state.error_pitch_angle) > req.threshold:
00027 rospy.loginfo("error: %f > %f" % (g_contact_state.error_pitch_angle,
00028 req.threshold))
00029 return RequireMonitorStatusResponse(False)
00030 else:
00031 rospy.loginfo("error: %f < %f" % (g_contact_state.error_pitch_angle,
00032 req.threshold))
00033 return RequireMonitorStatusResponse(True)
00034
00035 def contactGroundCallback(msg):
00036 global g_contact_state
00037 with g_lock:
00038 g_contact_state = msg
00039
00040 def main():
00041 global pitch_threshold, controller_ac
00042
00043 pitch_threshold = rospy.get_param("~pitch_threshold", 0.02)
00044
00045
00046 sub = rospy.Subscriber("/footcoords/contact_state", GroundContactState, contactGroundCallback)
00047 srv = rospy.Service("require_foot_contact_monitor", RequireMonitorStatus, requireMonitorCallback)
00048 rospy.spin()
00049
00050 if __name__ == "__main__":
00051 rospy.init_node("foot_contact_monitor")
00052 main()
00053