dqrobotics / cpp-interface-vrep

Vrep interface for the dqrobotics in C++
GNU Lesser General Public License v3.0
3 stars 5 forks source link

Timeout Error when using vrep the second time[BUG] #18

Closed YuheGong closed 6 months ago

YuheGong commented 6 months ago

Hi all, there is a timeout error when using dqrobotics cpp interface. When I run the code at first time. Everything is fine. But when I run the second time. The error :

"Starting V-REP simulation... terminate called after throwing an instance of 'std::runtime_error' what(): Timeout in VREP communication. Error: {No Value Error} {Timeout Error} . The most common source of this error is that the object Franka_joint1 does not exist in the current scene in CoppeliaSim. Aborted (core dumped)"

happened.

And when I close the CoppeliaSim, open CoppeliaSim again, run the code. Everything goes well. That means, the code is just one-use, after running one time, I have to close Coppelia -> open Coppelia -> open the scence -> run the code -> close Coppelia again.

Only reload the scence doesn't solve the problem. I have tried to reinstall CoppeliaSim and vrep-dq-cpp-interface, both don't solve the problem.


My code to connect to vrep:

DQ_VrepInterface vi; vi.connect(19997,100,10); vi.set_synchronous(true); std::cout << "Starting V-REP simulation..." << std::endl; vi.start_simulation(); std::vector Jointnames = {"Franka_joint1", "Franka_joint2", "Franka_joint3", "Franka_joint4", "Franka_joint5", "Franka_joint6", "Franka_joint7"};


May I get some help to solve it? Thanks very much

Environment:

juanjqo commented 6 months ago

Hi @YuheGong,

The version 4.6.0-18 of CoppeliaSim is not currently supported by the DQ Robotics. Please let me know if the problem is present on a supported version.

Best regards,

Juan

Supported versions

(@mmmarinho, please correct me if I am wrong to update the information).

Branch CoppeliaSim
release v3.6.2
master v4.2.0-rev5
master-v4.4.0-rev0 v4.4.0-rev0
master-v4.5.1-rev4 v4.5.1-rev4

What version did I install if I used the official Ubuntu PPA?

Before to add or remove PPAs please check the official documention.

Release PPA

If you installed the DQ Robotics interface using the following commands:

sudo add-apt-repository ppa:dqrobotics-dev/release
sudo apt-get update
sudo apt-get install libdqrobotics-interface-vrep

Then, the supported version is the v3.6.2.

Development PPA

If you installed the DQ Robotics interface using the following commands:

DO NOT add both PPAs at once. If you already used the Release PPA, you first have to remove it. please check the official documention.

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

Then, the supported version is the v4.2.0-rev5.

Please note that in the development branch, you have the option to install other versions. For instance:

sudo apt-get install libdqrobotics-interface-vrep-4.4.0-0

or

sudo apt-get install libdqrobotics-interface-vrep-4.5.1-4

In those cases, the supported CoppeliaSim version is explicitly indicated.

mmmarinho commented 6 months ago

@juanjqo Thanks!

This is good advice and probably could be copy and pasted on https://dqroboticsgithubio.readthedocs.io/en/latest/installation/cpp.html#interface-packages

PS: Feel free to close the issue when it's about an unsupported version.

YuheGong commented 6 months ago

Hi all, thanks for your help!

I have installed vrep-4.5.1-4. But the problem still exists.

May I get further help?

Best regards,

Yuhe

juanjqo commented 6 months ago

@YuheGong sure thing!

Could you please provide a minimal working example and the scene you are using to reproduce your issue?

YuheGong commented 6 months ago

@juanjqo yuhe_vrep_test.zip

yes please! Thanks very much! Could you download and extract the file I attached? This is a mini example. And here is the codes I use to compile them:

[open CoppeliaSim] [go into yuhe_vrep_test folder] [open the joint_velocity_commands.ttt in coppeliasim subfolder] [go back to yuhe_vrep_test folder] rm -rf build mkdir build cmake .. make cd .. ./build/joint_velocity_commands

And then you may see that it runs for a long time with no print at all. Then the error occurs.

juanjqo commented 6 months ago

