This document provides comprehensive documentation for the Python wrapper methods defined in python_api.cpp
. The wrapper uses pybind11 to expose C++ functionality to Python.
- Module: pydsr
- Submodule: signals
- Class: Attribute
- Class: Edge
- Class: Node
- Class: DSRGraph
- Class: rt_api
- Class: inner_api
The main module for DSR API in Python.
import pydsr
DSR Api for python - Provides access to the Distributed Scene Graph (DSR) functionality.
Connect functions to DSR signals. The types of the signals are defined in the signal_type
enum.
Enum values:
UPDATE_NODE
UPDATE_NODE_ATTR
UPDATE_EDGE
UPDATE_EDGE_ATTR
DELETE_EDGE
DELETE_NODE
DELETE_NODE_OBJ
DELETE_EDGE_OBJ
signals.connect(graph, signal_type, callback_function)
Connect a callback function to a specific signal type.
Parameters:
graph
: DSRGraph - The graph instance to connect tosignal_type
: signal_type - The type of signal to connect tocallback_function
: function - The callback function to be called when the signal is emitted
Function Signatures for Callbacks:
UPDATE_NODE
:function(int, str) -> None
UPDATE_NODE_ATTR
:function(int, [str]) -> None
UPDATE_EDGE
:function(int, int, str) -> None
UPDATE_EDGE_ATTR
:function(int, int, [str]) -> None
DELETE_EDGE
:function(int, int, str) -> None
DELETE_NODE
:function(int) -> None
DELETE_NODE_OBJ
:function(pydsr.Node) -> None
DELETE_EDGE_OBJ
:function(pydsr.Edge) -> None
Represents an attribute in the DSR system.
Attribute(value, timestamp, agent_id)
Attribute(value, agent_id)
Attribute(value)
Parameters:
value
: The value of the attribute (various types supported)timestamp
: uint64_t - Timestamp in nanoseconds (optional)agent_id
: uint32_t - ID of the agent (optional)
attribute.agent_id
Read the agent_id attribute. This property is readonly and is updated when a change is made in the value property.
attribute.timestamp
Read the timestamp (ns) attribute. This property is readonly and is updated when a change is made in the value property.
attribute.value
attribute.value = new_value
Read or assign a new value to the Attribute object.
repr(attribute)
Returns a string representation of the attribute.
Represents an edge in the DSR graph.
Edge(to, from, type, agent_id)
Parameters:
to
: uint64_t - Destination node IDfrom
: uint64_t - Origin node IDtype
: str - Type of the edgeagent_id
: uint32_t - ID of the agent
edge.type
Read the type of the edge. This property is readonly.
edge.origin
Read the origin node of the edge. This property is readonly.
edge.destination
Read the destination node of the edge. This property is readonly.
edge.agent_id
edge.agent_id = new_agent_id
Read or assign a new value to the agent_id attribute.
edge.attrs
edge.attrs = new_attrs
Read or write in the attribute map of the edge.
repr(edge)
Returns a string representation of the edge.
Represents a node in the DSR graph.
Node(agent_id, type, name="")
Parameters:
agent_id
: uint32_t - ID of the agenttype
: str - Type of the nodename
: str - Name of the node (optional, default="")
node.id
Read the id of the node. This property is readonly and is generated by the idserver agent when the node is inserted.
node.name
Read the name of the node. This property is readonly. If the name is not provided to the constructor or the name already exists in G, the name is generated by the idserver agent with a combination of the type and the id when the node is inserted.
node.type
Read the type of the node. This property is readonly.
node.agent_id
node.agent_id = new_agent_id
Read or assign a new value to the agent_id attribute.
node.attrs
node.attrs = new_attrs
Read or write in the attribute map of the node.
node.edges
node.edges = new_edges
Read or write in the edge map of the node.
repr(node)
Returns a string representation of the node.
node.get_edges()
Returns a list of all edges connected to the node.
Returns:
- List of Edge objects
Represents the Distributed Scene Graph.
DSRGraph(root, name, id, dsr_input_file="", all_same_host=True)
Parameters:
root
: int - Root node IDname
: str - Name of the graphid
: int - ID of the agentdsr_input_file
: str - Input file path (optional, default="")all_same_host
: bool - Whether all agents are on the same host (optional, default=True)
graph.get_agent_id()
Get the agent ID.
Returns:
- uint32_t - Agent ID
graph.get_agent_name()
Get the agent name.
Returns:
- str - Agent name
graph.get_node(id)
graph.get_node(name)
Return the node with the id or name passed as parameter.
Parameters:
id
: uint64_t - ID of the nodename
: str - Name of the node
Returns:
- Node or None - Returns None if the node does not exist
graph.delete_node(id)
graph.delete_node(name)
Delete the node with the given id or name.
Parameters:
id
: uint64_t - ID of the nodename
: str - Name of the node
Returns:
- bool - Result of the operation
graph.insert_node(node)
Insert a new node in the graph.
Parameters:
node
: Node - Node to insert
Returns:
- uint64_t or None - ID of the node or None if the Node already exists in the map
graph.update_node(node)
Update the node in the graph.
Parameters:
node
: Node - Node to update
Returns:
- bool - Result of the operation
graph.get_edge(from, to, type)
Return the edge with the parameters from, to, and type.
Parameters:
from
: uint64_t or str - Origin node ID or nameto
: uint64_t or str - Destination node ID or nametype
: str - Type of the edge
Returns:
- Edge or None - Returns None if the edge does not exist
graph.insert_or_assign_edge(edge)
Insert or update an edge.
Parameters:
edge
: Edge - Edge to insert or update
Returns:
- bool - Result of the operation
graph.delete_edge(from, to, type)
Remove an edge.
Parameters:
from
: uint64_t or str - Origin node ID or nameto
: uint64_t or str - Destination node ID or nametype
: str - Type of the edge
Returns:
- bool - Result of the operation
graph.get_node_root()
Return the root node.
Returns:
- Node - Root node
graph.get_nodes_by_type(type)
Return all the nodes with a given type.
Parameters:
type
: str - Type of the nodes
Returns:
- List of Node objects
graph.get_nodes()
Returns all nodes in the graph.
Returns:
- List of Node objects
graph.get_name_from_id(id)
Return the name of a node given its id.
Parameters:
id
: uint64_t - ID of the node
Returns:
- str - Name of the node
graph.get_id_from_name(name)
Return the id from a node given its name.
Parameters:
name
: str - Name of the node
Returns:
- uint64_t - ID of the node
graph.get_edges()
Return all the edges in the graph.
Returns:
- List of Edge objects
graph.get_edges_by_type(type)
Return all the edges with a given type.
Parameters:
type
: str - Type of the edges
Returns:
- List of Edge objects
graph.get_edges_to_id(id)
Return all the edges that point to the node.
Parameters:
id
: uint64_t - ID of the node
Returns:
- List of Edge objects
graph.write_to_json_file(file, skip_atts=[])
Write the graph to a JSON file.
Parameters:
file
: str - Path to the output fileskip_atts
: List[str] - List of attributes to skip (optional, default=[])
Real-time API for the DSR graph.
rt_api(graph)
Parameters:
graph
: DSRGraph - The graph instance
rt.insert_or_assign_edge_RT(node, to, trans, rot_euler)
Insert or assign an RT edge.
Parameters:
node
: Node - Origin nodeto
: uint64_t - Destination node IDtrans
: List[float] - Translation vectorrot_euler
: List[float] - Rotation in Euler angles
rt_api.get_edge_RT(node, to)
Get an RT edge.
Parameters:
node
: Node - Origin nodeto
: uint64_t - Destination node ID
Returns:
- Edge or None
rt.get_RT_pose_from_parent(node)
Get the RT pose from the parent node.
Parameters:
node
: Node - Node to get the pose from
Returns:
- 4x4 transformation matrix or None
rt.get_edge_RT_as_rtmat(edge, timestamp=0)
Get the RT edge as a transformation matrix.
Parameters:
edge
: Edge - Edge to get the transformation fromtimestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 4x4 transformation matrix or None
rt.get_translation(node_id, to, timestamp=0)
Get the translation vector.
Parameters:
node_id
: uint64_t - Origin node IDto
: uint64_t - Destination node IDtimestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 3D vector or None
Inner Eigen API for the DSR graph.
inner_api(graph)
Parameters:
graph
: DSRGraph - The graph instance
inner.transform(orig, dest, timestamp=0)
inner.transform(orig, vector, dest, timestamp=0)
Transform a point or vector from one frame to another.
Parameters:
orig
: str - Origin framedest
: str - Destination framevector
: 3D vector - Vector to transform (optional)timestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 3D vector or None
inner.transform_axis(orig, dest, timestamp=0)
inner.transform_axis(orig, vector, dest, timestamp=0)
Transform an axis from one frame to another.
Parameters:
orig
: str - Origin framedest
: str - Destination framevector
: 6D vector - Vector to transform (optional)timestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 6D vector or None
inner.get_transformation_matrix(orig, dest, timestamp=0)
Get the transformation matrix between two frames.
Parameters:
orig
: str - Origin framedest
: str - Destination frametimestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 4x4 transformation matrix or None
inner.get_rotation_matrix(orig, dest, timestamp=0)
Get the rotation matrix between two frames.
Parameters:
orig
: str - Origin framedest
: str - Destination frametimestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 3x3 rotation matrix or None
inner.get_translation_vector(orig, dest, timestamp=0)
Get the translation vector between two frames.
Parameters:
orig
: str - Origin framedest
: str - Destination frametimestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 3D vector or None
inner.get_euler_xyz_angles(orig, dest, timestamp=0)
Get the Euler angles (XYZ) between two frames.
Parameters:
orig
: str - Origin framedest
: str - Destination frametimestamp
: uint64_t - Timestamp (optional, default=0)
Returns:
- 3D vector (Euler angles) or None