Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrunettini committed Jul 31, 2018
2 parents 62d2481 + 479d075 commit 686bbd4
Show file tree
Hide file tree
Showing 180 changed files with 5,331 additions and 3,992 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()

# Main project
project(YARP
VERSION 3.0.1
VERSION 3.0.102
LANGUAGES C CXX)
set(PROJECT_DESCRIPTION "YARP: A thin middleware for humanoid robots and more")

Expand Down
2 changes: 1 addition & 1 deletion bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if (_nested_build)
# bindings for other languages to be compiled from the build material.

# Install main CMakeLists and Swig input file
foreach(f CMakeLists.txt yarp.i README.md)
foreach(f CMakeLists.txt yarp.i macrosForMultipleAnalogSensors.i matlab/vectors_fromTo_matlab.i README.md)
install(FILES ${CMAKE_SOURCE_DIR}/bindings/${f}
COMPONENT development
DESTINATION ${CMAKE_INSTALL_DATADIR}/yarp/bindings)
Expand Down
11 changes: 7 additions & 4 deletions bindings/lua/tests/test_vocab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
require("yarp")

function test_vocab()
vocab = yarp.Vocab.encode("abcd")
vocab = yarp.encode("abcd")
assert("number" == type(vocab))
assert(1684234849 == vocab)
assert("abcd" == yarp.Vocab.decode(vocab))
assert("abcd" == yarp.decode(vocab))
vocab2 = yarp.createVocab('a','b','c','d')
assert("number" == type(vocab2))
assert (vocab == vocab2)
end

function test_vocab_pixel_types_enum()
Expand All @@ -27,10 +30,10 @@ function test_vocab_global_scope()
assert("number" == type(yarp.VOCAB_CM_POSITION))
assert(7565168 == yarp.VOCAB_CM_POSITION) -- VOCAB3
assert(1685286768 == yarp.VOCAB_CM_POSITION_DIRECT) -- VOCAB4
assert(845375334 == yarp.VOCAB_FRAMEGRABBER_CONTROL2) -- VOCAB4 with '2'
assert(6514534 == yarp.VOCAB_FRAMEGRABBER_CONTROL) -- VOCAB4
end

test_vocab()
test_vocab_pixel_types_enum()
--test_vocab_global_scope() -- Requires SWIG_VERSION >= 0x030011 (3.0.11), see yarp.i
test_vocab_global_scope()

58 changes: 58 additions & 0 deletions bindings/macrosForMultipleAnalogSensors.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (C) 2018 Istituto Italiano di Tecnologia (IIT)
// All rights reserved.
//
// This software may be modified and distributed under the terms of the
// BSD-3-Clause license. See the accompanying LICENSE file for details.

%define RESET_CONSTANTS_IN_EXTENDED_ANALOG_SENSOR_INTERFACE
#undef ThreeAxisGyroscopes_EXTENDED_INTERFACE
#undef ThreeAxisLinearAccelerometers_EXTENDED_INTERFACE
#undef ThreeAxisMagnetometers_EXTENDED_INTERFACE
#undef OrientationSensors_EXTENDED_INTERFACE
#undef TemperatureSensors_EXTENDED_INTERFACE
#undef SixAxisForceTorqueSensors_EXTENDED_INTERFACE
#undef ContactLoadCellArrays_EXTENDED_INTERFACE
#undef EncoderArrays_EXTENDED_INTERFACE
#undef SkinPatches_EXTENDED_INTERFACE
%enddef

%define EXTENDED_ANALOG_SENSOR_INTERFACE(sensor)

RESET_CONSTANTS_IN_EXTENDED_ANALOG_SENSOR_INTERFACE

#define sensor ## _EXTENDED_INTERFACE 1

std::string get ## sensor ## Name(int sens_index) const {
std::string name;
bool ok = self->get ## sensor ## Name(sens_index,name);
if (!ok) return "unknown";
return name;
}

#if !ContactLoadCellArray_EXTENDED_INTERFACE \
&& !EncoderArray_EXTENDED_INTERFACE \
&& !SkinPatch_EXTENDED_INTERFACE
std::string get ## sensor ## FrameName(int sens_index) const {
std::string frameName;
bool ok = self->get ## sensor ## FrameName(sens_index,frameName);
if (!ok) return "unknown";
return frameName;
}
#endif