Hi @YuheGong, I was not able to reproduce the issue you are reporting. I installed the DQ Robotics interface of the development branch sudo apt-get install libdqrobotics-interface-vrep-4.5.1-4 and I am using CoppeliaSim 4.5-1-rev4. The code runs well every time. On the other hand, I did not know what you wanted to do by checking your code and the scene

Be aware that the FE Panda robot in your scene has joints working in velocity mode, but your code, which is set in synchronous mode, is trying to set joint positions by using the specific commands for asynchronous mode (Please check this for more information).

This is a minimal example that works with the scene you provided. This example runs in synchronous mode and implements a kinematic control in the joint space. Furthermore, the robot is commanded by joint velocities (this matches the joint modes of your robot).

#include <iostream>
#include <dqrobotics/interfaces/vrep/DQ_VrepInterface.h>
#include <thread>

int main()
{    
    auto vi = DQ_VrepInterface();
    try {
        if (!vi.connect("127.0.0.1", 19997,100,10))
            throw std::runtime_error("Unable to connect to CoppeliaSim.");
        vi.set_synchronous(true);
        vi.start_simulation();
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
        //----------------------------------------------------------
        std::vector<std::string> jointnames = {"Franka_joint1", "Franka_joint2",
                                            "Franka_joint3", "Franka_joint4",
                                            "Franka_joint5", "Franka_joint6",
                                            "Franka_joint7"};
        auto q_desired =(VectorXd(7)<< 0.5, 0.0,0,-1.57,0,1.57,0).finished();
        auto u      = VectorXd(7);
        auto q_current = VectorXd(7);
        auto q_error   = VectorXd(7);
        double epsilon = 0.01;
        double error   = 1;
        double gain = 5;

        while(error>epsilon)
        {
            q_current  = vi.get_joint_positions(jointnames);
            q_error = q_desired-q_current;
            u = gain*(q_error);
            vi.set_joint_target_velocities(jointnames, u);
            error = q_error.norm();

            vi.trigger_next_simulation_step();
            vi.wait_for_simulation_step_to_end();
            std::cout<<"error: "<<error<<std::endl;
        }

        //---------------------------------------------------------
        vi.stop_simulation();
        vi.disconnect();

    } catch (std::exception& e) {
        std::cout<<e.what()<<std::endl;
        vi.stop_simulation();
        vi.disconnect();
    }
    return 0;
}

Running the code more than one time

2024-03-1211-19-11-ezgif com-video-to-gif-converter

YuheGong commented 6 months ago

Hi @juanjqo Thanks for checking! Yes I also think it should be something about the dq-cpp-vrep interface wrong in my laptop. I ran the code you offered. And it shows :

Unable to connect to CoppeliaSim.

I think it means that the code cannot find the file right? There is something wrong in the connection.

juanjqo commented 6 months ago

@YuheGong for some reason, the connection between CoppeliaSim and the DQ Robotics Interface can not be established. Do you have other CoppeliaSim scenes open? Did you test restarting your Ubuntu SO to try again?

YuheGong commented 6 months ago

@juanjqo yes true! I reinstalled everything and reboot my ubuntu, it works! It is indeed some conflict between the different working windows and versions. Thanks so much for the help and checking my code! The synchronous mode and velocity control interface are indeed what we need for the experiment! :100: Thanks!

juanjqo commented 6 months ago

@juanjqo Glad to help!

YuheGong commented 6 months ago

@juanjqo By the way, a small simple question: the synchronous mode has a timestep dt = 0.001s right? And if the control command exceed 0.001s, will it report some error similar to the real robot: like "communication constraint violation" ?

bvadorno commented 6 months ago

Dear @YuheGong

@juanjqo By the way, a small simple question: the synchronous mode has a timestep dt = 0.001s right? And if the control command exceed 0.001s, will it report some error similar to the real robot: like "communication constraint violation" ?

This question is not related to the issue you opened. If you want to discuss it, please post it on the discussion forum if it hasn't been discussed there yet.

Kind regards, Bruno

YuheGong commented 6 months ago

@bvadorno Thanks Prof. Adorno! I just created a Q&A in the discussion form.

https://github.com/orgs/dqrobotics/discussions/16

Please feel free to take a look.

Best regards, Yuhe