3 from geometry_msgs.msg
import TwistStamped, Twist
8 """Manages timeouts and relaying incoming messages for a given control input""" 12 def __init__(self, sub_topic, pub_topic, timeout, stamped, sub_is_stamped=True, publish_redundant_halts=True, frame_id=''):
21 self.
_sub_type = TwistStamped
if sub_is_stamped
else Twist
26 raise ValueError(
'Invalid `timeout` value for control_input: {TIMEOUT}' 27 .format(TIMEOUT=timeout))
29 if not isinstance(stamped, bool):
30 raise ValueError(
'Invalid `stamped` value for control_input: {STAMPED}' 31 .format(STAMPED=stamped))
37 'Configuring Command Input Handler\n' +
38 'Subscribed Topic: {TOPIC}\n'.format(TOPIC=self.
sub_topic) +
39 'Published Topic: {TOPIC}\n'.format(TOPIC=self.
pub_topic) +
40 'Timeout: {TIMEOUT}\n'.format(TIMEOUT=self.
timeout) +
41 'Input Topic Stamped: {STAMPED}\n'.format(STAMPED=self.
sub_is_stamped) +
42 'Output Topic Stamped: {STAMPED}\n'.format(STAMPED=self.
is_stamped) +
47 """Passes through message and strip strips header if necessary""" 49 twist_cmd = data.twist
58 if type(data) == TwistStamped
and self.
expired(data):
65 """Tests message stamp to see if it has timeout""" 66 now = rospy.Time.now()
67 return 0.0 < self.
timeout <= (now - data.header.stamp).to_sec()
76 data_stamped = TwistStamped()
77 data_stamped.header.frame_id = self.
frame_id 78 data_stamped.header.stamp = rospy.Time.now()
79 data_stamped.twist = data
84 """Creates a handle for each input. Drop inputs if timeout is not a number or 85 stamped is not a boolean. 90 for idx, control_input
in enumerate(control_inputs):
93 self.input_handles.append(command_handle)
94 except ValueError
as e:
95 rospy.logfatal(
'control_input manager ({IDX}) was not created. {params}' 96 .format(IDX=idx, params=control_input))
104 required_parameters = {
'pub_topic',
'sub_topic',
'timeout',
'stamped'}
105 optional_parameters = {
'sub_is_stamped',
'publish_redundant_halts'}
106 for control_input
in control_inputs:
107 params = set(control_input.keys())
108 missing_params = required_parameters - params
109 unrecognized_params = params - required_parameters - optional_parameters
110 if len(missing_params) != 0:
111 err_msg =
"Missing the parameters: " +
', '.join(list(missing_params))
112 raise ValueError(err_msg)
113 elif len(unrecognized_params) != 0:
114 rospy.logerr(
'Unrecognized parameters: ' +
', '.join(list(unrecognized_params)))
118 rospy.init_node(
'control_input_manager')
119 control_inputs = rospy.get_param(
'~control_inputs')
125 if __name__ ==
'__main__':