def run_trial_tf(self, policy, time_to_run=5): """ Run an async controller from a policy. The async controller receives observations from ROS subscribers and then uses them to publish actions.""" should_stop = False consecutive_failures = 0 start_time = time.time() while should_stop is False: if self.observations_stale is False: consecutive_failures = 0 last_obs = tf_obs_msg_to_numpy(self._tf_subscriber_msg) action_msg = tf_policy_to_action_msg(self.dU, self._get_new_action(policy, last_obs), self.current_action_id) self._tf_publish(action_msg) self.observations_stale = True self.current_action_id += 1 else: rospy.sleep(0.01) consecutive_failures += 1 if time.time() - start_time > time_to_run and consecutive_failures > 5: # we only stop when we have run for the trial time and are no longer receiving obs. should_stop = True rospy.sleep(0.25) # wait for finished trial to come in. result = self._trial_service._subscriber_msg return result # the trial has completed. Here is its message.
def run_trial_tf(self, policy, time_to_run=5): """ Run an async controller from a policy. The async controller receives observations from ROS subscribers and then uses them to publish actions.""" should_stop = False consecutive_failures = 0 start_time = time.time() while should_stop is False: if self.observations_stale is False: consecutive_failures = 0 last_obs = tf_obs_msg_to_numpy(self._tf_subscriber_msg) action_msg = tf_policy_to_action_msg( self.dU, self._get_new_action(policy, last_obs), self.current_action_id) self._tf_publish(action_msg) self.observations_stale = True self.current_action_id += 1 else: rospy.sleep(0.01) consecutive_failures += 1 if time.time( ) - start_time > time_to_run and consecutive_failures > 5: # we only stop when we have run for the trial time and are no longer receiving obs. should_stop = True rospy.sleep(0.25) # wait for finished trial to come in. result = self._trial_service._subscriber_msg return result # the trial has completed. Here is its message.
def _get_obs(self, msg, condition): return tf_obs_msg_to_numpy(msg)