stabilizer_watcher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # A script to watch stabilizer status
4 
5 from hrpsys_ros_bridge.srv import OpenHRP_StabilizerService_getParameter as getParameter
6 import rospy
7 from std_msgs.msg import Empty
8 from sound_play.msg import SoundRequest
9 from hrpsys_ros_bridge.msg import ContactStatesStamped, ContactStateStamped, ContactState
10 from hrpsys_ros_bridge.msg import MotorStates
11 
12 # global variable
13 g_previous_st_controller_mode = None
14 is_servo_on = False
15 
17  is_lleg_contact = None
18  is_rleg_contact = None
19  for state in msg.states:
20  if state.header.frame_id == "lfsensor":
21  if state.state.state == ContactState.ON:
22  is_lleg_contact = True
23  else:
24  is_lleg_contact = False
25  if state.header.frame_id == "rfsensor":
26  if state.state.state == ContactState.ON:
27  is_rleg_contact = True
28  else:
29  is_rleg_contact = False
30  if is_lleg_contact or is_rleg_contact:
31  return "MODE_ST"
32  else:
33  return "MODE_AIR"
34 
35 def isChangedControllerMode(actual_from, actual_to, expected_from, expected_to):
36  if (actual_from in expected_from and
37  actual_to == expected_to):
38  return True
39  else:
40  return False
41 
42 def trig():
43  global is_servo_on
44  g_odom_init_trigger_pub.publish(Empty())
45  if is_servo_on is False:
46  return
47  # Say something
48  sound = SoundRequest()
49  sound.sound = SoundRequest.SAY
50  sound.command = SoundRequest.PLAY_ONCE
51  if hasattr(SoundRequest, 'volume'): # volume is added from 0.3.0 https://github.com/ros-drivers/audio_common/commit/da9623414f381642e52f59701c09928c72a54be7#diff-fe2d85580f1ccfed4e23a608df44a7f7
52  sound.volume = 1.0
53  sound.arg = "Robot stands on the ground."
54  g_robotsound_pub.publish(sound)
55 
57  global g_previous_st_controller_mode
58  global g_odom_init_trigger_pub, g_robotsound_pub
59  controller_mode = controllerModeToString(msg)
60  if (controller_mode == "MODE_AIR" or
61  controller_mode == "MODE_IDLE" or
62  controller_mode == "MODE_ST"):
63  if g_previous_st_controller_mode == None:
64  g_previous_st_controller_mode = controller_mode
65  if controller_mode == "MODE_ST":
66  trig()
67  else:
68  if isChangedControllerMode(g_previous_st_controller_mode,
69  controller_mode,
70  ["MODE_AIR", "MODE_IDLE"],
71  "MODE_ST"):
72  trig()
73  g_previous_st_controller_mode = controller_mode
74 
76  global is_servo_on
77  is_servo_on = any(msg.servo_state)
78 
79 if __name__ == "__main__":
80  rospy.init_node("stabilizer_watcher")
81  contact_states_sub = rospy.Subscriber("/act_contact_states", ContactStatesStamped, contactStatesCallback, queue_size=1)
82  motor_states_sub = rospy.Subscriber("/motor_states", MotorStates, motorStatesCallback, queue_size=1)
83  g_odom_init_trigger_pub = rospy.Publisher("/odom_init_trigger", Empty, queue_size=1)
84  g_robotsound_pub = rospy.Publisher("/robotsound", SoundRequest, queue_size=1)
85  rospy.spin()
86 
def isChangedControllerMode(actual_from, actual_to, expected_from, expected_to)


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