Util

Common utilities for API Python code.

bosdyn.util.duration_str(duration)[source]

Return a formatted string for a duration proto.

Parameters

duration (google.protobuf.Duration) – input duration

Returns

format ‘{seconds}.{nanoseconds}’.

Return type

string

bosdyn.util.duration_to_seconds(duration)[source]

Return a number of seconds, as a float, based on Duration protobuf fields.

If you want a precise duration, use the Duration class’s ToTimedelta function.

Parameters

duration (google.protobuf.Duration) – input duration

bosdyn.util.timestamp_str(timestamp)[source]

Return a formatted string for a timestamp or a duration proto.

Parameters

timestamp (google.protobuf.Timestamp or google.protobuf.Duration) – input duration

Returns

A string with format ‘{seconds}.{nanoseconds}’.

bosdyn.util.sec_to_nsec(secs)[source]

Convert time in seconds as from time.time() to a timestamp in nanoseconds.

Parameters

secs – Time in seconds

Returns

The time in nanoseconds, as an integer.

bosdyn.util.now_nsec()[source]

Returns nanoseconds from dawn of unix epoch until when this is called.

bosdyn.util.set_timestamp_from_now(timestamp_proto)[source]

Sets google.protobuf.Timestamp to point to the current time on the system clock.

Parameters

timestamp_proto[out] (google.protobuf.Timestamp) – The proto into which the time will be written

bosdyn.util.now_timestamp()[source]

Returns a google.protobuf.Timestamp set to the current time on the system clock.

bosdyn.util.set_timestamp_from_nsec(timestamp_proto, time_nsec)[source]

Writes a timestamp as an integer of nanoseconds from the unix epoch into a Timestamp proto

Parameters
  • timestamp_proto[out] (google.protobuf.Timestamp) – timestamp into which the time will be written

  • time_nsec[in] – the time, as an integer of nanoseconds from the unix epoch

bosdyn.util.nsec_to_timestamp(time_nsec)[source]

Returns a google.protobuf.Timestamp for a time from nanoseconds from the unix epoch.

Parameters

time_nsec (int) – the time, as an integer of nanoseconds from the unix epoch

bosdyn.util.timestamp_to_sec(timestamp_proto)[source]

Returns floating point of seconds from the unix epoch from a Timestamp proto.

Parameters

timestamp_proto (google.protobuf.Timestamp) – input time

bosdyn.util.timestamp_to_nsec(timestamp_proto)[source]

Returns integer of nanoseconds from the unix epoch from a Timestamp proto.

Parameters

timestamp_proto (google.protobuf.Timestamp) – input time

bosdyn.util.timestamp_to_datetime(timestamp_proto, use_nanos=True)[source]

Convert a google.protobuf.Timestamp to a Python datetime.datetime object.

Parameters
  • timestamp_proto (google.protobuf.Timestamp) – input time

  • use_nanos (bool) – use fractional seconds in proto (default=True)

Returns

a datetime.datetime proto

bosdyn.util.secs_to_hms(seconds)[source]

Format a time in seconds as ‘H:MM:SS’

Parameters

seconds – number of seconds (will be truncted to integer value)

bosdyn.util.distance_str(meters)[source]

Convert a distance in meters to a either xxx.xx m or xxx.xx km

Parameters

meters (float/int) – distance in meters

bosdyn.util.format_metric(metric)[source]

Returns a string representing a metric.

Parameters

metric (bosdyn.api.Parameter) – metric description

class bosdyn.util.RobotTimeConverter(robot_clock_skew_nsec)[source]

Bases: object

Converts times in the local system clock to times in the robot clock.

Conversions are made given an estimate of clock skew from the local clock to the robot clock.

robot_timestamp_from_local_nsecs(local_time_nsecs)[source]

Returns a robot-clock Timestamp proto for a local time in nanoseconds.

Parameters

local_time_nsecs – Local system time time, in integer of nanoseconds from the unix epoch.

robot_timestamp_from_local_secs(local_time_secs)[source]

Returns a robot-clock Timestamp proto for a local time in seconds.

Parameters

local_time_secs – Local system time time, in seconds from the unix epoch.

convert_timestamp_from_local_to_robot(timestamp_proto)[source]

Edits timestamp_proto in place to convert it from the local clock to the robot_clock.

Parameters

timestamp_proto[in/out] (google.protobuf.Timestamp) – local system time time