#if OrientationSensor_EXTENDED_INTERFACE
double get ## sensor ## MeasureAsRollPitchYaw(int sens_index, yarp::sig::Vector& rpy) const {
double timestamp;
bool ok = self->get ## sensor ## MeasureAsRollPitchYaw(sens_index, rpy, timestamp);
#else
double get ## sensor ## Measure(int sens_index, yarp::sig::Vector& out) const {
double timestamp;
bool ok = self->get ## sensor ## Measure(sens_index, out, timestamp);
#endif
if (!ok) return -1;
return timestamp;
}

#undef sensor ## _EXTENDED_INTERFACE

%enddef
61 changes: 0 additions & 61 deletions bindings/matlab/IVector_fromTo_matlab.i

This file was deleted.

108 changes: 108 additions & 0 deletions bindings/matlab/vectors_fromTo_matlab.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
// All rights reserved.
//
// This software may be modified and distributed under the terms of the
// BSD-3-Clause license. See the accompanying LICENSE file for details.

%define RESET_CONSTANTS_IN_TO_MATLAB
#undef mxCreateDoubleMatrixHasComplexFlagParam
#undef mxCreateLogicalMatrixHasComplexFlagParam
%enddef

%define TO_MATLAB(matlabType,mxArrayInitializer)

// Convert to a Matlab vector
mxArray * toMatlab() const
{
// create Matlab vector and map it to pointer 'd'
size_t selfDim = self->size();
#if mxArrayInitializer ## HasComplexFlagParam
mxArray *p = mxArrayInitializer(selfDim, 1, mxREAL);
#else
mxArray *p = mxArrayInitializer(selfDim, 1);
#endif
matlabType* d = static_cast<matlabType*>(mxGetData(p));

// copy items from 'self' to 'd'
for(size_t i=0; i<selfDim; i++)
{
d[i] = static_cast<matlabType>(self->operator[](i));
}
return p;
}

%enddef


%define FROM_MATLAB(matlabType,cppType,mxArrayInitializer,vectorClass)

// Convert from a Matlab vector
void fromMatlab(mxArray * in)
{
// check size
const mwSize * dims = mxGetDimensions(in);
size_t selfDim = self->size();
size_t matlabVecDim = (dims[0] == 1 ? dims[1] : dims[0]);

if (matlabVecDim == selfDim)
{
// map Matlab vector to pointer 'd'
matlabType* d = static_cast<matlabType*>(mxGetData(in));

// copy items from 'd' to 'self'
for(size_t i=0; i<selfDim; i++)
{
self->operator[](i) = static_cast<cppType>(d[i]);
}
return;
} else {
mexErrMsgIdAndTxt("yarp::vectorClass::wrongDimension",
"Wrong vector size. Matlab size: %d. vectorClass size: %d", matlabVecDim, selfDim);
}
}

%enddef


%define RESET(resetValue)

// Reset values
void zero()
{
for(size_t i=0; i < self->size(); i++)
{
self->operator[](i) = resetValue;
}
return;
}

%enddef

RESET_CONSTANTS_IN_TO_MATLAB
#define mxCreateDoubleMatrixHasComplexFlagParam 1

%extend std::vector<double> {
TO_MATLAB(double,mxCreateDoubleMatrix)
FROM_MATLAB(double,double,mxCreateDoubleMatrix,DVector)
RESET(0)
}

%extend std::vector<bool> {
TO_MATLAB(bool,mxCreateLogicalMatrix)
FROM_MATLAB(bool,bool,mxCreateLogicalMatrix,BVector)
RESET(false)
}

%extend std::vector<int> {
TO_MATLAB(double,mxCreateDoubleMatrix)
FROM_MATLAB(double,int,mxCreateDoubleMatrix,IVector)
RESET(0)
}

%extend yarp::sig::VectorOf<double> {
TO_MATLAB(double,mxCreateDoubleMatrix)
FROM_MATLAB(double,double,mxCreateDoubleMatrix,yarp::sig::VectorOf<double>)
RESET(0)
}

RESET_CONSTANTS_IN_TO_MATLAB
Loading

0 comments on commit 686bbd4

Please sign in to comment.