Data Buffer

Client for the data-buffer service.

This allows client code to log the following to the robot’s data buffer: text-messages, operator comments, blobs, signal ticks, and protobuf messages.

exception bosdyn.client.data_buffer.InvalidArgument[source]

Bases: Error

A given argument could not be used.

bosdyn.client.data_buffer.log_event(robot, event_type, level, description, start_timestamp_secs, end_timestamp_secs=None, id_str=None, parameters=None, log_preserve_hint=1)[source]

Add an Event to the Data Buffer.

Parameters:
  • robot – A Robot object.

  • event_type (string) – The type of event.

  • level (bosdyn.api.Event.Level) – The relative importance of the event.

  • description (string) – A human-readable description of the event.

  • start_timestamp_secs (float) – Start of the event, in local time.

  • end_timestamp_secs (float) – End of the event. start_timestamp_secs is used if None.

  • id_str (string) – Unique id for event. A uuid is generated if None.

  • parameters ([bosdyn.api.Parameter]) – Parameters to attach to the event.

  • log_preserve_hint (bosdyn.api.LogPreserveHint) – Whether event should try to preserve log data.

bosdyn.client.data_buffer.make_parameter(label, value, units='', notes='')[source]

Create a parameter proto from a label and the parameter value.

class bosdyn.client.data_buffer.DataBufferClient[source]

Bases: BaseClient

A client for adding to robot data buffer.

default_service_name = 'data-buffer'
service_type = 'bosdyn.api.DataBufferService'
update_from(other)[source]

Adopt key objects like processors, logger, and wallet from other.

add_text_messages(text_messages, **kwargs)[source]

Log text messages to the robot.

Parameters:

text_messages (List[TextMessage]) – Sequence of TextMessage protos.

Raises:

RpcError – Problem communicating with the robot.

add_text_messages_async(text_messages, **kwargs)[source]

Async version of add_text_messages.

add_operator_comment(msg, robot_timestamp=None, **kwargs)[source]

Add an operator comment to the robot log.

Parameters:
  • msg (string) – Text of user comment to log.

  • robot_timestamp (google.protobuf.Timestamp) – Time of messages, in robot time. If not set, timestamp will be when the robot receives the message.

Raises:

RpcError – Problem communicating with the robot.

add_operator_comment_async(msg, robot_timestamp=None, **kwargs)[source]

Async version of add_operator_comment.

add_blob(data, type_id, channel=None, robot_timestamp=None, write_sync=False, **kwargs)[source]

Log blob messages to the data buffer.

Parameters:
  • data (bytes) – Binary data of one blob.

  • type_id (string) – Type of binary data of blob. For example, this could be the full name of a protobuf message type.

  • channel (string) – The name by which messages are typically queried: often the same as type_id, or of the form ‘{prefix}/{type_id}’.

  • robot_timestamp (google.protobuf.Timestamp) – Time of messages, in robot time.

Raises:

RpcError – Problem communicating with the robot.

add_blob_async(data, type_id, channel=None, robot_timestamp=None, write_sync=False, **kwargs)[source]

Async version of add_blob.

add_protobuf(proto, channel=None, robot_timestamp=None, write_sync=False)[source]

Log protobuf messages to the data buffer.

Parameters:
  • proto (Protobuf message) – Serializable protobuf to log.

  • channel (string) – Name of channel for data. If not set defaults to proto type name.

  • robot_timestamp (google.protobuf.Timestamp) – Time of proto, in robot time.

Raises:

RpcError – Problem communicating with the robot.

add_protobuf_async(proto, channel=None, robot_timestamp=None, write_sync=False)[source]

Async version of add_protobuf.

add_events(events, **kwargs)[source]

Log event messages to the robot.

Parameters:

events (List[Event]) – Sequence of Event protos.

Raises:

RpcError – Problem communicating with the robot.

add_events_async(events, **kwargs)[source]

Async version of add_events.

register_signal_schema(variables, schema_name, **kwargs)[source]

Log signal schema to the robot.

Parameters:
  • variables (List[SignalSchema.Variable]) – List of SignalSchema variables defining what is in tick.

  • schema_name (string) – Name of schema (defined previously by client).

Raises:

RpcError – Problem communicating with the robot.

register_signal_schema_async(variables, schema_name, **kwargs)[source]

Async version of register_signal_schema

add_signal_tick(data, schema_id, encoding=1, sequence_id=0, source='client', **kwargs)[source]

Log signal data to the robot data buffer.

Schema should be sent before any ticks.

Parameters:
  • data (bytes) – Single hunk of binary data.

  • schema_id (int) – ID name of schema (obtained from a previous schema registration)

  • encoding (SignalTick.Encoding) – Encoding of the data

  • sequence_id (int) – Index of which sequence tick this is

  • source (string) – String name representing client

Raises:
  • RpcError – Problem communicating with the robot.

  • LookupError – The schema_id is unknown (not previously registered by this client)

add_signal_tick_async(data, schema_id, encoding=1, sequence_id=0, source='client', **kwargs)[source]

Async version of add_signal_tick.

now_in_robot_basis(msg_type=None, proto=None)[source]

Get current time in robot clock basis if possible, None otherwise.

class bosdyn.client.data_buffer.LoggingHandler(service, data_buffer_client, level=0, time_sync_endpoint=None, rpc_timeout=1, msg_num_limit=10, msg_age_limit=1, skip_rpcs=False)[source]

Bases: Handler

A logging system Handler that will publish text to the data-buffer service.

Parameters:
  • service – Name of the service. See LogAnnotationTextMessage.

  • data_buffer_client – API client that will send log messages.

  • level – Python logging level. Defaults to NOTSET.

  • time_sync_endpoint – A TimeSyncEndpoint, already synchronized to the remote clock.

  • rpc_timeout – Timeout on RPCs made by data_buffer_client.

  • msg_num_limit – If number of messages reaches this number, send data with data_buffer_client.

  • msg_age_limit – If messages have been sitting locally for this many seconds, send data with data_buffer_client.

  • skip_rpcs – Do not log any messages for RPC sending.

Raises:

log_annotation.InvalidArgument – The TimeSyncEndpoint is not valid.

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

flush()[source]

Ensure all logging output has been flushed.

This version does nothing and is intended to be implemented by subclasses.

close()[source]

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

is_thread_alive()[source]

Return true if send-thread is running.

restart(data_buffer_client)[source]

Restart the send thread.

Raises:

AssertionError if send thread is still alive.

static fallback_log(msg)[source]

Handle log messages that were failed to be sent by printing to the console.

record_to_msg(record: LogRecord)[source]

Convert logging record to TextMessage proto.

static record_level_to_proto_level(record_level)[source]

Convert logging record level to TextMessage proto level.

bosdyn.client.data_buffer.is_not_text_log(record: LogRecord) bool[source]

Filter out the RecordMessages calls that the handler sends so that we do not go into an infinite loop.

bosdyn.client.data_buffer.is_not_rpc(record: LogRecord) bool[source]

Because our loggers use the form sdk_name.robot_name.service_name.rpc_method, we can’t easily just turn off all logging for rpcs. This function identifies the rpc logging calls to be able to strip them out.