def _update_next_subgait(self) -> GaitUpdate:
        """Update the next subgait.

        Behaves differently based on whether a new subgait has been scheduled early.
        First the next subgait is determined, which is based on the status of transitioning
        and whether the subgait has to be stopped.

        Then if the next subgait is not None the current subgait is replaced by the
        next subgait, and all appriopriate values are updated.

        If a new subgait hasn't been scheduled early, this function also returns a
        TrajectoryCommand.

        :return: optional trajectory_command, is_finished
        """
        if self._transition_to_subgait is not None and not self._is_transitioning:
            # We should schedule a transition subgait
            self._is_transitioning = True
            next_subgait = self._make_transition_subgait()
        elif self._transition_to_subgait is not None and self._is_transitioning:
            # A transition subgait has ended
            next_subgait = self.subgaits.get(
                self._transition_to_subgait.subgait_name)
            self._transition_to_subgait = None
            self._is_transitioning = False
        elif self._scheduled_early:
            # We scheduled early and already determined the next subgait
            next_subgait = self._next_subgait
        else:
            # We determine the next subgait with the subgait graph
            next_subgait = self._next_graph_subgait()

        # If there is no next subgait, then we are finished
        if next_subgait is None:
            return GaitUpdate.finished()

        # Update subgait and timestamps
        self._update_time_stamps(next_subgait)
        self._current_subgait = next_subgait

        # Schedule the next subgait if we haven't already scheduled early
        if not self._scheduled_early:
            return GaitUpdate.should_schedule(
                self._command_from_current_subgait())
        else:
            # Reset early schedule attributes
            self._scheduled_early = False
            self._next_subgait = None
            return GaitUpdate.subgait_updated()
    def update(self, current_time: Time) -> GaitUpdate:
        self._current_time = current_time
        if self._current_time < self._end_time or self._constructing:
            return GaitUpdate.empty()
        else:
            next_subgait = self._default_walk.graph[(
                self._current_subgait, self._default_walk.graph.TO)]

            if next_subgait == self._default_walk.graph.END:
                return GaitUpdate.finished()
            self._constructing = True
            self._current_subgait = next_subgait
            command = self._new_trajectory_command()
            self._constructing = False
            return GaitUpdate.should_schedule(command)
Beispiel #3
0
 def update(
     self,
     current_time: Time,
     early_schedule_duration: Optional[Duration] = ZERO_DURATION,
 ) -> GaitUpdate:
     """Give an update on the progress of the gait.
     :param current_time: Current time.
     :param early_schedule_duration: The duration to schedule the gait early.
     :returns Returns a GaitUpdate with only the is_finished set to either true or false.
     """
     if current_time >= self._end_time:
         return GaitUpdate.finished()
     elif self._scheduled_early and current_time > self._start_time:
         return GaitUpdate.subgait_updated()
     else:
         return GaitUpdate.empty()
    def _update_state_machine(self) -> GaitUpdate:
        """Update the state machine that the new subgait has begun.
        Also updates the starting position and time stamps for the
        next subgait.

        :returns: a GaitUpdate for the state machine
        :rtype: GaitUpdate
        """
        if self._next_command is None:
            return GaitUpdate.finished()

        self._update_start_pos()
        self._update_time_stamps(self._next_command.duration)
        self._scheduled_early = False

        return GaitUpdate.subgait_updated()