7
7
8
8
#include < yarp/os/Property.h>
9
9
#include < yarp/os/Stamp.h>
10
+ #include < yarp/os/ResourceFinder.h>
10
11
11
12
#include " imu.h"
12
13
@@ -27,19 +28,21 @@ bool Imu::setup(yarp::os::Property& property) {
27
28
28
29
robotName = property.find (" robot" ).asString (); // robot name
29
30
portName = property.find (" port" ).asString (); // name of the port from which the data are streamed
30
- modelPath = property.find (" model" ).asString (); // urdf model path
31
31
frameName = property.find (" frame" ).asString (); // frame on which the sensor is attached
32
32
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);
33
36
34
37
ROBOTTESTINGFRAMEWORK_TEST_REPORT (" Running IMU test on " +robotName+" ..." );
35
38
36
39
yarp::os::Property MASclientOptions;
37
40
MASclientOptions.put (" device" , " multipleanalogsensorsclient" );
38
41
MASclientOptions.put (" remote" , portName);
39
42
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
+
43
46
yarp::os::Property controlBoardOptions;
44
47
controlBoardOptions.put (" device" , " remotecontrolboardremapper" );
45
48
yarp::os::Bottle axesNames;
@@ -70,15 +73,15 @@ bool Imu::setup(yarp::os::Property& property) {
70
73
controlBoardOptions.put (" remoteControlBoards" , remoteControlBoards.get (0 ));
71
74
controlBoardOptions.put (" localPortPrefix" , " /test" );
72
75
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" );
81
77
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" );
82
85
83
86
outputPort.open (" /test-imu/out" );
84
87
ROBOTTESTINGFRAMEWORK_TEST_REPORT (" Opening port " +outputPort.getName ()+" ..." );
@@ -93,7 +96,7 @@ bool Imu::setup(yarp::os::Property& property) {
93
96
axis.push_back (axisName);
94
97
}
95
98
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 ()));
97
100
kinDynComp.loadRobotModel (model.model ());
98
101
99
102
iDynTree::Vector3 baseLinkOrientationRad;
@@ -136,17 +139,8 @@ void Imu::tearDown() {
136
139
outputPort.interrupt ();
137
140
outputPort.close ();
138
141
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 ();
150
144
}
151
145
152
146
void Imu::run () {
0 commit comments