landing_time_detector.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4 Display the difference between reference and actual swing/support time according to hrpsys_ros_bridge/ContactState using
5 jsk_rviz_plugins/PictogramArray
6 """
7 
8 import rospy
9 from jsk_rviz_plugins.msg import Pictogram, PictogramArray
10 from geometry_msgs.msg import Quaternion
11 from hrpsys_ros_bridge.msg import ContactState, ContactStateStamped, ContactStatesStamped
12 from std_msgs.msg import ColorRGBA
13 import message_filters
14 
15 def callback(ref, act):
16  "msgs = ContactStatesStamped"
17  if len(ref_contact_states_queue) > buffer_size - 1:
18  arr = PictogramArray()
19  arr.header.frame_id = "/odom"
20  arr.header.stamp = rospy.Time.now()
21  for i, (ref_st, act_st) in enumerate(zip(ref.states, act.states)):
22  picto = Pictogram()
23  if ref_st.state.state == act_st.state.state:
24  continue
25  else:
26  if [ref_st.state.state, act_st.state.state] == [ContactState.OFF, ContactState.ON]:
27  if [x.states[i].state.state for x in ref_contact_states_queue] == [ContactState.OFF] * buffer_size and [x.states[i].state.state for x in act_contact_states_queue] == [ContactState.OFF] * buffer_size:
28  picto.character = "fa-long-arrow-down"
29  picto.size = 1
30  picto.pose.orientation = Quaternion(0, -1, 0, 1)
31  picto.action = Pictogram.ADD
32  picto.color = ColorRGBA(1.0, 0.0, 0.0, 0.8)
33  rospy.loginfo("%s early landing %s [s]", ref_st.header.frame_id, str(ref_st.state.remaining_time))
34  elif [x.states[i].state.state for x in ref_contact_states_queue] == [ContactState.ON] * buffer_size and [x.states[i].state.state for x in act_contact_states_queue] == [ContactState.ON] * buffer_size:
35  picto.character = "up-bold"
36  picto.size = 1
37  picto.pose.orientation = Quaternion(0, -1, 0, 1)
38  picto.action = Pictogram.ADD
39  picto.color = ColorRGBA(0.0, 1.0, 0.0, 0.8)
40  rospy.loginfo("%s late taking off", ref_st.header.frame_id)
41  print("oso hanare")
42  else:
43  continue
44  elif [ref_st.state.state, act_st.state.state] == [ContactState.ON, ContactState.OFF]:
45  if [x.states[i].state.state for x in ref_contact_states_queue] == [ContactState.OFF] * buffer_size and [x.states[i].state.state for x in act_contact_states_queue] == [ContactState.OFF] * buffer_size:
46  picto.character = "fa-long-arrow-down"
47  picto.size = 1
48  picto.pose.orientation = Quaternion(0, -1, 0, 1)
49  picto.action = Pictogram.ADD
50  picto.color = ColorRGBA(0.0, 1.0, 0.0, 0.8)
51  rospy.loginfo("%s late landing", ref_st.header.frame_id)
52  elif [x.states[i].state.state for x in ref_contact_states_queue] == [ContactState.ON] * buffer_size and [x.states[i].state.state for x in act_contact_states_queue] == [ContactState.ON] * buffer_size:
53  picto.character = "up-bold"
54  picto.size = 1
55  picto.pose.orientation = Quaternion(0, -1, 0, 1)
56  picto.action = Pictogram.ADD
57  picto.color = ColorRGBA(1.0, 0.0, 0.0, 0.8)
58  rospy.loginfo("%s early taking off %s [s]", ref_st.header.frame_id, str(ref_st.state.remaining_time))
59  else:
60  continue
61  picto.header.frame_id = ref_st.header.frame_id
62  picto.header.stamp = ref_st.header.stamp
63  arr.pictograms.append(picto)
64  if len(arr.pictograms) > 0:
65  pub.publish(arr)
66  ref_contact_states_queue.pop(0)
67  act_contact_states_queue.pop(0)
68  ref_contact_states_queue.append(ref)
69  act_contact_states_queue.append(act)
70 
71 if __name__ == "__main__":
72  rospy.init_node("landing_time_detector")
73 
74  pub = rospy.Publisher("~pictogram_array", PictogramArray)
75  ref_contact_states_sub = message_filters.Subscriber('~input_ref', ContactStatesStamped)
76  act_contact_states_sub = message_filters.Subscriber('~input_act', ContactStatesStamped)
77 
78  buffer_size = 5
79  ref_contact_states_queue = []
80  act_contact_states_queue = []
81 
82  ts = message_filters.TimeSynchronizer([ref_contact_states_sub, act_contact_states_sub], 10)
83  ts.registerCallback(callback)
84 
85  rospy.spin()
msg
message_filters::Subscriber
landing_time_detector.callback
def callback(ref, act)
Definition: landing_time_detector.py:15
message_filters::TimeSynchronizer


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Fri Dec 13 2024 03:49:56