Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings for Multiple Analog Sensors interfaces #1756

Conversation

nunoguedelha
Copy link
Contributor

@nunoguedelha nunoguedelha commented Jun 18, 2018

Motivation

After the integration of the multiple analog sensors interfaces and respective devices (refer to #1526, #1586, #1676) we need to access those interfaces from scripting languages like Matlab, and so, create the respective bindings.
On top of that, some redundant code is cluttering the SWIG interface file yarp.i, which can be avoided by using the appropriate macros.

Description

Added bindings for Multiple Analog Sensors interfaces :

  • minor refactoring of main header MultipleAnalogSensorsInterfaces.h defining the interfaces
  • added main header to yarp/dev/all.h for a proper inclusion of the interfaces definitions in the mex source files yarpXXX_wrap.cxx
  • include main interfaces header in yarp.i and wrapped the cast functions (PolyDriver*)->view(<sensor_interface*>) for each one of the interfaces
  • extended the new interfaces for wrapping the methods which Swig struggles to handle

Did some refactoring in the SWIG interface file yarp.i for reducing redundant code :

  • all wrappers for casting from PolyDriver to specific device interfaces are now generated through a Swig macro.
  • all new class extensions are done using a Swig macro defined in macrosForMultipleAnalogSensors.i
  • refactored the from/toMatlab() wrappers and extended them to the classes : std::vector<double>, std::vector<bool>, std::vector<int>.

(std::vector<std::string> is a bit more tricky and was left out for now.)

  • Update the changelog

@nunoguedelha
Copy link
Contributor Author

nunoguedelha commented Jun 18, 2018

CC @traversaro @fjandrad

@nunoguedelha
Copy link
Contributor Author

@traversaro , I'm still completing the last point (impacting IVector_fromTo_matlab.i), but you can already review the other changes in the current commits.

@Nicogene Nicogene added PR Type: Feat/Enh This PR adds some new feature or enhances some part of YARP Component: Bindings swig, python, java, ruby, perl, octave, matlab, lua, csharp, tcl Type: Cleanup Involves cleaning up some part of YARP Target: YARP v3.1.0 PR Status: Changelog - Not OK This PR does not have a changelog entry, or the changelog needs to be fixed labels Jun 18, 2018
@Nicogene
Copy link
Member

Please add few lines in the changelog

@Nicogene Nicogene added the PR Status: Rebase - Not OK This PR needs to be rebased over the latest commit in the target branch label Jun 19, 2018
@Nicogene
Copy link
Member

Please rebase over the latest devel and resolve the conflict, thanks!

@traversaro
Copy link
Member

By the way, the conflicts are probably due to #1757 , i.e. CAST_POLYDRIVER_TO_INTERFACE needs to be used also with the IInterfaceControl.

@jgvictores
Copy link
Member

@nunoguedelha CAST_POLYDRIVER_TO_INTERFACE looks really cool, I believe it's something for which I couldn't come up with a solution within #1607. Thanks!

Regarding the files added within the PR, I'd like to share a small concern.

#698 was open due to a new file bindings/things.i (included by distributed yarp.i) being added to YARP but not distributed within the YARP Windows binary installer. This was fixed by the removal of bindings/things.i.

This PR adds bindings/macrosForMultipleAnalogSensors.i and bindings/matlab/vectors_fromTo_matlab.i (both for inclusion by yarp.i). Does anybody (@mbrunettini @traversaro @drdanz ?) know how/where the YARP Windows binary installer packaging is done to avoid reaching the same situation?

@traversaro
Copy link
Member

Regarding the files added within the PR, I'd like to share a small concern.

I am not 100% sure, but I guess it should be sufficient to add all the files that we want to install to https://github.com/robotology/yarp/blob/devel/bindings/CMakeLists.txt#L91 . All the installation logic should be there, I would expect the Windows installer to just collect what is installed by the CMake install target and put in the installer.

@PeterBowman
Copy link
Member

Does anybody (...) know how/where the YARP Windows binary installer packaging is done to avoid reaching the same situation?

@jgvictores see robotology/yarp-packaging. Per /windows/README.txt:

(...) Everything is built with CMake, so you can always search for the relevant *.sln file and open it to build manually.

- small refactoring of main header MultipleAnalogSensorsInterfaces.h
  defining the insterfaces
- added main header to yarp/dev/all.h for a proper inclusion of  the
  interfaces definitions in the mex source files yarpXXX_wrap.cxx
- include main interfaces header in `yarp.i` and wrapped the cast
  functions `(PolyDriver*)->view(<sensor_interface*>)` for each one
  of the interfaces
- extended the interface `IThreeAxisGyroscopes` for wrapping the
  methods hard to handle by Swig
- all extensions are done as for `IThreeAxisGyroscopes`, and using
  a Swig macro defined in `macrosForMultipleAnalogSensors.i`
- all wrappers for casting from PolyDriver to specific device interfaces
  are now generated through a Swig macro.
Completed the extension of the classes std::vector<double>,
std::vector<bool>, std::vector<int>, yarp::sig::Vector with
these wrappers.
@nunoguedelha nunoguedelha force-pushed the feature/addMultipleAnalogSensorsBindings branch from f8260a7 to a71047a Compare June 19, 2018 14:38
@nunoguedelha
Copy link
Contributor Author

@traversaro @PeterBowman Thanks for the clarifications.

@nunoguedelha nunoguedelha changed the title WIP: Add bindings for Multiple Analog Sensors interfaces Add bindings for Multiple Analog Sensors interfaces Jun 19, 2018
@Nicogene Nicogene added PR Status: Changelog - OK This PR has a proper changelog entry PR Status: Rebase - OK This PR does not need to be rebased and removed PR Status: Changelog - Not OK This PR does not have a changelog entry, or the changelog needs to be fixed labels Jun 19, 2018
@Nicogene Nicogene removed the PR Status: Rebase - Not OK This PR needs to be rebased over the latest commit in the target branch label Jun 19, 2018
Copy link
Member

@Nicogene Nicogene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I will merge it as soon as the test passes, thanks!

@jgvictores
Copy link
Member

Should https://github.com/nunoguedelha/yarp/blob/feature/addMultipleAnalogSensorsBindings/bindings/CMakeLists.txt#L91 be changed from:

foreach(f CMakeLists.txt yarp.i README.md)

to:

foreach(f CMakeLists.txt yarp.i README.md macrosForMultipleAnalogSensors.i matlab/vectors_fromTo_matlab.i)

or similar?

@Nicogene
Copy link
Member

Nicogene commented Jun 20, 2018

So is it needed an additional change in bindings/CMakeLists.txt before merging right?

@jgvictores
Copy link
Member

That's what I've understood from the comments above. : )

