Esempio n. 1
0
 def _update_timestamp_filter(self, timestamp, timesync_endpoint):
     """Set or convert fields of the proto that need timestamps in the robot's clock."""
     # Input timestamp is a google.protobuf.Timestamp
     if not timesync_endpoint:
         raise NoTimeSyncError("[choreography service] No timesync endpoint set for the robot.")
     converter = _TimeConverter(self, timesync_endpoint)
     return converter.robot_timestamp_from_local_secs(timestamp)
Esempio n. 2
0
    def _update_time_filter(self, timestamp, timesync_endpoint):
        """Set or convert fields of the proto that need timestamps in the robot's clock.

        Args:
            timestamp (float): Client time, such as from time.time().
            timesync_endpoint (TimeSyncEndpoint): A timesync endpoint associated with the robot object.

        Raises:
            NoTimeSyncError: Could not find the timesync endpoint for the robot to convert the time.
        """
        # Input timestamp is a float. (from time.time())
        if not timesync_endpoint:
            raise NoTimeSyncError("[world object service] No timesync endpoint set for the robot.")
        # Lazy RobotTimeConverter: initialized only if needed to make a conversion.
        converter = _TimeConverter(self, timesync_endpoint)
        return converter.robot_timestamp_from_local_secs(timestamp)
Esempio n. 3
0
    def _update_timestamp_filter(self, timestamp, timesync_endpoint):
        """Set or convert fields of the proto that need timestamps in the robot's clock.

        Args:
            timestamp (google.protobuf.Timestamp): Client time.
            timesync_endpoint (TimeSyncEndpoint): A timesync endpoint associated with the robot object.

        Raises:
            NoTimeSyncError: Could not find the timesync endpoint for the robot to convert the time.
        """
        # Input timestamp is a google.protobuf.Timestamp
        if not timesync_endpoint:
            raise NoTimeSyncError("[world object service] No timesync endpoint set for the robot.")
        converter = _TimeConverter(self, timesync_endpoint)
        converter.convert_timestamp_from_local_to_robot(timestamp)
        return timestamp
Esempio n. 4
0
    def _update_command_timestamps(self, command):
        """Set or convert fields of the command proto that need timestamps in the robot's clock.

        Args:
            command: Command message to update.
        """
        if self._timesync_endpoint is None:
            raise NoTimeSyncError

        converter = _TimeConverter(self, self._timesync_endpoint)

        def _to_robot_time(key, proto):
            """If proto has a field named key with a timestamp, convert timestamp to robot time."""
            if not (key in proto.DESCRIPTOR.fields_by_name and proto.HasField(key)):
                return  # No such field in proto, or field does not contain a timestamp.
            timestamp = getattr(proto, key)
            converter.convert_timestamp_from_local_to_robot(timestamp)

        # Convert timestamps from local time to robot time.
        _edit_proto(command, EDIT_TREE_CONVERT_LOCAL_TIME_TO_ROBOT_TIME, _to_robot_time)