Skip to content

Commit 03c32b2

Browse files
Fix after review
1 parent f84f45e commit 03c32b2

File tree

4 files changed

+33
-41
lines changed

4 files changed

+33
-41
lines changed

src/imu/CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
cmake_minimum_required(VERSION 3.5)
2-
project(imu)
1+
if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION)
2+
cmake_minimum_required(VERSION 3.5)
3+
endif()
34

45
add_definitions(-D_USE_MATH_DEFINES)
56

6-
include_directories(${CMAKE_SOURCE_DIR}
7-
${RobotTestingFramework_INCLUDE_DIRS})
8-
9-
robottestingframework_add_plugin(${PROJECT_NAME} HEADERS ${PROJECT_NAME}.h
10-
SOURCES ${PROJECT_NAME}.cpp)
7+
robottestingframework_add_plugin(imu HEADERS imu.h
8+
SOURCES imu.cpp)
119

1210
# add required libraries
13-
target_link_libraries(${PROJECT_NAME} RobotTestingFramework::RTF
11+
target_link_libraries(imu RobotTestingFramework::RTF
1412
RobotTestingFramework::RTF_dll
1513
YARP::YARP_robottestingframework
1614
iDynTree::idyntree-high-level
1715
iDynTree::idyntree-estimation)
1816
# set the installation options
19-
install(TARGETS ${PROJECT_NAME}
20-
EXPORT ${PROJECT_NAME}
17+
install(TARGETS imu
18+
EXPORT imu
2119
COMPONENT runtime
2220
LIBRARY DESTINATION lib)

src/imu/imu.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <yarp/os/Property.h>
99
#include <yarp/os/Stamp.h>
10+
#include <yarp/os/ResourceFinder.h>
1011

1112
#include "imu.h"
1213

@@ -27,19 +28,21 @@ bool Imu::setup(yarp::os::Property& property) {
2728

2829
robotName = property.find("robot").asString(); // robot name
2930
portName = property.find("port").asString(); // name of the port from which the data are streamed
30-
modelPath = property.find("model").asString(); // urdf model path
3131
frameName = property.find("frame").asString(); // frame on which the sensor is attached
3232
sensorName = property.find("sensor").asString(); // sensor name within urdf
33+
modelName = property.find("model").asString(); // urdf model path
34+
yarp::os::ResourceFinder &rf = yarp::os::ResourceFinder::getResourceFinderSingleton();
35+
std::string modelAbsolutePath = rf.findFileByName(modelName);
3336

3437
ROBOTTESTINGFRAMEWORK_TEST_REPORT("Running IMU test on "+robotName+"...");
3538

3639
yarp::os::Property MASclientOptions;
3740
MASclientOptions.put("device", "multipleanalogsensorsclient");
3841
MASclientOptions.put("remote", portName);
3942
MASclientOptions.put("local", "/imuTest/"+portName);
40-
41-
MASclientDriver = new yarp::dev::PolyDriver(MASclientOptions);
42-
43+
44+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver.open(MASclientOptions), "Unable to open the MAS client driver");
45+
4346
yarp::os::Property controlBoardOptions;
4447
controlBoardOptions.put("device", "remotecontrolboardremapper");
4548
yarp::os::Bottle axesNames;
@@ -70,15 +73,15 @@ bool Imu::setup(yarp::os::Property& property) {
7073
controlBoardOptions.put("remoteControlBoards", remoteControlBoards.get(0));
7174
controlBoardOptions.put("localPortPrefix", "/test");
7275

73-
controlBoardDriver = new yarp::dev::PolyDriver(controlBoardOptions);
74-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver->isValid(), "Device driver cannot be opened");
75-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver->view(iorientation), "Unable to open orientation interface");
76-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->isValid(), "Device driver cannot be opened");
77-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(ipos), "Unable to open position control interface");
78-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(ienc), "Unable to open encoder interface");
79-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(iaxes), "Unable to open axes interface");
80-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(ilim), "Unable to open limits interface");
76+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.open(controlBoardOptions), "Unable to open the controlBoard driver");
8177

78+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver.isValid(), "Device driver cannot be opened");
79+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver.view(iorientation), "Unable to open orientation interface");
80+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.isValid(), "Device driver cannot be opened");
81+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(ipos), "Unable to open position control interface");
82+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(ienc), "Unable to open encoder interface");
83+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(iaxes), "Unable to open axes interface");
84+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(ilim), "Unable to open limits interface");
8285

8386
outputPort.open("/test-imu/out");
8487
ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening port "+outputPort.getName()+"...");
@@ -93,7 +96,7 @@ bool Imu::setup(yarp::os::Property& property) {
9396
axis.push_back(axisName);
9497
}
9598

96-
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(model.loadReducedModelFromFile(modelPath.c_str(), axis), Asserter::format("Cannot load model %s", modelPath.c_str()));
99+
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(model.loadReducedModelFromFile(modelAbsolutePath.c_str(), axis), Asserter::format("Cannot load model from %s", modelAbsolutePath.c_str()));
97100
kinDynComp.loadRobotModel(model.model());
98101

99102
iDynTree::Vector3 baseLinkOrientationRad;
@@ -136,17 +139,8 @@ void Imu::tearDown() {
136139
outputPort.interrupt();
137140
outputPort.close();
138141

139-
if(MASclientDriver)
140-
{
141-
delete MASclientDriver;
142-
MASclientDriver = 0;
143-
}
144-
145-
if(controlBoardDriver)
146-
{
147-
delete controlBoardDriver;
148-
controlBoardDriver = 0;
149-
}
142+
controlBoardDriver.close();
143+
MASclientDriver.close();
150144
}
151145

152146
void Imu::run() {

src/imu/imu.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _IMU_H_
2-
#define _IMU_H_
1+
#ifndef IMU_H
2+
#define IMU_H
33

44
#include <yarp/dev/PolyDriver.h>
55
#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
@@ -24,12 +24,12 @@ class Imu : public yarp::robottestingframework::TestCase {
2424
private:
2525
std::string robotName;
2626
std::string portName;
27-
std::string modelPath;
27+
std::string modelName;
2828
std::string frameName;
2929
std::string sensorName;
3030

31-
yarp::dev::PolyDriver *MASclientDriver;
32-
yarp::dev::PolyDriver *controlBoardDriver;
31+
yarp::dev::PolyDriver MASclientDriver;
32+
yarp::dev::PolyDriver controlBoardDriver;
3333
yarp::dev::IOrientationSensors* iorientation;
3434
yarp::dev::IPositionControl* ipos;
3535
yarp::dev::IEncoders* ienc;
@@ -59,4 +59,4 @@ class Imu : public yarp::robottestingframework::TestCase {
5959
bool moveJoint(int ax, double pos);
6060
};
6161

62-
#endif //_IMU_H_
62+
#endif //IMU_H

suites/contexts/icub/test_imu.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
robot ${robotname}
2-
model /path/to/your/robot/model.urdf
2+
model model.urdf
33
port /${robotname}/head/inertials
44
sensor head_imu_0
55
frame head_imu_0

0 commit comments

Comments
 (0)