/dqrobotics-interface-coppeliasim

An unofficial DQ Robotics interface for Matlab and C++20 to connect with CoppeliaSim based on ZeroMQ remote API.

Primary LanguageC++GNU Lesser General Public License v3.0LGPL-3.0

Static BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeGitHub LicenseStatic Badge

dqrobotics-interface-coppeliasim (Matlab ≥ 2023b, C++20, and CoppeliaSim ≥ v4.7.0-rev0)

An unofficial DQ Robotics interface to connect with CoppeliaSim based on ZeroMQ remote API. This API provides more functionalities when compared to the legacy remote API (the one used by the DQ Robotics interface). However, unlike DQ Robotics, dqrobotics-interface-coppeliasim is experimental and lacks official support.

CoppeliaSim SO Status (C++20) Status (Python) Status (Matlab ≥ R2023b)
Static BadgeStatic Badge macOS (Apple Silicon) Static Badge Static Badge Static Badge
Static BadgeStatic Badge Ubuntu 22.04 LTS (arm64, x64) Static Badge Static Badge Static Badge
Static BadgeStatic Badge Windows 11 (arm64, x64) Static Badge Static Badge Static Badge

Don't use this interface for your project! ⚠️

Static Badge This project is under active development, incomplete, and experimental/unstable. Therefore, I highly recommend the official DQ Robotics interface if you want stability and outstanding technical support.

Feature Status (C++20) Status (Python) Status (Matlab ≥ R2023b)
Implementation 🚧 under construction 🚀 -- 🚧 under construction 🐢
Documentation 🚧 under construction 🚀 -- 📌 planned
Unit Testing 🚧 under construction 🚀 -- 📌 planned
Packages 📌 planned -- 📌 planned

The C++20 version is the baseline, and you could expect it to be the most stable, reliable, and better-supported version.

Basic requirements (for C++ users)

MacOS (Apple Silicon)

brew install pkg-config cppzmq

Ubuntu

sudo apt install libzmq3-dev

Windows

If you do not have vcpkg:

cd C:/
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg; .\bootstrap-vcpkg.bat
.\vcpkg.exe integrate install

Required vcpkg packages:

.\vcpkg install cppzmq

Download and install CoppeliaSim ≥ v4.7.0-rev0 (Use CoppeliaSim arm64 for Apple Silicon Macs)

Build and Install (UNIX)

Example for coppeliasim-v4.7.0-rev2. Note: ⚠️ replace coppeliasim-v4.7.0-rev2 with the actual CoppeliaSim version you have (≥ v4.7.0-rev0).

git clone https://github.com/juanjqo/dqrobotics-interface-coppeliasim --recursive
cd dqrobotics-interface-coppeliasim/coppeliarobotics/zmqRemoteApi
git checkout coppeliasim-v4.7.0-rev2
cd ../.. && mkdir build && cd build
cmake ..
make -j16
sudo make install

Additional step for Ubuntu users:

sudo ldconfig

Build and Install (Windows)

Run powershell as administrator:

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake ..
cmake --build . --config Release
cmake --install .

To Uninstall

sudo xargs rm < install_manifest.txt

Example (Find more examples here)

  1. Open CoppeliaSim. (You do not need to load a specific scene).
  2. Run and enjoy!

ezgif com-video-to-gif-converter (1)

#include <dqrobotics/DQ.h>
#include <dqrobotics/interfaces/coppeliasim/DQ_CoppeliaSimInterface.h>
#include <dqrobotics/interfaces/coppeliasim/robots/URXCoppeliaSimRobot.h>

using namespace DQ_robotics;
using namespace Eigen;

VectorXd compute_control_signal(const MatrixXd& J,
                                const VectorXd& q,
                                const double& damping,
                                const double& gain,
                                const VectorXd& task_error);

int main()
{
    auto vi = std::make_shared<DQ_CoppeliaSimInterface>();
    vi->connect();

    // Load the models only if they are not already on the scene.
    vi->load_from_model_browser("/robots/non-mobile/UR5.ttm", "/UR5");
    vi->load_from_model_browser("/other/reference frame.ttm", "/Current_pose");
    vi->load_from_model_browser("/other/reference frame.ttm", "/Desired_pose");
    vi->start_simulation();

    auto robot = URXCoppeliaSimRobot("/UR5", vi, URXCoppeliaSimRobot::MODEL::UR5);
    auto robot_model = robot.kinematics();
    robot.set_robot_as_visualization_tool();

    auto q = robot.get_configuration_space_positions();
    double gain = 10;
    double T = 0.001;
    double damping = 0.01;

    auto xd = robot_model.fkm(((VectorXd(6) <<  0.5, 0, 1.5, 0, 0, 0).finished()));
    vi->set_object_pose("/Desired_pose", xd);

    for (int i=0; i<300; i++)
    {
        auto x = robot_model.fkm(q);
        vi->set_object_pose("/Current_pose", x);
        auto J =  robot_model.pose_jacobian(q);
        auto Jt = robot_model.translation_jacobian(J, x);
        auto task_error = (x.translation()-xd.translation()).vec4();
        auto u = compute_control_signal(Jt, q, damping, gain, task_error);
        q = q + T*u;
        robot.set_control_inputs(q);
        std::cout<<"error: "<<task_error.norm()<<std::endl;
    }
    vi->stop_simulation();
}

VectorXd compute_control_signal(const MatrixXd& J,
                                const VectorXd& q,
                                const double& damping,
                                const double& gain,
                                const VectorXd& task_error)
{
    VectorXd u = (J.transpose()*J + damping*damping*MatrixXd::Identity(q.size(), q.size())).inverse()*
        J.transpose()*(-gain*task_error);
    return u;
}
add_executable(${CMAKE_PROJECT_NAME} main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME}
                      dqrobotics
                      dqrobotics-interface-coppeliasim)