From bdded28bf2b89a8fc83a6e90d0189fbfb96f8a05 Mon Sep 17 00:00:00 2001 From: "Murilo M. Marinho" Date: Tue, 26 Nov 2024 10:29:22 +0000 Subject: [PATCH] [DQ_CoppeliaSimInterfaceZMQ_py.cpp] Added DQ_CoppeliaSimInterfaceZMQ python binding and module. --- CMakeLists.txt | 2 +- dqrobotics/interfaces/coppeliasim/__init__.py | 26 +++++ setup.py | 1 + src/dqrobotics_module.h | 5 + .../DQ_CoppeliaSimInterfaceZMQ_py.cpp | 103 ++++++++++++++++++ 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 dqrobotics/interfaces/coppeliasim/__init__.py create mode 100644 src/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ_py.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a64783d..823bfbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,6 @@ pybind11_add_module(_dqrobotics interfaces/cpp-interface-coppeliasim-zmq/submodules/zmqRemoteApi/clients/cpp/RemoteAPIClient.cpp interfaces/cpp-interface-coppeliasim-zmq/src/dqrobotics/interfaces/coppeliasim/internal/_zmq_wrapper.cpp interfaces/cpp-interface-coppeliasim-zmq/src/dqrobotics/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ.cpp - interfaces/cpp-interface-coppeliasim-zmq/src/dqrobotics/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQExperimental.cpp + src/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ_py.cpp ) diff --git a/dqrobotics/interfaces/coppeliasim/__init__.py b/dqrobotics/interfaces/coppeliasim/__init__.py new file mode 100644 index 0000000..213e860 --- /dev/null +++ b/dqrobotics/interfaces/coppeliasim/__init__.py @@ -0,0 +1,26 @@ +""" +# Copyright (c) 2019-2022 DQ Robotics Developers +# +# This file is part of DQ Robotics. +# +# DQ Robotics 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. +# +# DQ Robotics 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 DQ Robotics. If not, see . +# +# ################################################################ +# +# Contributors: +# - Murilo M. Marinho, email: murilo@g.u-tokyo.ac.jp +# +# ################################################################ +""" +from dqrobotics._dqrobotics._interfaces._coppeliasim import * diff --git a/setup.py b/setup.py index 06a9d9a..ff8176c 100644 --- a/setup.py +++ b/setup.py @@ -111,6 +111,7 @@ def build_extension(self, ext): 'dqrobotics.interfaces.vrep', 'dqrobotics.interfaces.vrep.robots', 'dqrobotics.interfaces.json11', + 'dqrobotics.interfaces.coppeliasim', 'dqrobotics.robot_control', 'dqrobotics.solvers'], classifiers=[ diff --git a/src/dqrobotics_module.h b/src/dqrobotics_module.h index a82c140..5e4ef06 100644 --- a/src/dqrobotics_module.h +++ b/src/dqrobotics_module.h @@ -70,6 +70,8 @@ namespace py = pybind11; #include #include +#include + #include using namespace DQ_robotics; @@ -112,6 +114,9 @@ void init_DQ_VrepInterface_py(py::module& m); void init_DQ_VrepRobot_py(py::module& m); void init_DQ_SerialVrepRobot_py(py::module& m); +//dqrobotics/interfaces/coppeliasim +void init_DQ_CoppeliaSimInterfaceZMQ_py(py::module& m); + //dqrobotics/interfaces/json11 void init_DQ_JsonReader_py(py::module& m); diff --git a/src/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ_py.cpp b/src/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ_py.cpp new file mode 100644 index 0000000..d590488 --- /dev/null +++ b/src/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ_py.cpp @@ -0,0 +1,103 @@ +/** +(C) Copyright 2019-2024 DQ Robotics Developers + +This file is part of DQ Robotics. + + DQ Robotics 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. + + DQ Robotics 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 DQ Robotics. If not, see . + +Contributors: +1. Murilo M. Marinho (murilomarinho@ieee.org) + - Initial implementation. + +*/ + +#include "../../dqrobotics_module.h" + +//Default arguments added with: +//https://pybind11.readthedocs.io/en/stable/basics.html#default-args + +void init_DQ_CoppeliaSimInterfaceZMQ_py(py::module& m) +{ + /***************************************************** + * VrepInterface + * **************************************************/ + py::class_< + DQ_CoppeliaSimInterfaceZMQ, + std::shared_ptr + > dqcsinterfacezmq_py(m,"DQ_CoppeliaSimInterfaceZMQ"); + dqcsinterfacezmq_py.def(py::init<>()); + + dqcsinterfacezmq_py.def("connect",(bool (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const int&, const int&, const int&))&DQ_CoppeliaSimInterfaceZMQ::connect,"Connects to CoppeliaSim with a given ip."); + + dqcsinterfacezmq_py.def("disconnect", &DQ_CoppeliaSimInterfaceZMQ::disconnect,"Disconnects from CoppeliaSim."); + dqcsinterfacezmq_py.def("disconnect_all",&DQ_CoppeliaSimInterfaceZMQ::disconnect_all,"Disconnect all from CoppeliaSim"); + + dqcsinterfacezmq_py.def("start_simulation",&DQ_CoppeliaSimInterfaceZMQ::start_simulation,"Start simulation"); + dqcsinterfacezmq_py.def("stop_simulation", &DQ_CoppeliaSimInterfaceZMQ::stop_simulation,"Stops simulation"); + + dqcsinterfacezmq_py.def("set_synchronous", (void (DQ_CoppeliaSimInterfaceZMQ::*) (const bool&))&DQ_CoppeliaSimInterfaceZMQ::set_synchronous, "Sets synchronous mode"); + + dqcsinterfacezmq_py.def("trigger_next_simulation_step", &DQ_CoppeliaSimInterfaceZMQ::trigger_next_simulation_step, "Sends a synchronization trigger signal to the server."); + + dqcsinterfacezmq_py.def("wait_for_simulation_step_to_end", &DQ_CoppeliaSimInterfaceZMQ::wait_for_simulation_step_to_end, "Waits until the simulation step is finished."); + + dqcsinterfacezmq_py.def("get_object_translation", + (DQ (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const std::string&))&DQ_CoppeliaSimInterfaceZMQ::get_object_translation, + "Gets object translation."); + + dqcsinterfacezmq_py.def("set_object_translation", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const DQ&, const std::string&))&DQ_CoppeliaSimInterfaceZMQ::set_object_translation, + "Sets object translation."); + + dqcsinterfacezmq_py.def("get_object_rotation", + (DQ (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const std::string&))&DQ_CoppeliaSimInterfaceZMQ::get_object_rotation, + "Gets object rotation."); + + dqcsinterfacezmq_py.def("set_object_rotation", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const DQ&))&DQ_CoppeliaSimInterfaceZMQ::set_object_rotation, + "Sets object rotation."); + + dqcsinterfacezmq_py.def("get_object_pose", + (DQ (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const std::string&))&DQ_CoppeliaSimInterfaceZMQ::get_object_pose, + "Gets object pose."); + + dqcsinterfacezmq_py.def("set_object_pose", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const DQ&, const std::string&))&DQ_CoppeliaSimInterfaceZMQ::set_object_pose, + "Sets object pose."); + + dqcsinterfacezmq_py.def("set_joint_position", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const double&))&::DQ_CoppeliaSimInterfaceZMQ::set_joint_positions, + "Set joint position"); + + dqcsinterfacezmq_py.def("set_joint_target_position", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&, const double&))&DQ_CoppeliaSimInterfaceZMQ::set_joint_target_positions, + "Set joint target position"); + + dqcsinterfacezmq_py.def("get_joint_position", + (double (DQ_CoppeliaSimInterfaceZMQ::*) (const std::string&))&::DQ_CoppeliaSimInterfaceZMQ::get_joint_positions, + "Get joint position"); + + dqcsinterfacezmq_py.def("set_joint_positions", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::vector&, const VectorXd&))&DQ_CoppeliaSimInterfaceZMQ::set_joint_positions, + "Set joint positions"); + + dqcsinterfacezmq_py.def("set_joint_target_positions", + (void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::vector&, const VectorXd&))&DQ_CoppeliaSimInterfaceZMQ::set_joint_target_positions, + "Set joint positions"); + + dqcsinterfacezmq_py.def("get_joint_positions", + (VectorXd (DQ_CoppeliaSimInterfaceZMQ::*) (const std::vector&))&DQ_CoppeliaSimInterfaceZMQ::get_joint_positions, + "Get joint positions"); + +}