dqrobotics / cpp-interface-coppeliasim-zmq

A DQ Robotics interface for CoppeliaSim's ZeroMQ remote API.
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Static BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeStatic BadgeGitHub LicenseStatic Badge

cpp-interface-coppeliasim-zmq

A DQ Robotics interface based on the ZeroMQ remote API to connect with CoppeliaSim. This API provides more functionalities than the legacy remote API (the one used by the DQ Robotics interface).

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

Instructions for Developers

Basic requirements (for C++ users)

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

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 boost

Ubuntu

sudo apt install libzmq3-dev libboost-all-dev

Windows

Required vcpkg packages:

.\vcpkg install cppzmq

Build and Install (UNIX)

Example for coppeliasim-v4.8.0-rev0. Note: :warning: replace coppeliasim-v4.8.0-rev0 with your CoppeliaSim version (≥ v4.7.0-rev0).

git clone https://github.com/dqrobotics/cpp-interface-coppeliasim-zmq.git --recursive
cd cpp-interface-coppeliasim-zmq/submodules/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_CoppeliaSimInterfaceZMQExperimental.h>

using namespace DQ_robotics;
using namespace Eigen;

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

    //To enable experimental methods
    // 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");

    auto jointnames = vi->get_jointnames_from_parent_object("/UR5");
    vi->set_joint_modes(jointnames, DQ_CoppeliaSimInterfaceZMQExperimental::JOINT_MODE::DYNAMIC);
    vi->set_joint_control_modes(jointnames, DQ_CoppeliaSimInterfaceZMQExperimental::JOINT_CONTROL_MODE::VELOCITY);
    vi->enable_dynamics(true);
    vi->set_engine(DQ_CoppeliaSimInterfaceZMQExperimental::ENGINE::MUJOCO);
    vi->set_simulation_time_step(0.05);
    vi->set_stepping_mode(true);
    vi->draw_trajectory(jointnames.back(), 2, {1,0,1}, 1000);

    vi->start_simulation();

    auto qd = (VectorXd(6)<< 0.5, 0.5, 0.5,0.5,0.5,0.5).finished();
    auto q = vi->get_joint_positions(jointnames);
    VectorXd error = qd-q;
    double k = 0.1;

    double epsilon = 0.1;

    while (error.norm() > epsilon)
    {
        q = vi->get_joint_positions(jointnames);
        error = qd-q;
        auto u = k*error;
        vi->set_joint_target_velocities(jointnames, u);
        vi->trigger_next_simulation_step();
        std::cout<<"error: "<<error.norm()<<std::endl;
    }
    vi->stop_simulation();
}
add_executable(${CMAKE_PROJECT_NAME} main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME}
                      dqrobotics
                      dqrobotics-interface-coppeliasim-zmq)