Skip to content

Commit

Permalink
[DQ_CoppeliaSimInterfaceZMQ_py.cpp] Added DQ_CoppeliaSimInterfaceZMQ …
Browse files Browse the repository at this point in the history
…python binding and module.
  • Loading branch information
Murilo M. Marinho committed Nov 26, 2024
1 parent 72d7e53 commit bdded28
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

26 changes: 26 additions & 0 deletions dqrobotics/interfaces/coppeliasim/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
#
# ################################################################
#
# Contributors:
# - Murilo M. Marinho, email: [email protected]
#
# ################################################################
"""
from dqrobotics._dqrobotics._interfaces._coppeliasim import *
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
5 changes: 5 additions & 0 deletions src/dqrobotics_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace py = pybind11;
#include <dqrobotics/interfaces/vrep/robots/YouBotVrepRobot.h>
#include <dqrobotics/interfaces/vrep/robots/FrankaEmikaPandaVrepRobot.h>

#include <dqrobotics/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ.h>

#include <dqrobotics/interfaces/json11/DQ_JsonReader.h>

using namespace DQ_robotics;
Expand Down Expand Up @@ -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);

Expand Down
103 changes: 103 additions & 0 deletions src/interfaces/coppeliasim/DQ_CoppeliaSimInterfaceZMQ_py.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
Contributors:
1. Murilo M. Marinho ([email protected])
- 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<DQ_CoppeliaSimInterfaceZMQ>
> 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<std::string>&, const VectorXd&))&DQ_CoppeliaSimInterfaceZMQ::set_joint_positions,
"Set joint positions");

dqcsinterfacezmq_py.def("set_joint_target_positions",
(void (DQ_CoppeliaSimInterfaceZMQ::*) (const std::vector<std::string>&, const VectorXd&))&DQ_CoppeliaSimInterfaceZMQ::set_joint_target_positions,
"Set joint positions");

dqcsinterfacezmq_py.def("get_joint_positions",
(VectorXd (DQ_CoppeliaSimInterfaceZMQ::*) (const std::vector<std::string>&))&DQ_CoppeliaSimInterfaceZMQ::get_joint_positions,
"Get joint positions");

}

0 comments on commit bdded28

Please sign in to comment.