Skip to content

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

License

Notifications You must be signed in to change notification settings

juanjqo/dqrobotics-interface-coppeliasim

Repository files navigation

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

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

Static Badge This project is deprecated. The supported version is now in the DQ Robotics.

dqrobotics-interface-coppeliasim (Matlab ≥ 2023b, C++17, 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 than the legacy remote API. However, unlike DQ Robotics, dqrobotics-interface-coppeliasim is experimental and lacks official support.

Static Badge SO Status (C++17) Status (Python) Status (Matlab ≥ R2023b)
Static Badge macOS Static Badge Static Badge Static Badge Static Badge
Static Badge Static Badge Ubuntu {22.04, 24.04} LTS Static Badge Static Badge Static Badge Static Badge Static Badge
Static Badge Static Badge Windows 11 Static Badge Static Badge Static Badge Static Badge Static Badge

Basic requirements (for C++ users)

  • MacOS users require Homebrew

  • Windows users require vcpkg (C:\vcpkg)

    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
  • Download and install CoppeliaSim ≥ v4.7.0-rev0 (Use CoppeliaSim arm64 for Apple Silicon Macs)

Install DQ Robotics for C++

Skip these steps if you already have DQ Robotics installed.

MacOS (Apple Silicon)

brew install eigen
git clone https://github.com/dqrobotics/cpp.git
cd cpp
mkdir build && cd build
cmake ..
make -j16
sudo make install

Ubuntu

sudo add-apt-repository ppa:dqrobotics-dev/development -y
sudo apt-get update
sudo apt-get install libdqrobotics

Windows

Instructions missing here!

Additional requirements:

MacOS (Apple Silicon)

brew install pkg-config cppzmq eigen

Ubuntu

sudo apt install libzmq3-dev

Windows

Required vcpkg packages:

.\vcpkg install cppzmq

Build and Install (UNIX)

Example for coppeliasim-v4.8.0-rev0. Note: ⚠️ replace coppeliasim-v4.8.0-rev0 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.8.0-rev0
cd ../.. 
mkdir build && cd build
cmake ..
make -j16
sudo make install

Additional step for Ubuntu users:

sudo ldconfig

To Uninstall

Go to the build folder, and run:

sudo xargs rm < install_manifest.txt

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 .

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)

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published