Skip to content

Commit

Permalink
ctrlLib defines math symbols to avoid referring to M_PI in the headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pattacini committed Dec 18, 2015
1 parent f1e0d37 commit 1966fb3
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 53 deletions.
5 changes: 2 additions & 3 deletions src/libraries/ctrlLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ include_directories(${PROJECT_SOURCE_DIR}/include
${GSL_INCLUDE_DIRS}
${YARP_INCLUDE_DIRS})

add_library(${PROJECT_NAME} ${folder_source} ${folder_header})

if(MSVC)
target_compile_definitions(${PROJECT_NAME} PUBLIC _USE_MATH_DEFINES)
add_definitions(-D_USE_MATH_DEFINES)
endif()

add_library(${PROJECT_NAME} ${folder_source} ${folder_header})
target_link_libraries(${PROJECT_NAME} ${GSL_LIBRARIES} ${YARP_LIBRARIES})

icub_export_library(${PROJECT_NAME} INTERNAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
Expand Down
20 changes: 15 additions & 5 deletions src/libraries/ctrlLib/include/iCub/ctrl/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,32 @@
#ifndef __CTRLMATH_H__
#define __CTRLMATH_H__

#include <cmath>

#include <yarp/sig/Vector.h>
#include <yarp/sig/Matrix.h>
#include <yarp/math/Math.h>

#define CTRL_RAD2DEG (180.0/M_PI)
#define CTRL_DEG2RAD (M_PI/180.0)


namespace iCub
{

namespace ctrl
{

/**
* The PI constant.
*/
extern const double CTRL_PI;

/**
* 180/PI.
*/
extern const double CTRL_RAD2DEG;

/**
* PI/180.
*/
extern const double CTRL_DEG2RAD;

/**
* \ingroup Maths
*
Expand Down
10 changes: 10 additions & 0 deletions src/libraries/ctrlLib/src/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ using namespace yarp::sig;
using namespace yarp::math;


/************************************************************************/
namespace iCub {
namespace ctrl {
const double CTRL_PI=M_PI;
const double CTRL_RAD2DEG=180.0/M_PI;
const double CTRL_DEG2RAD=M_PI/180.0;
}
}


/************************************************************************/
double iCub::ctrl::dot(const Matrix &A, int colA, const Matrix &B, int colB)
{
Expand Down
35 changes: 18 additions & 17 deletions src/libraries/iDyn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@
# Authors: Matteo Fumagalli, Serena Ivaldi
# CopyPolicy: Released under the terms of the GNU GPL v2.0.

SET(PROJECTNAME iDyn)
project(iDyn)

PROJECT(${PROJECTNAME})

SET(folder_source src/iDyn.cpp
set(folder_source src/iDyn.cpp
src/iDynInv.cpp
src/iDynBody.cpp
src/iDynTransform.cpp
src/iDynContact.cpp)

SET(folder_header include/iCub/iDyn/iDyn.h
set(folder_header include/iCub/iDyn/iDyn.h
include/iCub/iDyn/iDynInv.h
include/iCub/iDyn/iDynBody.h
include/iCub/iDyn/iDynTransform.h
include/iCub/iDyn/iDynContact.h)

SOURCE_GROUP("Source Files" FILES ${folder_source})
SOURCE_GROUP("Header Files" FILES ${folder_header})
source_group("Source Files" FILES ${folder_source})
source_group("Header Files" FILES ${folder_header})

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include
include_directories(${PROJECT_SOURCE_DIR}/include
${iKin_INCLUDE_DIRS}
${skinDynLib_INCLUDE_DIRS}
${GSL_INCLUDE_DIRS}
${YARP_INCLUDE_DIRS})

ADD_LIBRARY(${PROJECTNAME} ${folder_source} ${folder_header})
if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
endif()

TARGET_LINK_LIBRARIES(${PROJECTNAME} iKin
skinDynLib
${GSL_LIBRARIES}
${YARP_LIBRARIES})
add_library(${PROJECT_NAME} ${folder_source} ${folder_header})
target_link_libraries(${PROJECT_NAME} iKin
skinDynLib
${GSL_LIBRARIES}
${YARP_LIBRARIES})

icub_export_library(${PROJECTNAME} INTERNAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
DEPENDS iKin skinDynLib
DESTINATION include/iCub/iDyn
FILES ${folder_header})
icub_export_library(${PROJECT_NAME} INTERNAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
DEPENDS iKin skinDynLib
DESTINATION include/iCub/iDyn
FILES ${folder_header})


8 changes: 4 additions & 4 deletions src/libraries/iDyn/include/iCub/iDyn/iDyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ class iDynLink : public iKin::iKinLink
* @param _Min is the joint angle lower bound in [-pi,pi] (-pi by default)
* @param _Max is the joint angle higher bound in [-pi,pi] (pi by default)
*/
iDynLink(double _A, double _D, double _Alpha, double _Offset, double _Min=-M_PI, double _Max=M_PI);
iDynLink(double _A, double _D, double _Alpha, double _Offset, double _Min=-iCub::ctrl::CTRL_PI, double _Max=iCub::ctrl::CTRL_PI);

/**
* Constructor, with initialization of kinematic and dynamic data
Expand All @@ -470,7 +470,7 @@ class iDynLink : public iKin::iKinLink
* @param _Min is the joint angle lower bound in [-pi,pi] (-pi by default)
* @param _Max is the joint angle higher bound in [-pi,pi] (pi by default)
*/
iDynLink(const double _m, const yarp::sig::Matrix &_HC, const yarp::sig::Matrix &_I, double _A, double _D, double _Alpha, double _Offset, double _Min=-M_PI, double _Max=M_PI);
iDynLink(const double _m, const yarp::sig::Matrix &_HC, const yarp::sig::Matrix &_I, double _A, double _D, double _Alpha, double _Offset, double _Min=-iCub::ctrl::CTRL_PI, double _Max=iCub::ctrl::CTRL_PI);

/**
* Constructor, with initialization of kinematic and dynamic data
Expand All @@ -484,7 +484,7 @@ class iDynLink : public iKin::iKinLink
* @param _Min is the joint angle lower bound in [-pi,pi] (-pi by default)
* @param _Max is the joint angle higher bound in [-pi,pi] (pi by default)
*/
iDynLink(const double _m, const yarp::sig::Vector &_C, const yarp::sig::Matrix &_I, double _A, double _D, double _Alpha, double _Offset, double _Min=-M_PI, double _Max=M_PI);
iDynLink(const double _m, const yarp::sig::Vector &_C, const yarp::sig::Matrix &_I, double _A, double _D, double _Alpha, double _Offset, double _Min=-iCub::ctrl::CTRL_PI, double _Max=iCub::ctrl::CTRL_PI);

/**
* Constructor, with initialization of kinematic and dynamic data
Expand All @@ -505,7 +505,7 @@ class iDynLink : public iKin::iKinLink
* @param _Min is the joint angle lower bound in [-pi,pi] (-pi by default)
* @param _Max is the joint angle higher bound in [-pi,pi] (pi by default)
*/
iDynLink(const double _m, const double _rCx, const double _rCy, const double _rCz, const double Ixx, const double Ixy, const double Ixz, const double Iyy, const double Iyz, const double Izz, double _A, double _D, double _Alpha, double _Offset, double _Min=-M_PI, double _Max=M_PI);
iDynLink(const double _m, const double _rCx, const double _rCy, const double _rCz, const double Ixx, const double Ixy, const double Ixz, const double Iyy, const double Iyz, const double Izz, double _A, double _D, double _Alpha, double _Offset, double _Min=-iCub::ctrl::CTRL_PI, double _Max=iCub::ctrl::CTRL_PI);

/**
* Copy constructor
Expand Down
11 changes: 7 additions & 4 deletions src/libraries/iDyn/src/iDyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
* Public License for more details
*/

#include <iCub/iDyn/iDyn.h>
#include <iCub/ctrl/math.h>
#include <stdio.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <yarp/os/Log.h>
#include <iomanip>

#include <yarp/os/Log.h>
#include <iCub/iDyn/iDyn.h>
#include <iCub/ctrl/math.h>


using namespace std;
using namespace yarp::os;
using namespace yarp::dev;
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/iKin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ if(ICUB_USE_IPOPT)
add_definitions(${IPOPT_DEFINITIONS})
endif()

if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
endif()

add_library(${PROJECT_NAME} ${folder_source} ${folder_header})
target_link_libraries(${PROJECT_NAME} ctrlLib ${YARP_LIBRARIES})

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/iKin/include/iCub/iKin/iKinFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class iKinLink
* default).
*/
iKinLink(double _A, double _D, double _Alpha, double _Offset,
double _Min=-M_PI, double _Max=M_PI);
double _Min=-iCub::ctrl::CTRL_PI, double _Max=iCub::ctrl::CTRL_PI);

/**
* Creates a new Link from an already existing Link object.
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/optimization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ include_directories(${PROJECT_SOURCE_DIR}/include
${YARP_INCLUDE_DIRS})

add_definitions(${IPOPT_DEFINITIONS})
if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
endif()

add_library(${PROJECTNAME} ${folder_source} ${folder_header})

set_property(TARGET ${PROJECTNAME} APPEND_STRING PROPERTY LINK_FLAGS " ${IPOPT_LINK_FLAGS}")
Expand Down
1 change: 1 addition & 0 deletions src/libraries/optimization/src/calibReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Public License for more details
*/

#include <cmath>
#include <algorithm>

#include <yarp/math/Math.h>
Expand Down
4 changes: 4 additions & 0 deletions src/modules/iKinGazeCtrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ include_directories(${PROJECT_SOURCE_DIR}/include
${IPOPT_INCLUDE_DIRS}
${YARP_INCLUDE_DIRS})

if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
endif()

add_executable(${PROJECTNAME} ${folder_header} ${folder_source})
target_link_libraries(${PROJECTNAME} ctrlLib iKin ${YARP_LIBRARIES})
install(TARGETS ${PROJECTNAME} DESTINATION bin)
Expand Down
28 changes: 14 additions & 14 deletions src/modules/wholeBodyDynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
# Author: Matteo Fumagalli, Marco Randazzo
# CopyPolicy: Released under the terms of the GNU GPL v2.0.


SET(PROJECTNAME wholeBodyDynamics)
project(wholeBodyDynamics)

PROJECT(${PROJECTNAME})
file(GLOB folder_source main.cpp observerThread.cpp)
file(GLOB folder_header observerThread.h)

FILE(GLOB folder_source main.cpp observerThread.cpp)
FILE(GLOB folder_header observerThread.h)
source_group("Source Files" FILES ${folder_source})
source_group("Header Files" FILES ${folder_header})

SOURCE_GROUP("Source Files" FILES ${folder_source})
SOURCE_GROUP("Header Files" FILES ${folder_header})

INCLUDE_DIRECTORIES(${iDyn_INCLUDE_DIRS}
include_directories(${iDyn_INCLUDE_DIRS}
${YARP_INCLUDE_DIRS}
${skinDynLib_INCLUDE_DIRS})

ADD_EXECUTABLE(${PROJECTNAME} ${folder_source} ${folder_header})
if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
endif()

TARGET_LINK_LIBRARIES(${PROJECTNAME} iDyn
${YARP_LIBRARIES}
skinDynLib)
add_executable(${PROJECT_NAME} ${folder_source} ${folder_header})
target_link_libraries(${PROJECT_NAME} iDyn
${YARP_LIBRARIES}
skinDynLib)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

INSTALL(TARGETS ${PROJECTNAME} DESTINATION bin)
8 changes: 5 additions & 3 deletions src/modules/wholeBodyDynamics/observerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* Public License for more details
*/

#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>

#include <yarp/os/all.h>
#include <yarp/sig/all.h>
#include <yarp/dev/all.h>
Expand All @@ -25,9 +30,6 @@
#include <iCub/iDyn/iDynBody.h>
#include <iCub/skinDynLib/skinContact.h>

#include <iostream>
#include <iomanip>
#include <string.h>
#include "observerThread.h"

using namespace yarp::os;
Expand Down
4 changes: 4 additions & 0 deletions src/tools/depth2kin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ include_directories(${PROJECT_SOURCE_DIR}/include
${learningMachine_INCLUDE_DIRS})

add_definitions(${IPOPT_DEFINITIONS})
if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
endif()

add_executable(${PROJECTNAME} ${header_files} ${source_files} ${idl_files} ${doc_files})
set_property(TARGET ${PROJECTNAME} APPEND_STRING PROPERTY LINK_FLAGS " ${IPOPT_LINK_FLAGS}")
target_link_libraries(${PROJECTNAME} ${YARP_LIBRARIES}
Expand Down
1 change: 1 addition & 0 deletions src/tools/depth2kin/src/nlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Public License for more details
*/

#include <cmath>
#include <algorithm>
#include <string>
#include <deque>
Expand Down
4 changes: 2 additions & 2 deletions src/tools/stereoCalib/src/stereoCalibThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool stereoCalibThread::threadInit()
for(size_t i=0; i<head_angles.length()-2; i++)
qL[i+torso_angles.length()]=head_angles[i];
qL[7]=head_angles[4]+(0.5-(LEFT))*head_angles[5];
qL=CTRL_DEG2RAD*qL;
qL=iCub::ctrl::CTRL_DEG2RAD*qL;

qR.resize(torso_angles.length()+head_angles.length()-1);
for(size_t i=0; i<torso_angles.length(); i++)
Expand All @@ -110,7 +110,7 @@ bool stereoCalibThread::threadInit()
for(size_t i=0; i<head_angles.length()-2; i++)
qR[i+torso_angles.length()]=head_angles[i];
qR[7]=head_angles[4]+(0.5-(RIGHT))*head_angles[5];
qR=CTRL_DEG2RAD*qR;
qR=iCub::ctrl::CTRL_DEG2RAD*qR;

return true;
}
Expand Down

0 comments on commit 1966fb3

Please sign in to comment.