foot_contact_monitor.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from jsk_footstep_msgs.msg import ExecFootstepsAction
5 from jsk_footstep_controller.msg import GroundContactState
6 from jsk_footstep_controller.srv import RequireMonitorStatus, RequireMonitorStatusResponse
7 from threading import Lock
8 from math import pi
9 import actionlib
10 
11 g_lock = Lock()
12 g_contact_state = None
13 
15  requested_stamp = req.header.stamp
16  # wait for newer message
17  r = rospy.Rate(10)
18  while not rospy.is_shutdown():
19  with g_lock:
20  if g_contact_state and requested_stamp < g_contact_state.header.stamp:
21  break
22  else:
23  rospy.loginfo("Waiting for newer message")
24  r.sleep()
25  with g_lock:
26  if abs(g_contact_state.error_pitch_angle) > req.threshold:
27  rospy.loginfo("error: %f > %f" % (g_contact_state.error_pitch_angle,
28  req.threshold))
29  return RequireMonitorStatusResponse(False)
30  else:
31  rospy.loginfo("error: %f < %f" % (g_contact_state.error_pitch_angle,
32  req.threshold))
33  return RequireMonitorStatusResponse(True)
34 
36  global g_contact_state
37  with g_lock:
38  g_contact_state = msg
39 
40 def main():
41  global pitch_threshold, controller_ac
42  #pitch_threshold = rospy.get_param("~pitch_threshold", 2 * pi / 180.0)
43  pitch_threshold = rospy.get_param("~pitch_threshold", 0.02)
44  # controller_ac = actionlib.SimpleActionClient(
45  # 'footstep_controller', ExecFootstepsAction)
46  sub = rospy.Subscriber("/footcoords/contact_state", GroundContactState, contactGroundCallback)
47  srv = rospy.Service("require_foot_contact_monitor", RequireMonitorStatus, requireMonitorCallback)
48  rospy.spin()
49 
50 if __name__ == "__main__":
51  rospy.init_node("foot_contact_monitor")
52  main()
53 


jsk_footstep_controller
Author(s):
autogenerated on Fri May 14 2021 02:52:04