@traversaro
Copy link
Member

Yep, @nunoguedelha can you do the modification?

…from the build material

(typically for such files to be found by the windows installer)
@nunoguedelha
Copy link
Contributor Author

Sure, done.

@Nicogene Nicogene merged commit 13121aa into robotology:devel Jun 23, 2018
@Nicogene
Copy link
Member

Merged, thanks!

@jgvictores
Copy link
Member

jgvictores commented Jun 29, 2018

After some thought on #1776, pretty sure this will suffer from matlab/vectors_fromTo_matlab.i losing the matlab/ path, and will therefore not be found by yarp.i. Commenting here as this (matlab/vectors_fromTo_matlab.i) has been merged to devel, whereas #1776 affects master.

@PeterBowman
Copy link
Member

After some thought on #1776, pretty sure this will suffer from matlab/vectors_fromTo_matlab.i losing the matlab/ path...

Confirming that vectors_fromTo_matlab.i is installed into <prefix>/share/yarp/bindings/ while <prefix>/share/yarp/bindings/matlab/ is expected.

...and will therefore not be found by yarp.i.

Can't test it by myself, but I'm curious about the following lines (introduced by this PR):

yarp/bindings/yarp.i

Lines 452 to 455 in 4bca59c

#ifdef SWIGMATLAB
// Extend IVector for handling conversion of vectors from and to Matlab
%include "matlab/vectors_fromTo_matlab.i"
#endif

There is no SWIGMATLAB macro listed in the SWIG docs. How does it actually get defined?

@nunoguedelha
Copy link
Contributor Author

Confirming that vectors_fromTo_matlab.i is installed into /share/yarp/bindings/ while /share/yarp/bindings/matlab/ is expected

@PeterBowman @jgvictores this is indeed a real issue and is being addressed. The bindings used to be generated using directly the yarp.i interface file from the source directory. The generation process is being improved and will use the file from the install directory (robotology/yarp-matlab-bindings#35), and along with this, the issue on vectors_fromTo_matlab.i path will be fixed.

There is no SWIGMATLAB macro listed in the SWIG docs. How does it actually get defined?

this flag is defined directly in the Mex library source file yarp-matlab-bindings/matlab/autogenerated/yarpMATLAB_wrap.cxx generated by SWIG.

@traversaro
Copy link
Member

The issue mentioned by @PeterBowman is blocking robotology/yarp-matlab-bindings#35 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Bindings swig, python, java, ruby, perl, octave, matlab, lua, csharp, tcl PR Status: Changelog - OK This PR has a proper changelog entry PR Status: Rebase - OK This PR does not need to be rebased PR Type: Feat/Enh This PR adds some new feature or enhances some part of YARP Resolution: Merged Target: YARP v3.1.0 Type: Cleanup Involves cleaning up some part of YARP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants