Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ services:
&& ros2 run sas_common sas_object_test_node
&& ros2 run sas_common sas_object_client_manager_test_node
&& ros2 run sas_common test_python_wrapper.py
&& ros2 run sas_common test_object_client_manager_wrapper.py
&& ros2 run sas_common sas_simulator_test_node"
5 changes: 3 additions & 2 deletions sas_common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
compiled extension module :mod:`sas_common._sas_common` for convenience.

Exports:
- rclcpp_Init: Initialize rclcpp
- rclcpp_init: Initialize rclcpp
- rclcpp_Node: Node wrapper exposed from the C++ extension
- rclcpp_spin_some: Spin the node briefly
- rclcpp_shutdown: Shutdown rclcpp
- ObjectClient, SimulatorClient: C++ client wrappers for object/simulator control
- ObjectClientManager: Manager for multiple ObjectClient instances

"""

from sas_common._sas_common import rclcpp_init, rclcpp_Node, rclcpp_spin_some, rclcpp_shutdown, ObjectClient, SimulatorClient
from sas_common._sas_common import rclcpp_init, rclcpp_Node, rclcpp_spin_some, rclcpp_shutdown, ObjectClient, SimulatorClient, ObjectClientManager
75 changes: 75 additions & 0 deletions scripts/test_object_client_manager_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/python3
"""
# Copyright (c) 2026 Murilo Marques Marinho
#
# This file is part of sas_common.
#
# sas_common is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# sas_common is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with sas_common. If not, see <https://www.gnu.org/licenses/>.
#
# #######################################################################################
#
# Author: Murilo M. Marinho, email: murilomarinho@ieee.org
#
# #######################################################################################
"""
"""Test script for the ObjectClientManager Python bindings.

This script demonstrates usage of the ObjectClientManager exposed via
the sas_common Python package. It initializes rclcpp, creates a node,
instantiates an ObjectClientManager, and exercises add/remove/get/list operations.

Run with: python3 test_object_client_manager_wrapper.py
"""
from dqrobotics import *
from sas_common import rclcpp_init, rclcpp_Node, rclcpp_spin_some, rclcpp_shutdown, ObjectClientManager

def main():
"""Run a basic smoke-test for the ObjectClientManager Python bindings."""
try:
rclcpp_init()
node = rclcpp_Node("sas_common_object_client_manager_test_node")

mgr = ObjectClientManager(node)
print("Initial size:", mgr.size())

mgr.add_client("arm")
mgr.add_client("hand")
print("Size after adding arm and hand:", mgr.size())

print("Has arm:", mgr.has_client("arm"))
print("Has hand:", mgr.has_client("hand"))
print("Has gripper:", mgr.has_client("gripper"))
print("Client names:", mgr.get_client_names())

arm = mgr.get_client("arm")
print("Arm enabled:", arm.is_enabled())
print("Arm topic prefix:", arm.get_topic_prefix())

x = DQ([1])
arm.send_pose(x)

removed = mgr.remove_client("hand")
print("Removed hand:", removed)
print("Size after removal:", mgr.size())
print("Client names after removal:", mgr.get_client_names())

rclcpp_spin_some(node)
rclcpp_shutdown()
except KeyboardInterrupt:
print("Interrupted by user")
except Exception as e:
print("Unhandled exception:", e)

if __name__ == '__main__':
main()
27 changes: 27 additions & 0 deletions src/sas_common_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
#
# ################################################################*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <rclcpp/rclcpp.hpp>

#include <sas_common/sas_object_client.hpp>
#include <sas_common/sas_object_client_manager.hpp>
#include <sas_common/sas_simulator_client.hpp>

namespace py = pybind11;
using OC = sas::ObjectClient;
using OCM = sas::ObjectClientManager;
using SC = sas::SimulatorClient;

PYBIND11_MODULE(_sas_common, m) {
Expand Down Expand Up @@ -65,4 +68,28 @@ PYBIND11_MODULE(_sas_common, m) {
.def("is_enabled",&SC::is_enabled,"Returns true if the SimulatorClient is enabled.")
.def("get_topic_prefix",&SC::get_topic_prefix,
"Return the topic/service prefix configured for this client.");

py::class_<OCM>(m, "ObjectClientManager")
.def(py::init<const std::shared_ptr<rclcpp::Node>&>(),
py::arg("node"),
"Construct an ObjectClientManager that manages multiple ObjectClient instances.")
.def("add_client", &OCM::add_client,
py::arg("name"),
"Add (or replace) an ObjectClient identified by name.")
.def("remove_client", &OCM::remove_client,
py::arg("name"),
"Remove an ObjectClient by name. Returns True if found and removed.")
.def("get_client", [](OCM& self, const std::string& name) -> OC& {
return self.get_client(name);
},
py::arg("name"),
py::return_value_policy::reference_internal,
"Return a reference to the managed ObjectClient named `name`.")
.def("has_client", &OCM::has_client,
py::arg("name"),
"Return True if a client with the given name exists.")
.def("get_client_names", &OCM::get_client_names,
"Return a list of all managed client names.")
.def("size", &OCM::size,
"Return the number of managed clients.");
}