dqrobotics / cpp-interface-vrep

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

[master-v4.5.1-rev4] Update the `CMakelists` to include `simConst.h` correctly. #12

Closed juanjqo closed 11 months ago

juanjqo commented 11 months ago

@dqrobotics/developers

Hi @mmmarinho,

This PR updates the submodules and the header CMakelists in DQ_VrepInterface() to include simConst.h. On this branch, the synchronous mode is working properly on Ubuntu VM hosted on Windows, using CoppeliaSim 4.5.1. I'm going to do more tests in different setups.

Context: As discussed in Python/pull51, the synchronous mode is not working as expected in the current version (bd2f2cc) of the cpp-interface-vrep.

Minimal example:

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

int main()
{
    auto vi = DQ_VrepInterface();
    try {
        if (!vi.connect("10.198.113.136", 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));
        //---------------Your code here----------------------------

        double time_simulation_step = 0.05;
        double y_0 = vi.get_object_pose("/Sphere").translation().vec3()[2];
        double y_sim;
        double y_est;
        double t;
        std::cout<<"-----------------"<<std::endl;
        std::cout<<"Initial height: "<<y_0<<std::endl;
        std::cout<<"-----------------"<<std::endl;

        for (int i=0; i<=5; i++)
        {
            t = i*time_simulation_step;
            y_sim = vi.get_object_pose("/Sphere").translation().vec3()[2];
            y_est = y_0 - 0.5 * 9.81 * std::pow(t, 2);
            vi.trigger_next_simulation_step();
            vi.wait_for_simulation_step_to_end();
        }
        std::cout<<"Elapsed time: "<<t<<std::endl;
        std::cout<<"Estimated height: "<<y_est<<", Measured height: "<<y_sim<<std::endl;
        vi.stop_simulation();
        vi.disconnect();
    } catch (std::exception& e) {
        std::cout<<e.what()<<std::endl;
        vi.stop_simulation();
        vi.disconnect();
    }
    return 0;
}

Output

```shell
Estimated height: 0.693437, Measured height: 0.687306

Best regards,

Juancho