Skip to content

Conversation

@ffasilva
Copy link
Member

@ffasilva ffasilva commented Feb 16, 2024

Hi, @dqrobotics/developers,

This PR adds an example of geting the inertial parameters of a cuboid on CoppeliaSim. The motivation is to test the new methods added to DQ_VrepInterface in 109.

The LUA child script on the scene cuboid_inertial_parameters.ttt diverges from the one used in the C++ examples. As they were, functions get_center_of_mass() and get_inertia() only returned the parameters with respect to either the shape frame or the inertial reference frame through an if-else check "is(reference frame == 'absolute_frame')". To allow arbitrary reference frames, the LUA function sim.getObjectMatrix needs to receive a handle (i.e., an int), which required the modifications. Namely, the reference frame is now passed as an inInts rather than an inStrings. I also removed unused arguments, renamed some variables, and added comments to make the functions clearer.

Kind regards,
Frederico

P.S.: As described in the .m file, the necessary scene is available in OSF.

@ffasilva
Copy link
Member Author

Hi @juanjqo,

I modified the Lua API to behave the same as the one you implemented for your C++ examples, while still allowing for arbitrary reference frames. Since the Lua script is somewhat of an add-on to the library, I believe having a slightly different version in some examples is not a problem.

Kind regards,
Frederico

@juanjqo
Copy link
Member

juanjqo commented Sep 13, 2024

@ffasilva thank you for your example. I recommend using try-catch blocks to finish the connection automatically if an execution error happens, especially when using the legacy remote API. Otherwise, the connection port remains open, and the user must close it manually or restart Matlab.

Layout example:

clear all;
close all;
clc;

include_namespace_dq;

vi = DQ_VrepInterface();

try
    vi.connect('127.0.0.1', 19997);
    vi.start_simulation();
    %-----------Your code here-------------------

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

catch ME
    vi.stop_simulation();
    vi.disconnect();
    rethrow(ME)
end

On the other hand, it looks like there is some bug when using BODY_FRAME arguments.

Minimal example:

clear all;
close all;
clc;

include_namespace_dq;

vi = DQ_VrepInterface();

try
   vi.connect('127.0.0.1', 19997);
   vi.start_simulation();

   % Get the Cuboid's handle
   handle = vi.get_handle('Cuboid');
   % Get the Cuboid's inertia matrix
   inertia_matrix_in_sf = vi.get_inertia_matrix(handle, vi.BODY_FRAME);
   disp('inertia matrix =')
   disp(inertia_matrix_in_sf)

   vi.stop_simulation();
   vi.disconnect();

catch ME
   vi.stop_simulation();
   vi.disconnect();
   rethrow(ME)
end

Output:

Arrays have incompatible sizes for this operation.

Error in DQ_VrepInterface/get_inertia_matrix (line 903)
               if(reference_frame == obj.ABSOLUTE_FRAME)

Error in untitled2 (line 18)
   inertia_matrix_in_sf = vi.get_inertia_matrix(handle,
   vi.BODY_FRAME);

Related documentation

Please let me know if you can reproduce the issue.

Best regards,

Juancho

@ffasilva
Copy link
Member Author

Hi @juanjqo

@ffasilva thank you for your example. I recommend using try-catch blocks to finish the connection automatically if an execution error happens, especially when using the legacy remote API. Otherwise, the connection port remains open, and the user must close it manually or restart Matlab.

I didn't add a try-catch block because I'm already checking for any previous connection that wasn't properly closed (e.g., due to an execution error).

%% V-REP setup
% Create a DQ_VrepInterface object and start communication with V-REP
vi = DQ_VrepInterface();

% Finish any previous V-REP communication
vi.stop_simulation();
vi.disconnect_all();

% Start a new connection
vi.connect('127.0.0.1',19997);
disp('Communication established!')

On the other hand, it looks like there is some bug when using BODY_FRAME arguments.

Thanks for pointing that out. I fixed it in d29125d.

Feel free to let me know if you have any more suggestions.

Kind regards,
Frederico

@juanjqo
Copy link
Member

juanjqo commented Oct 10, 2024

Thank you @ffasilva

It looks like everything is running well. My main concern is the duplication of the DQRoboticsApiCommandServer.lua, which is currently available in dqrobotics/cpp-examples. I think is impractical in terms of maintenance and support to have duplicate files. I recommend removing the one you are proposing here and using the one that is already in the DQ robotics.

Best regards,

Juancho

@ffasilva
Copy link
Member Author

Hi @juanjqo,

If we're only going to keep one file, I would suggest doing it the other way around and keeping this version of DQRoboticsApiCommandServer.lua. This one preserves the signature of the one in dqrobotics/cpp-examples and allows the user to choose arbitrary reference frames for the inertia tensor and CoM vector. Therefore, I don't see the benefit of keeping the older version.

Kind regards,
Frederico

@juanjqo
Copy link
Member

juanjqo commented Oct 11, 2024

Hi @ffasilva,

I think the modifications you are proposing in DQRoboticsApiCommandServer.lua are useful. However, any file modification must be proposed through a PR in the corresponding repository in which the file is located. Therefore, I would recommend proposing the changes that enable arbitrary reference frames in the file DQRoboticsApiCommandServer.lua in dqrobotics/cpp-examples.

Cheers,

Juancho

…ommandServer.lua'. It will be added in a different pull request to 'dqrobotics/cpp-examples'.
@ffasilva
Copy link
Member Author

Hi @juanjqo,

This makes sense. I've removed the .lua file from this pull request, and I'll open a different one for it in the cpp-examples.

Kind regards,
Frederico

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants