foot_contact_monitor.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
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     # wait for newer message
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     #pitch_threshold = rospy.get_param("~pitch_threshold", 2 * pi / 180.0)
00043     pitch_threshold = rospy.get_param("~pitch_threshold", 0.02)
00044     # controller_ac = actionlib.SimpleActionClient(
00045     #     'footstep_controller', ExecFootstepsAction)
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 


jsk_footstep_controller
Author(s):
autogenerated on Fri Apr 19 2019 03:45:37